<?php
if(!isset(Configs::$_['user_permissions']['BB30023']))
{
redirect_to(SITE_URL.'admin/notfound');
}
$db=new Database();
$listData=$db->query("select * from bb_thread_attach_files_data order by ent_dt desc limit 0,100");
$file_id=getGet('file_id');
if(isset($file_id[5]))
{
$queryStr="select file_path,file_name,data_type,post_id from bb_thread_attach_files_data where file_id='".$file_id."'";
$fileData=$db->query($queryStr);
if(file_exists(ROOT_PATH.$fileData[0]['file_path']))
{
download($fileData[0]['file_path'], $fileData[0]['file_name']);
}
}
?>
<style>
.datepicker
{
z-index:99999;
}
</style>
<!-- Modal -->
<div class="modal fade" id="modalSearch" style='z-index:99999;' data-backdrop="false" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog ">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title " id="exampleModalLabel"><?php echo get_text_by_lang('Search','admin');?></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body ">
<p>
<label><strong><?php echo get_text_by_lang('From date','admin');?></strong></label>
<input type="text" class="form-control search-from-date datepicker input-size-medium" name="send[keywords]" />
</p>
<p>
<label><strong><?php echo get_text_by_lang('To date','admin');?></strong></label>
<input type="text" class="form-control search-to-date datepicker input-size-medium" name="send[keywords]" />
</p>
<p>
<label><strong><?php echo get_text_by_lang('File size small than (KB)','admin');?></strong></label>
<input type="text" class="form-control search-sizesmall input-size-medium" value="" name="send[keywords]" />
</p>
<p>
<label><strong><?php echo get_text_by_lang('File size large than (KB)','admin');?></strong></label>
<input type="text" class="form-control search-sizelarge input-size-medium" value="" name="send[keywords]" />
</p>
<p>
<label><strong><?php echo get_text_by_lang('File type','admin');?></strong></label>
<input type="text" class="form-control search-type input-size-medium" value="" name="send[keywords]" />
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-info btnSearch" ><i class="fas fa-search"></i> <?php echo get_text_by_lang('Search','admin');?></button>
<button type="button" class="btn btn-danger btnCloseAlert" data-dismiss="modal"><i class="fas fa-times"></i> <?php echo get_text_by_lang('Close','admin');?></button>
</div>
</div>
</div>
</div>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<!-- Info boxes -->
<div class="row">
<div class="col-lg-12">
<form action="" method="post" enctype="multipart/form-data">
<div class="card" style='margin-top:20px;'>
<div class="card-header border-0">
<h3 class="card-title"><?php echo get_text_by_lang('Resources','admin');?></h3>
<div class="card-tools">
<a href="#" class="btn btn-tool btn-sm btn-modal-search">
<i class="fas fa-search"></i>
</a>
</div>
</div>
<div class="card-body table-responsive p-0">
<table class="table table-hover table-striped table-valign-middle">
<thead>
<tr >
<th><button type="button" class="btn btn-default btn-xs btn-checkall" data-checked="no"><i class="fas fa-square"></i></button></th>
<th><?php echo get_text_by_lang('File name','admin');?></th>
<th><?php echo get_text_by_lang('File type','admin');?></th>
<th><?php echo get_text_by_lang('File size','admin');?></th>
<th><?php echo get_text_by_lang('Ent_dt','admin');?></th>
<th class="text-right"><?php echo get_text_by_lang('Downloads','admin');?></th>
<th class="text-right"><?php echo get_text_by_lang('Action','admin');?></th>
</tr>
</thead>
<tbody class='list-data'>
</tbody>
</table>
</div>
</div>
<!-- /.card -->
</form>
</div>
<div class='col-lg-12 ' >
<div class="btn-group" style='float:left;' role="group" aria-label="Basic example">
<select class="form-control post-action select2js-nomodal" name="send[type]">
<option value=""><?php echo get_text_by_lang('Select an action','admin');?></option>
<option value="delete"><?php echo get_text_by_lang('Delete','admin');?></option>
</select>
<button type="button" class="btn btn-info btnApply"><?php echo get_text_by_lang('Apply','admin');?></button>
</div>
<div class="btn-group" style='float:right;' role="group" aria-label="Basic example">
<button type="button" class="btn btn-info btnPrev"><?php echo get_text_by_lang('Previous','admin');?></button>
<input type='number' class='form-control txtPageNumber' style='margin-left: -5px;width:90px;text-align:center;' value="1" />
<button type="button" class="btn btn-info btnNext"><?php echo get_text_by_lang('Next','admin');?></button>
</div>
</div>
</div>
<!-- /.row -->
<!-- /.row -->
</div><!--/. container-fluid -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<script>
pageData['listData']=<?php echo json_encode($listData);?>;
</script>
<script type="text/javascript">
// postData('http://localhost/coffeecms/api/index', { answer: 42 })
// .then(data => {
// console.log(data); // JSON data parsed by `data.json()` call
// console.log(data['error']);
// });
function prepareShowData()
{
var total=pageData['listData'].length;
var li='';
var td='';
var statusCl='';
for (var i = 0; i < total; i++) {
td+='<tr class="tr-id-'+pageData['listData'][i]['file_id']+'" style="cursor:pointer;">';
td+='<td style="width:80px;text-align: left;">';
td+='<button type="button" class="btn btn-default btn-xs btn-checkbox" data-checked="no" data-id="'+pageData['listData'][i]['file_id']+'"><i class="fas fa-square"></i></button>';
td+='</td>';
// td+='<td >'+getFileName(pageData['listData'][i]['file_name']);
td+='<td >'+pageData['listData'][i]['file_name'];
td+='</td>';
td+='<td >'+pageData['listData'][i]['file_type'].toUpperCase();
td+='</td>';
td+='<td >'+bytesToSize(pageData['listData'][i]['file_size']);
td+='</td>';
td+='<td >'+pageData['listData'][i]['ent_dt'];
td+='</td>';
td+='<td class="text-right">'+pageData['listData'][i]['views'];
td+='</td>';
td+='<td class="text-right">';
td+='<a title="Download" href="'+SITE_URL+'admin/plugin_page_url?plugin=bulletinboard&page=resources&file_id='+pageData['listData'][i]['file_id']+'" class="btn btn-info btn-sm btn-edit" data-id="'+pageData['listData'][i]['file_id']+'" style="margin-right:5px;" ><i class="fas fa-file-download"></i></a>';
td+='</td>';
td+='</tr>';
}
$('.list-data').html(td);
}
$(document).ready(function(){
prepareShowData();
$('.select2js').select2();
$('.select2js-nomodal').select2();
$('.edit-status').select2({
dropdownParent: $("#modalEdit")
});
$('.datepicker').datepicker({
autoclose: true,
format: 'mm/dd/yyyy',
});
$('.search-from-date').val(moment().add('days',-7).format('MM/DD/YYYY'));
$('.search-to-date').val(moment().format('MM/DD/YYYY'));
});
//btn-modal-search
$(document).on('click','.btn-modal-search',function(){
$('#modalSearch').modal({backdrop:'static',keyboard:false});
});
$(document).on('click','.btnApply',function(){
pageData['list_id']='';
$('.btn-checkbox').each(function(){
var id=$(this).attr('data-id');
var checked=$(this).attr('data-checked');
if(checked=='yes')
{
pageData['list_id']+=id+',';
}
});
var sendData={};
sendData['type']='1';
sendData['list_id']=pageData['list_id'];
pageData['action']=$('.post-action > option:selected').val().trim();
sendData['action']=pageData['action'];
postData(API_URL+'plugin_api?plugin=bulletinboard&func=bb_resources_action_apply', sendData).then(data => {
// console.log(data); // JSON data parsed by `data.json()` call
if(pageData['action']=='delete')
{
$('.btn-checkbox').each(function(){
var id=$(this).attr('data-id');
var checked=$(this).attr('data-checked');
// if(checked=='yes')
// {
// $('.tr-id-'+id).remove();
// }
});
}
location.reload();
});
});
//btn-checkbox
$(document).on('click','.btn-checkbox',function(){
var checked=$(this).attr('data-checked');
if(checked=='no')
{
$(this).attr('data-checked','yes');
$(this).html('<i class="fas fa-check-square"></i>').addClass('btn-success');
}
else
{
$(this).attr('data-checked','no');
$(this).html('<i class="fas fa-square"></i>').removeClass('btn-success');
}
});
$(document).on('click','.btn-checkall',function(){
var checked=$(this).attr('data-checked');
if(checked=='no')
{
$(this).attr('data-checked','yes');
$(this).html('<i class="fas fa-check-square"></i>').addClass('btn-success');
$('.btn-checkbox').attr('data-checked','yes').html('<i class="fas fa-check-square"></i>').addClass('btn-success');
}
else
{
$(this).attr('data-checked','no');
$(this).html('<i class="fas fa-square"></i>').removeClass('btn-success');
$('.btn-checkbox').attr('data-checked','no').html('<i class="fas fa-square"></i>').removeClass('btn-success');
}
});
$(document).on('keyup','.search-sizesmall',function(){
$('.search-sizelarge').val('');
});
$(document).on('keyup','.search-sizelarge',function(){
$('.search-sizesmall').val('');
});
$(document).on('click','.btnSearch',function(){
var sendData={};
sendData['page_no']='1';
$('.txtPageNumber').val(sendData['page_no']);
sendData['type']='1';
pageData['start_date']=$('.search-from-date').val().trim();
pageData['end_date']=$('.search-to-date').val().trim();
pageData['sizesmall']=$('.search-sizesmall').val().trim();
pageData['sizelarge']=$('.search-sizelarge').val().trim();
pageData['file_type']=$('.search-type').val().trim();
if(pageData['start_date'].length==0)
{
showAlert('','From date not valid!');
return false;
}
if(pageData['end_date'].length==0)
{
showAlert('','From date not valid!');
return false;
}
sendData['start_date']=moment(pageData['start_date'],'MM/DD/YYYY').format('YYYY-MM-DD');
sendData['end_date']=moment(pageData['end_date'],'MM/DD/YYYY').format('YYYY-MM-DD');
sendData['sizesmall']=pageData['sizesmall'];
sendData['sizelarge']=pageData['sizelarge'];
sendData['file_type']=pageData['file_type'];
postData(API_URL+'plugin_api?plugin=bulletinboard&func=bb_get_list_resources', sendData).then(data => {
// console.log(data); // JSON data parsed by `data.json()` call
$('#modalSearch').modal('hide');
pageData['listData']=data['data'];
prepareShowData();
});
});
$(document).on('click','.btnPrev',function(){
var no=$('.txtPageNumber').val();
if(no.length==0)
{
showAlert('','Page number not valid.');
return false;
}
pageData['page_no']=no;
if(parseInt(pageData['page_no'])<=0)
{
pageData['page_no']=1;
}
var sendData={};
sendData['page_no']=parseInt(pageData['page_no'])-1;
$('.txtPageNumber').val(sendData['page_no']);
sendData['type']='1';
pageData['start_date']=$('.search-from-date').val().trim();
pageData['end_date']=$('.search-to-date').val().trim();
pageData['sizesmall']=$('.search-sizesmall').val().trim();
pageData['sizelarge']=$('.search-sizelarge').val().trim();
pageData['file_type']=$('.search-type').val().trim();
if(pageData['start_date'].length==0)
{
showAlert('','From date not valid!');
return false;
}
if(pageData['end_date'].length==0)
{
showAlert('','From date not valid!');
return false;
}
sendData['start_date']=moment(pageData['start_date'],'MM/DD/YYYY').format('YYYY-MM-DD');
sendData['end_date']=moment(pageData['end_date'],'MM/DD/YYYY').format('YYYY-MM-DD');
sendData['sizesmall']=pageData['sizesmall'];
sendData['sizelarge']=pageData['sizelarge'];
sendData['file_type']=pageData['file_type'];
postData(API_URL+'plugin_api?plugin=bulletinboard&func=bb_get_list_resources', sendData).then(data => {
// console.log(data); // JSON data parsed by `data.json()` call
$('#modalSearch').modal('hide');
pageData['listData']=data['data'];
prepareShowData();
});
});
$(document).on('click','.btnNext',function(){
var no=$('.txtPageNumber').val();
if(no.length==0)
{
showAlert('','Page number not valid.');
return false;
}
pageData['page_no']=no;
if(parseInt(pageData['page_no'])<=0)
{
pageData['page_no']=1;
}
var sendData={};
sendData['page_no']=parseInt(pageData['page_no'])+1;
$('.txtPageNumber').val(sendData['page_no']);
sendData['type']='1';
pageData['start_date']=$('.search-from-date').val().trim();
pageData['end_date']=$('.search-to-date').val().trim();
pageData['sizesmall']=$('.search-sizesmall').val().trim();
pageData['sizelarge']=$('.search-sizelarge').val().trim();
pageData['file_type']=$('.search-type').val().trim();
if(pageData['start_date'].length==0)
{
showAlert('','From date not valid!');
return false;
}
if(pageData['end_date'].length==0)
{
showAlert('','From date not valid!');
return false;
}
sendData['start_date']=moment(pageData['start_date'],'MM/DD/YYYY').format('YYYY-MM-DD');
sendData['end_date']=moment(pageData['end_date'],'MM/DD/YYYY').format('YYYY-MM-DD');
sendData['sizesmall']=pageData['sizesmall'];
sendData['sizelarge']=pageData['sizelarge'];
sendData['file_type']=pageData['file_type'];
postData(API_URL+'plugin_api?plugin=bulletinboard&func=bb_get_list_resources', sendData).then(data => {
// console.log(data); // JSON data parsed by `data.json()` call
$('#modalSearch').modal('hide');
pageData['listData']=data['data'];
prepareShowData();
});
});
</script>
|