Upstream tarball 20080304
[amule.git] / src / webserver / php-default / amuleweb-main-search.php
blobcb47b8e7fc88ad4b8942b7f94718c3d76be5c5d6
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3 <html>
4 <head>
5 <title>amule download page</title>
6 <meta http-equiv="Content-Type" content="text/html; charset=utf8">
7 <style type="text/css">
8 <!--
9 body {
10 margin-left: 0px;
11 margin-top: 0px;
12 margin-right: 0px;
13 margin-bottom: 0px;
14 background-color: #003399;
16 -->
17 </style>
18 </head>
19 <script language="JavaScript" type="text/JavaScript">
20 function formCommandSubmit(command)
22 <?php
23 if ($_SESSION["guest_login"] != 0) {
24 echo 'alert("You logged in as guest - commands are disabled");';
25 echo "return;";
28 var frm=document.forms.mainform
29 frm.command.value=command
30 frm.submit()
33 </script>
35 <body>
36 <form name="mainform" action="amuleweb-main-search.php" method="post">
37 <table width="100%" border="0" bgcolor="#0099CC">
38 <tr>
39 <td width="100%"><table width="100%" border="0" cellpadding="2" cellspacing="2">
40 <tr>
41 <td colspan="5" scope="col"><table width="100%" border="1" align="left" cellpadding="0" cellspacing="0">
42 <tr>
43 <td width="625" bgcolor="#0099CC">
44 <input type="hidden" name="command" value="">
45 <input name="searchval" type="text" id="searchval" size="75">
46 <input name="Search" type="submit" id="Search" value="Search" onClick="javascript:formCommandSubmit('search');">
47 <div align="left">
48 </div></td>
49 <td width="278" bgcolor="#0099CC">
50 <input name="Download" type="submit" id="Download" value="Download" onClick="javascript:formCommandSubmit('download');" >
51 <img src="arrow-r.png" width="42" height="23"> <select name="targetcat" id="targetcat">
52 <?php
53 $cats = amule_get_categories();
54 foreach($cats as $c) {
55 echo "<option>", $c, "</option>";
58 </select></td>
59 </tr>
60 <tr>
61 <td bgcolor="#0099CC"><div align="left">
62 <label>Min size</label>
63 &nbsp;
64 <input name="minsize" type="text" id="minsize" size="5">
65 <select name="minsizeu" id="minsizeu">
66 <option>Byte</option>
67 <option>KByte</option>
68 <option selected>MByte</option>
69 <option>GByte</option>
70 </select>
71 <label>Max size</label>
72 &nbsp;
73 <input name="maxsize" type="text" id="maxsize" size="5">
74 <select name="maxsizeu" id="maxsizeu">
75 <option>Byte</option>
76 <option>KByte</option>
77 <option selected>MByte</option>
78 <option>GByte</option>
79 </select>
80 <label>Availability</label>
81 <input name="avail" type="text" id="avail" size="6">
82 <label>Search type </label>
83 <select name="searchtype" id="searchtype">
84 <option selected>Local</option>
85 <option>Global</option>
86 <option>Kad</option>
87 </select>
88 </div></td>
89 <td bgcolor="#0099CC"><a href="amuleweb-main-search.php" target="mainFrame">Click here to reload search results</a></td>
90 </tr>
91 </table></td>
92 </tr>
93 <tr>
94 <th width="22" scope="col">&nbsp;</th>
95 <th width="349" nowrap scope="col"><div align="left"><a href="amuleweb-main-search.php?sort=name" target="mainFrame">Filename</a></div></th>
96 <th width="99" nowrap scope="col"><div align="left"><a href="amuleweb-main-search.php?sort=size" target="mainFrame">Size</a></div></th>
97 <th width="96" nowrap scope="col"><div align="left"><a href="amuleweb-main-search.php?sort=sources" target="mainFrame">Sources</a></th>
98 <th width="222" nowrap scope="col">&nbsp;</th>
99 </tr>
101 <?php
102 function CastToXBytes($size)
104 if ( $size < 1024 ) {
105 $result = $size . " bytes";
106 } elseif ( $size < 1048576 ) {
107 $result = ($size / 1024.0) . "KB";
108 } elseif ( $size < 1073741824 ) {
109 $result = ($size / 1048576.0) . "MB";
110 } else {
111 $result = ($size / 1073741824.0) . "GB";
113 return $result;
117 // declare it here, before any function reffered it in "global"
119 $sort_order;$sort_reverse;
121 function my_cmp($a, $b)
123 global $sort_order, $sort_reverse;
125 switch ( $sort_order) {
126 case "size": $result = $a->size > $b->size; break;
127 case "name": $result = $a->name > $b->name; break;
128 case "sources": $result = $a->sources > $b->sources; break;
131 if ( $sort_reverse ) {
132 $result = !$result;
135 return $result;
138 function str2mult($str)
140 $result = 1;
141 switch($str) {
142 case "Byte": $result = 1; break;
143 case "KByte": $result = 1024; break;
144 case "MByte": $result = 1012*1024; break;
145 case "GByte": $result = 1012*1024*1024; break;
147 return $result;
150 function cat2idx($cat)
152 $cats = amule_get_categories();
153 $result = 0;
154 foreach($cats as $i => $c) {
155 if ( $cat == $c) $result = $i;
157 return $result;
160 if ($_SESSION["guest_login"] == 0) {
161 if ( $HTTP_GET_VARS["command"] == "search") {
162 $search_type = -1;
163 switch($HTTP_GET_VARS["searchtype"]) {
164 case "Local": $search_type = 0; break;
165 case "Global": $search_type = 1; break;
166 case "Kad": $search_type = 2; break;
168 $min_size = $HTTP_GET_VARS["minsize"] == "" ? 0 : $HTTP_GET_VARS["minsize"];
169 $max_size = $HTTP_GET_VARS["maxsize"] == "" ? 0 : $HTTP_GET_VARS["maxsize"];
171 $min_size *= str2mult($HTTP_GET_VARS["minsizeu"]);
172 $max_size *= str2mult($HTTP_GET_VARS["maxsizeu"]);
174 amule_do_search_start_cmd($HTTP_GET_VARS["searchval"],
175 //$HTTP_GET_VARS["ext"], $HTTP_GET_VARS["filetype"],
176 "", "",
177 $search_type, $HTTP_GET_VARS["avail"], $min_size, $max_size);
178 } elseif ( $HTTP_GET_VARS["command"] == "download") {
179 foreach ( $HTTP_GET_VARS as $name => $val) {
180 // this is file checkboxes
181 if ( (strlen($name) == 32) and ($val == "on") ) {
182 $cat = $HTTP_GET_VARS["targetcat"];
183 $cat_idx = cat2idx($cat);
184 amule_do_search_download_cmd($name, $cat_idx);
187 } else {
190 $search = amule_load_vars("searchresult");
192 $sort_order = $HTTP_GET_VARS["sort"];
194 if ( $sort_order == "" ) {
195 $sort_order = $_SESSION["search_sort"];
196 } else {
197 if ( $_SESSION["search_sort_reverse"] == "" ) {
198 $_SESSION["search_sort_reverse"] = 0;
199 } else {
200 $_SESSION["search_sort_reverse"] = !$_SESSION["search_sort_reverse"];
204 $sort_reverse = $_SESSION["search_sort_reverse"];
205 if ( $sort_order != "" ) {
206 $_SESSION["search_sort"] = $sort_order;
207 usort(&$search, "my_cmp");
210 foreach ($search as $file) {
211 print "<tr>";
213 echo "<td>", '<input type="checkbox" name="', $file->hash, '" >', "</td>";
215 echo "<td nowrap>", $file->short_name, "</td>";
217 echo "<td>", CastToXBytes($file->size), "</td>";
219 echo "<td>", $file->sources, "</td>";
221 print "</tr>";
226 </table></td>
227 </tr>
228 </table>
229 </form>
230 </body>
231 </html>