forked from tbagriyanik/eOgr
/
data_dosyalar.php
260 lines (217 loc) · 8.26 KB
/
data_dosyalar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?php
/*
eOgr - elearning project
Developer Site: http://yunus.sourceforge.net
Demo Site: http://yunus.sourceforge.net/eogr
Source Track: http://eogr.googlecode.com
Support: http://www.ohloh.net/p/eogr
This project is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or any later version. See the GNU
Lesser General Public License for more details.
*/
@session_start();
header("Content-Type: text/html; charset=utf-8");
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Easy set variables
*/
/* Array of database columns which should be read and sent back to DataTables. Use a space where
* you want to insert a non-database field (for example a counter or static image)
*/
require("conf.php");
checkLoginLang(true,true,"data_dosyalar.php");
// if (!check_source()) die ("<font id='hata'>$metin[295]</font>");
$aColumns = array( 'id', 'userID', 'fileName', 'downloadCount',' ');
$aColumns2 = array( 'id', 'userID', 'fileName', 'downloadCount');
/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "id";
/* DB table to use */
$sTable = "eo_files";
/* Database connection information */
$gaSql['user'] = $_username;
$gaSql['password'] = $_password;
$gaSql['db'] = $_db;
$gaSql['server'] = $_host;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* If you just want to use the basic configuration for DataTables with PHP server-side, there is
* no need to edit below this line
*/
/*
* MySQL connection
*/
$gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password'] ) or
die( 'Could not open connection to server' );
mysql_select_db( $gaSql['db'], $gaSql['link'] ) or
die( 'Could not select database '. $gaSql['db'] );
/*
* Paging
*/
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) and $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
/*
* Ordering
*/
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
$sOrder = "ORDER BY ";
for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
{
if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
{
$sOrder .= $aColumns2[ intval( $_GET['iSortCol_'.$i] ) ]."
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$tumDosyalar = ((isset($_SESSION["tumDosyalar"]))?"1":"0");
$sWhere = "";
if (!empty($_GET['sSearch']) and $_GET['sSearch'] != "" )
{
if($tumDosyalar!="1")
$sWhere = "WHERE ((";
else
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns)-1 ; $i++ )
{
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
}
$sWhere = substr_replace( $sWhere, "", -3 );
$sWhere .= ')';
}
/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns)-1 ; $i++ )
{
if (!empty($_GET['bSearchable_'.$i]) and !empty($_GET['sSearch_'.$i]) and $_GET['bSearchable_'.$i] == "true" and $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE (";
}
else
{
$sWhere .= " AND ";
}
$sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
if($tumDosyalar!="1"){
if(!empty($_GET['sSearch']))
$sWhere .= " OR (SELECT userName FROM eo_users WHERE eo_users.id=eo_files.userID ) LIKE '%".mysql_real_escape_string($_GET['sSearch'])."%') AND fileName not REGEXP '^[0-9]{10,15}' ";
else
$sWhere .= " WHERE fileName not REGEXP '^[0-9]{10,15}' ";
}
else{
if(!empty($_GET['sSearch']))
$sWhere .= " OR (SELECT userName FROM eo_users WHERE eo_users.id=eo_files.userID ) LIKE '%".mysql_real_escape_string($_GET['sSearch'])."%' ";
else
$sWhere .= "";
}
/*
* SQL queries
* Get data to display
*/
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns2)).",
(SELECT userName FROM eo_users WHERE
eo_users.id=eo_files.userID
) as userName
FROM $sTable
$sWhere
$sOrder
$sLimit
";
//echo $sQuery;
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
/* Data set length after filtering */
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTable
";
$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
/*
* Output
*/
$sOutput = '{';
$sOutput .= '"sEcho": '.intval((isset($_GET['sEcho']))?$_GET['sEcho']:"").', ';
$sOutput .= '"iTotalRecords": '.$iTotal.', ';
$sOutput .= '"iTotalDisplayRecords": '.$iFilteredTotal.', ';
$sOutput .= '"aaData": [ ';
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$sOutput .= "[";
$kayNo = $aRow[ $aColumns[0] ];
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ( $aColumns[$i] == "fileName" )
{
/* Special output formatting */
$sOutput .= '"<a href=\"fileDownload.php?id='.$aRow[ $aColumns[0] ].'&file='.$aRow[ $aColumns[$i] ].'\" class=\"external\">'.$aRow[ $aColumns[$i] ].'</a> ';
if(in_array(file_ext($aRow[ $aColumns[$i] ]),array("jpg","jpeg","png","gif")))
$sOutput .= ' <a href=\"fileDownload.php?id='.$aRow[ $aColumns[0] ].
'&file='.$aRow[ $aColumns[$i] ].'&islem=goster\" target=\"_blank\"><img src=\"img/preview.png\" border=\"0\" style=\"vertical-align:middle\" alt=\"207\"/></a> ';
if(in_array(file_ext($aRow[ $aColumns[$i] ]),$_filesToPlay))
$sOutput .= ' <a href=\"fileDownload.php?id='.$aRow[ $aColumns[0] ].
'&file='.$aRow[ $aColumns[$i] ].'&islem=goster\" target=\"_blank\"><img src=\"img/preview.png\" border=\"0\" style=\"vertical-align:middle\" alt=\"??\"/></a> ';
$sOutput .= " <font size='-2'>".getSizeAsString(@filesize($_uploadFolder.'/'.$aRow[ $aColumns[$i] ]));
$humanRelativeDate = new HumanRelativeDate();
$sOutput .= " ".iconv( "ISO-8859-9","UTF-8",$humanRelativeDate->getTextForSQLDate(date ("Y-m-d H:i:s",@filemtime($_uploadFolder.'/'.$aRow[ $aColumns[$i] ]) ))).'</font>",';
}
else if ( $aColumns[$i] == 'userID' )
{
$sOutput .= ' "'.($aRow[ 4 ]).'",';
}
else if ( $aColumns[$i] != ' ' )
{
/* General output */
$sOutput .= '"'.str_replace('"', '\"', $aRow[ $aColumns[$i] ]).'",';
}
else if ( $aColumns[$i] == ' ' )
{
/* Delete */
if(($aRow[ 4 ]==$_SESSION["usern"]
or getUserType($_SESSION["usern"])=="2")
and (preg_match("/777/",decoct(@fileperms($_uploadFolder)))
or preg_match("/766/",decoct(@fileperms($_uploadFolder)))))
$sOutput .= '"<img src=\"img/cross.png\" alt=\"delete\" width=\"16\" height=\"16\" border=\"0\" style=\"vertical-align: middle;cursor:pointer;\" onclick=\"javascript:delWithCon('.$kayNo.')\" title=\"'.$metin[102].'\"/>",';
else
$sOutput .= '"",';
}
}
/*
* Optional Configuration:
* If you need to add any extra columns (add/edit/delete etc) to the table, that aren't in the
* database - you can do it here
*/
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= "],";
}
$sOutput = substr_replace( $sOutput, "", -1 );
$sOutput .= '] }';
echo $sOutput;
?>