-
Notifications
You must be signed in to change notification settings - Fork 9
/
list.inc
234 lines (216 loc) · 8.82 KB
/
list.inc
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
<?php
include_once drupal_get_path('module', 'librusec') .'/librusec.inc';
function libLetter($buk) {
set_title("Авторы, фамилия которых начинается на букву $buk");
$sth = SELECT("SUM(N) as N, AvtorId FROM `libbook` JOIN libavtor USING (BookId) JOIN libavtorname USING(AvtorId)
WHERE LastName LIKE '$buk%' GROUP BY AvtorId ORDER BY 1 DESC LIMIT 22");
while ($a1=dbf($sth)) $r .= avl($a1->AvtorId, ' ').' ';
return $r." ...<br><br>".libList('a', $buk);
}
function p($t) {
return addslashes(trim(urldecode($_GET[$t])));
}
function libAJAXlist() {
Global $sa, $rd, $user;
$sa = $_GET['sa'];
$rd = $_GET['rd'];
$W = 'WHERE NOT (Deleted&1)';
if (!$user->uid) $W .= ' AND NOT libbook.Blocked';
$tm = $_GET['tm'];//Time
if ($t = p('t')) {$t=str_replace('*','%',$t); $W .= " AND Title LIKE '$t%'";}
if ($t = p('ln')) if ($t == 'Прочее') $W .= " AND LastName < 'Z' "; else $W .= " AND LastName LIKE '$t%'";
if ($t = p('fn')) $W .= " AND FirstName LIKE '$t%'";
if ($t = p('mn')) $W .= " AND MiddleName LIKE '$t%'";
if ($t = p('g')) {
$wst = '';
foreach (split (',', $t) as $l) {
if ($l = trim($l)) {
if ($wst) $wst .= " OR";
$wst .= " GenreDesc LIKE '%$l%' OR GenreCode LIKE '$l%'";
}
}
$W .= " AND ($wst)";
}
if ($t = p('e')) {
$wst = '';
foreach (split (',', $t) as $l) {
if ($l = trim($l)) {
if ($wst) $wst .= " OR";
$wst .= " FileType = '$l'";
}
}
$W .= " AND ($wst)";
}
if ($t = p('s1')) $W .= " AND FileSize >= '$t'*1024";
if ($t = p('s2')) $W .= " AND FileSize <= '$t'*1024";
if ($t = p('lng')) {
$wst = '';
foreach (split (',', $t) as $l) {
if ($l = trim($l)) {
if ($wst) $wst .= " OR";
$wst .= " Lang = '$l'";
}
}
$W .= " AND ($wst)";
}
if ($_GET[st1]) $O = "Title";
if ($_GET[st2]) $O = "Title DESC";
if ($_GET[sln1]) $O = "LastName, FirstName, MiddleName, Title";
if ($_GET[sln2]) $O = "LastName DESC, FirstName, MiddleName, Title";
if ($_GET[sfn1]) $O = "FirstName";
if ($_GET[sfn2]) $O = "FirstName DESC";
if ($_GET[smn1]) $O = "MiddleName";
if ($_GET[smn2]) $O = "MiddleName DESC";
if ($_GET[sg1]) $O = "GenreDesc";
if ($_GET[sg2]) $O = "GenreDesc DESC";
if ($_GET[ss1]) $O = "FileSize";
if ($_GET[ss2]) $O = "FileSize DESC";
if ($_GET[se1]) $O = "FileType";
if ($_GET[se2]) $O = "FileType DESC";
if ($_GET[sd1]) $O = "BookId";
if ($_GET[sd2]) $O = "BookId DESC";
if (!$O) $O = ' BookId DESC';
$se = $_GET['se'];//SeqId
$l = $_GET['l'];//Lang
$y = $_GET['y'];//Year
foreach (array('ln','fn','mn') as $qq)
if ($_GET[$qq] || $_GET['s'.$qq.'1'] || $_GET['s'.$qq.'2'])
$ja = "JOIN libavtor USING(BookId) JOIN libavtorname USING(AvtorId)";
if ($_GET['g'] || $_GET['sg1'] || $_GET['sg2']) {
$jg = "JOIN libgenre USING(BookId) JOIN libgenrelist USING(GenreId)";
$gb = "GROUP BY 1";
}
if ($_GET['ab']=='ab2') {
$SinBooks = 1;
if (!$ja) $ja = "JOIN libavtor USING(BookId)";
$tot = Sel("COUNT(DISTINCT(libavtor.AvtorId)) FROM libbook $ja $jg $W");
$S = "SELECT libavtor.AvtorId AS a, COUNT(libbook.BookId) as N FROM libbook $ja $jg $W GROUP BY 1 ORDER BY $O";
} else {
$tot = Sel ("COUNT(DISTINCT(libbook.BookId)) FROM libbook $ja $jg $W");
$S = "SELECT libbook.BookId AS b FROM libbook $ja $jg $W $gb ORDER BY $O";
}
// Global $user; if ($user->uid == 1) print "<br>$S<br>";
$sth = pgq($S, $tot);
print "<div align=left>";
if (!$SinBooks) print downloadall('up'); //AnnChkbox('RB()').
for ($NN = 0; $a1 = dbf($sth); $NN++) {
if ($SinBooks)
print avl1($a1->a)." ($a1->N)<br>\n";
else
print DoLibRow($a1->b, 'authors checkbox genre annotation list');
}
if (!$SinBooks) print downloadall('down')."</form>";
print "</div><br>";
if (!$NN) print "Не нашлось ни единой книжки, удовлетворяющей вашим требованиям. Упростите.";
$pager = theme('pager');
$pager = preg_replace('|/makebooklist.page=(\d+)"|','javascript:pg($1)"',$pager);
$pager = preg_replace('|/makebooklist.page=(\d+)[^"]+"|','javascript:pg($1)"',$pager);
$pager = preg_replace('|/makebooklist[^"]*|','javascript:pg(0)',$pager);
print $pager;
}
function libList($type='', $FirstLetter='') {
if ($FirstLetter && $type == 'b') {
$FirstTitle = $FirstLetter;
$FirstLetter = '';
}
if ($FirstLetter) $sln1 = ' checked';
if ($type == 'a') $ab = 'ab=ab2&';
elseif ($type == 'b') $ab = 'ab=ab1&';
else $ab = '';
$sth = SELECT("DISTINCT Lang FROM libbook WHERE Lang <> ''");
while ($v = db_result($sth)) $ll .= "$v, ";
$ll = rtrim($ll, ', ');
$sth = SELECT("DISTINCT FileType FROM libbook");
while ($v = db_result($sth)) $tt .= "$v, ";
$tt = rtrim($tt, ', ');
$r = "<script>var page='$_GET[page]'";
$r .= '
var t1 = "<table><tr><td>";
var t2 = "</table>";
var lp = "1";
var ltm = 0;
var lp1 = "";
var type = "";
var cnt=0;
var tt;
function libRB(libnow) {
cnt++;
var tm = new Date; tm = tm.getTime();
if (libnow != 1 && tm - ltm < 1555) { setTimeout(libRB, 333); return; } //были недавно, зайдите попозже.
ltm = tm;
var par = "";
if (page) par = "page="+page+"&";
var a = ["t", "g", "ln", "fn", "mn", "s1", "s2", "e", "lng"];
for (var i in a) {
var q = jQuery("#"+a[i]).val();
if (q) par += a[i] + "=" + encodeURI(q) + "&";
}
jQuery("input[@type=radio][@checked]").each(function(i){par += this.value + "=1&"});
if (jQuery("#sa[@checked]").val()) par += "sa=1&";
if (jQuery("#rd[@checked]").val()) par += "rd=1&";
if (libnow != 1 && lp1 != par) {//прошлый раз просили не это. Еще не определились. Зайдите попозже.
lp1 = par;
setTimeout(libRB, 1111);
return;
}
if (lp != par) {
jQuery("#books").html("<p>грузим...</p>");
jQuery.get("/makebooklist?"+par+"'.$ab.'", function(r){ jQuery("#books").html(t1+r+t2); } )
lp = par;
}
}
function pg(p) {page=p; libRB(1);}
</script>
<style>th {font-size: 70%;padding:0px;spacing:0px}</style>'."
<ul>
<li>Жанры (<a href=/g>список</a>) можно указать несколько через запятую
<li>Языки: ($ll), можно указать несколько через запятую.
<li>Форматы: ($tt), можно указать несколько через запятую.
<table id=tt>
<tr>";
if ($type != 'a') $r .= "<th nowrap>Название";
$r .= "
<th nowrap>Фамилия
<th nowrap>Имя
<th nowrap>Отчество
<th nowrap>Жанр
<th nowrap>Размер файла
<th nowrap>Дата
<th nowrap>Формат
<th nowrap>Язык
<tr>";
if ($type != 'a') $r .= "
<td nowrap><input type=radio name=r value=st1 onchange=libRB()><img src=/img/s1.gif>
<input type=radio name=r value=st2 onchange=libRB()><img src=/img/s2.gif>";
$r .= "
<td nowrap><input type=radio name=r value=sln1 onchange=libRB() $sln1><img src=/img/s1.gif>
<input type=radio name=r value=sln2 onchange=libRB()><img src=/img/s2.gif>
<td nowrap><input type=radio name=r value=sfn1 onchange=libRB()><img src=/img/s1.gif>
<input type=radio name=r value=sfn2 onchange=libRB()><img src=/img/s2.gif>
<td nowrap><input type=radio name=r value=smn1 onchange=libRB()><img src=/img/s1.gif>
<input type=radio name=r value=smn2 onchange=libRB()><img src=/img/s2.gif>
<td nowrap><input type=radio name=r value=sg1 onchange=libRB()><img src=/img/s1.gif>
<input type=radio name=r value=sg2 onchange=libRB()><img src=/img/s2.gif>
<td nowrap><input type=radio name=r value=ss1 onchange=libRB()><img src=/img/s1.gif>
<input type=radio name=r value=ss2 onchange=libRB()><img src=/img/s2.gif>
<td nowrap><input type=radio name=r value=sd1 onchange=libRB()><img src=/img/s1.gif>
<input type=radio name=r value=sd2 onchange=libRB()><img src=/img/s2.gif>
<tr>";
if ($type != 'a') $r .= "
<td><input id=t size=10 onKeyUp=libRB() value='$FirstTitle'>";
$r .= "
<td><input id=ln size=8 onKeyUp=libRB() value='$FirstLetter'>
<td><input id=fn size=8 onKeyUp=libRB()>
<td><input id=mn size=8 onKeyUp=libRB()>
<td><input id=g size=10 onKeyUp=libRB()>
<td nowrap>от <input id=s1 size=3 onKeyUp=libRB()>K до <input id=s2 size=3 onKeyUp=libRB()>K
<td>
<td><input id=e size=2 onKeyUp=libRB()>
<td><input id=lng size=2 onKeyUp=libRB()>
</table>";
if (!$type) $r .= " <input type=radio name=ab value=ab1 onchange=libRB()>Книги <input type=radio name=ab value=ab2 onchange=libRB()>Авторы\n";
$r .= "</form>\n";
$r .= "<div id=books><br></div>";
$r .= "<script>jQuery(document).ready(libRB)</script>";
return $r;
}