forked from BNUACM/bnuoj-web-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_data.php
152 lines (139 loc) · 5.04 KB
/
mail_data.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
<?php
include_once("conn.php");
$user=convert_str($_GET['username']);
$aColumns = array( 'mailid', 'sender','reciever', 'title', 'mail_time', 'status' );
$sIndexColumn = "mailid";
$sTable = "mail";
//paging
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
$sLimit = "LIMIT ".mysql_real_escape_string( $_GET['iDisplayStart'] ).", ".
mysql_real_escape_string( $_GET['iDisplayLength'] );
}
if($nowuser!=$user||$nowuser== ""||$nowpass==""||!db_user_match($nowuser,$nowpass)) $sLimit = "LIMIT 0,0";
//ordering
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 .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
".mysql_real_escape_string( $_GET['sSortDir_'.$i] ) .", ";
}
}
$sOrder = substr_replace( $sOrder, "", -2 );
if ( $sOrder == "ORDER BY" )
{
$sOrder = "";
}
}
//filtering
$sWhere = "";
if ( $_GET['sSearch'] != "" )
{
$sWhere = "WHERE (";
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
if ($aColumns[$i]=="source"||$aColumns[$i]=="title") {
$str=$_GET['sSearch'];
$change = array(
' '=>'%',
);
$s=strtr(mysql_real_escape_string($str),$change);
$sWhere .= $aColumns[$i]." LIKE '%".$s."%' OR ";
}
else $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) ; $i++ )
{
if ( $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
{
if ( $sWhere == "" )
{
$sWhere = "WHERE ";
}
else
{
$sWhere .= " AND ";
}
/*if ($aColumns[$i]=="vname") {
if ($_GET['sSearch_'.$i]=="BNU") $sWhere .= "vname = '' ";
else $sWhere .= $aColumns[$i]." = '".mysql_real_escape_string($_GET['sSearch_'.$i])."' ";
}
else*/ $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
}
}
// echo "<script>alert($sWhere);</script>";
if ( $sWhere == "" ) $sWhere = "WHERE (reciever='$user' or sender='$user')";
$sWhere.= " AND (reciever='$user' or sender='$user')" ;
/*
* SQL queries
* Get data to display
*/
$sQuery = "
SELECT SQL_CALC_FOUND_ROWS ".str_replace(" , ", " ", implode(", ", $aColumns))."
FROM $sTable
$sWhere
$sOrder
$sLimit
";
// echo $sQuery;die();
$rResult = mysql_query( $sQuery ) or die(mysql_error());
/* Data set length after filtering */
$sQuery = "
SELECT FOUND_ROWS()
";
$rResultFilterTotal = mysql_query( $sQuery ) or die(mysql_error());
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];
/* Total data set length */
$sQuery = "
SELECT COUNT(".$sIndexColumn.")
FROM $sTable where reciever='$user' or sender='$user'
";
$rResultTotal = mysql_query( $sQuery ) or die(mysql_error());
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];
/*
* Output
*/
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $iTotal,
"iTotalDisplayRecords" => $iFilteredTotal,
"aaData" => array()
);
$mark=0;
while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i<count($aColumns)-1 ; $i++ )
{
if ($aColumns[$i] == "sender" ) {
$row[] = "<a href='userinfo.php?name=".$aRow[$aColumns[$i]]."'>".$aRow[ $aColumns[$i] ]."</a>";
}
else if ($aColumns[$i] == "title" ) {
if ($aRow[ $aColumns[count($aColumns)-1] ]=="0") $row[] = "<a class='getmail' href='javascript:void(0);' name='".$aRow[$aColumns[0]]."'><b>".htmlspecialchars($aRow[ $aColumns[$i] ])."</b></a>";
else $row[] = "<a class='getmail' name='".$aRow[$aColumns[0]]."' href='javascript:void(0);'>".htmlspecialchars($aRow[ $aColumns[$i] ])."</a>";
}
else if ( $aColumns[$i] != ' ' )
{
/* General output */
$row[] = $aRow[ $aColumns[$i] ];
}
}
// if ($mark%2==1) $row["DT_RowClass"]="gradeC even";
// else $row["DT_RowClass"]="gradeC odd";
// $row["DT_RowClass"]="gradeC";
$mark++;
$output['aaData'][] = $row;
}
echo json_encode( $output );
?>