bölümle alakalı gerekli kodları konu altında mevcut

<script>
oTable = null;
filterType = 'apk';
newSearch = true;
firstLoad = true;
$(document).ready(function () {
oTable = $('#searchResults').dataTable({
"sPaginationType": "full_numbers",
"bAutoWidth": false,
"bServerSide": true,
"bProcessing": true,
"sAjaxSource": 'ajax/_search.ajax.php',
"iDisplayLength": 25,
"bFilter": false,
"bSort": false,
"bLengthChange": false,
"aoColumns": [
{},
{sClass: "alignCenter searchLastCol", sWidth: "150"}
],
"oLanguage": {
"oPaginate": {
"sFirst": "<?php echo t('datatable_first', 'First'); ?>",
"sPrevious": "<?php echo t('datatable_previous', 'Previous'); ?>",
"sNext": "<?php echo t('datatable_next', 'Next'); ?>",
"sLast": "<?php echo t('datatable_last', 'Last'); ?>"
},
"sEmptyTable": "<?php echo t('datatable_no_files_available_in_search_results', 'No files available in search results'); ?>",
"sInfo": "<?php echo t('datatable_showing_x_to_x_of_total_files', 'Showing _START_ to _END_ of _TOTAL_ files'); ?>",
"sInfoEmpty": "<?php echo t('datatable_no_files', ''); ?>",
"sLengthMenu": "<?php echo t('datatable_show_menu_files', 'Show _MENU_ files'); ?>",
"sProcessing": "<?php echo t('datatable_loading_please_wait', 'Loading, please wait...'); ?>",
"sInfoFiltered": "<?php echo t('datatable_base_filtered', ' (filtered)'); ?>",
"sSearch": "<?php echo t('datatable_search_text', 'Search:'); ?>",
"sZeroRecords": "<?php echo t('datatable_no_matching_records_found', 'No matching records found'); ?>"
},
"fnServerData": function (sSource, aoData, fnCallback) {
if(firstLoad != true) {
$('#searchResults').parent().fadeTo('fast', 0.3);
}
firstLoad = false;
aoData.push({"name": "filterText", "value": $('#filterText').val()});
aoData.push({"name": "filterType", "value": filterType});
$.ajax({
"dataType": 'json',
"type": "GET",
"url": "ajax/_search.ajax.php",
"data": aoData,
"success": function (json) {
updateTotals(json);
fnCallback(json);
$('#searchResults').parent().fadeTo('fast', 1.0);
}
});
}
});
});
function reloadTable(lFilterType)
{
if (typeof (lFilterType) == 'undefined')
{
lFilterType = null;
}
filterType = lFilterType;
oTable.fnPageChange('first');
oTable.fnDraw(false);
}
function updateTotals(json)
{
if (filterType == null)
{
$('.nav-tabs a:first').tab('show');
}
if (newSearch == false)
{
// scroll to top
$("html, body").animate({scrollTop: $(".search-control").offset().top - 10 - ($("#navigation").height())}, 200);
}
newSearch = false;
setTabText('all', json.iTotalAll);
<?php foreach($documentTypes AS $documentType => $documentExt): ?>
setTabText('<?php echo $documentType; ?>', json.iTotal<?php echo UCFirst($documentType); ?>);
<?php endforeach; ?>
}
function setTabText(id, total)
{
$('.tab-text-' + id).html('(' + total + ')');
}
</script>
<div class="row">
<div class="col-md-12">
<div class="col-md-12 form-description">
<p><?php echo t("search_intro", "Search or browse all publicly shared files on this site using the form below."); ?></p>
</div>
</div>
<div class="col-md-12">
<form action="<?php echo WEB_ROOT; ?>/apk.html" class="search-line block" method="POST" onSubmit="reloadTable(); return false;">
<div class="input-group">
<div class="search-control">
<input name="filterText" id="filterText" type="text" class="form-control autocomplete ui-autocomplete-input" placeholder="<?php echo t("search_box_placeholder", "Enter your search term here..."); ?>" autocomplete="off"/>
</div>
<span class="input-group-btn main-search-button">
<button type="submit" class="btn btn-default"><?php echo t("search_form_search", "Search"); ?> <i class="fa fa-search"></i></button>
</span>
</div>
</form>
</div>
<div class="col-md-12">
<div class="tabbable page-tabs search-tabs">
<ul class="nav nav-tabs">
</ul>
<div class="tab-content">
<!-- First tab -->
<div class="tab-pane fade active in">
<?php
if(notification::isErrors())
{
echo notification::outputErrors();
}
elseif(notification::isSuccess())
{
echo notification::outputSuccess();
}
?>
<table id="searchResults" width="100%" cellpadding="3" cellspacing="0" class="searchResults">
<tbody><tr><td><?php echo t('loading_please_wait', 'Loading, please wait...'); ?></td></tr></tbody>
</table>
</div>
<!-- /first tab -->
</div>
</div>
</div>
</div>
<div class="customFilter" id="customFilter" style="display: none;">
<label class="adminResponsiveHide filterByTypeWrapper" style="padding-left: 6px;">
Server:
<select name="filterByType" id="filterByType" onChange="reloadTable();
return false;" style="width: 120px;">
<option value="">- all -</option>
<?php
foreach($documentTypes AS $documentType => $documentExtensions)
{
echo '<option value="' . $documentExtensions . '"';
if(($filterByType) && ($filterByType == $documentExtensions))
{
echo ' SELECTED';
}
echo '>' . $documentType . '</option>';
}
?>
</select>
</label>
</div><?php
if(SITE_CONFIG_ENABLE_FILE_SEARCH == 'no')
{
// this page can not be accessed
coreFunctions::output404();
}
// setup initial params
$s = (int)$_REQUEST['iDisplayStart'];
$l = (int)$_REQUEST['iDisplayLength'];
$db = Database::getDatabase();
// create json response
$jsonRs = array();
// document types
require_once(SITE_TEMPLATES_PATH . '/partial/_search_document_types.inc.php');
// prepare clause
$clause = 'WHERE ';
$clause .= 'status = "active" ';
$clause .= 'AND file.isPublic > 0 ';
// only files in public folders
$publicFolderClause = 'SELECT ff1.id FROM file_folder ff1 WHERE ff1.isPublic > 0 AND IF(ff1.parentId IS NULL, 1, (SELECT IF(ff2.isPublic = 0, 0, IF(ff2.parentId IS NULL, ff2.isPublic, (SELECT ff3.isPublic FROM file_folder ff3 WHERE ff3.id = ff2.parentId))) FROM file_folder ff2 WHERE ff2.id = ff1.parentId)) > 0';
$clause .= 'AND (file.folderId IN ('.$publicFolderClause.') OR (file.folderId IS NULL))';
// only files in users which have opted to share them
$clause .= 'AND (file.userId IN (SELECT id FROM users WHERE isPublic = 1) OR (file.userId IS NULL))';
// filterText
$filterText = '';
if(isset($_REQUEST['filterText']))
{
$filterText = $_REQUEST['filterText'];
$filterText = str_replace(array('"', '%', '*'), '', $filterText);
}
if(strlen($filterText))
{
$clause .= 'AND (file.shortUrl = '.$db->quote($filterText).' OR file.originalFilename LIKE "%'.$db->escape($filterText).'%") ';
}
// load stats for tabs
$jsonRs['iTotalAll'] = $db->getValue('SELECT COUNT(id) AS total FROM file '.$clause);
foreach($documentTypes AS $documentType=>$documentExt)
{
$arrKey = 'iTotal'.UCFirst($documentType);
$jsonRs[$arrKey] = $db->getValue('SELECT COUNT(id) AS total FROM file '.$clause.' AND extension IN ("'.implode('","', explode(',', $documentExt)).'")');
}
// filterType
$filterType = '';
if(isset($_REQUEST['filterType']))
{
$filterType = $_REQUEST['filterType'];
}
// make filterType safe
$filterTypeArr = array();
if(strlen($filterType))
{
if(isset($documentTypes[$filterType]))
{
$filterTypeExp = explode(',', $documentTypes[$filterType]);
foreach($filterTypeExp AS $filterTypeExpItem)
{
// limit length
$filterTypeExpItem = substr($filterTypeExpItem, 0, 10);
$filterTypeExpItem = strtolower($filterTypeExpItem);
// remove unwanted characters
$filterTypeExpItem = str_replace(array(',',')','(','$','"',''','&','-','*','%'), '', $filterTypeExpItem);
if(strlen($filterTypeExpItem))
{
$filterTypeArr[] = $filterTypeExpItem;
}
}
}
}
if(COUNT($filterTypeArr))
{
$clause .= 'AND extension IN ("'.implode('","', $filterTypeArr).'") ';
}
// load all
$totalResults = $db->getValue('SELECT COUNT(id) AS total FROM file '.$clause);
// load filtered
$results = $db->getRows('SELECT * FROM file '.$clause.'ORDER BY uploadedDate DESC LIMIT '.$s.','.$l);
$data = array();
if ($results)
{
foreach ($results AS $result)
{
$fileObj = file::hydrate($result);
$previewImageUrlMedium = file::getIconPreviewImageUrl($result, false, 160, false, 68, 68, 'middle');
$lrs = array();
$cell1 = '';
$cell1 .= '<div class="start-icon"><a href="'.validation::safeOutputToScreen($fileObj->getFullShortUrl()).'" target="_blank"><img src="'.$previewImageUrlMedium.'" alt="'.validation::safeOutputToScreen($result['extension']).'" title="'.validation::safeOutputToScreen($result['extension']).'"/></a></div>';
$cell1 .= '<div class="main-text">';
$cell1 .= '<h6><a href="'.validation::safeOutputToScreen($fileObj->getFullShortUrl()).'" target="_blank">'.validation::safeOutputToScreen($result['originalFilename']).'</a></h6>';
$cell1 .= '<a class="resultUrl" href="'.validation::safeOutputToScreen($fileObj->getFullShortUrl()).'" target="_blank">'.$fileObj->getFullShortUrl().'</a>';
$cell1 .= '<p>'.t('search_date_uploaded', 'Dated Uploaded').': '.validation::safeOutputToScreen(coreFunctions::formatDate($result['uploadedDate'], SITE_CONFIG_DATE_FORMAT)).' '.t('search_filesize', 'Filesize').': '.validation::safeOutputToScreen(coreFunctions::formatSize($result['fileSize'])).'<p>';
$cell1 .= '</div>';
$lrs[] = $cell1;
$lrs[] = '<a href="'.validation::safeOutputToScreen($fileObj->getFullShortUrl()).'" target="_blank" class="btn btn-primary btn-file-download">'.t('download', 'download').' <i class="fa fa-download"></i></a>';
$data[] = $lrs;
}
}
$jsonRs['sEcho'] = intval($_GET['sEcho']);
$jsonRs['iTotalRecords'] = $totalResults;
$jsonRs['iTotalDisplayRecords'] = $totalResults;
$jsonRs['aaData'] = $data;
echo json_encode($jsonRs);
