39 function GetResults($Item, $Filename, $tag, $Page, $SizeMin, $SizeMax, $searchtype,
40 $License, $Copyright, $uploadDao, $groupID,
$PG_CONN)
43 $UploadtreeRecs = array();
44 $totalUploadtreeRecs = array();
45 $totalUploadtreeRecsCount = 0;
46 $NeedTagfileTable =
true;
47 $NeedTaguploadtreeTable =
true;
51 $row = $uploadDao->getUploadEntry($Item);
53 $text = _(
"Invalid URL, nonexistant item");
54 return "<h2>$text $Item</h2>";
58 $upload_pk = $row[
"upload_fk"];
61 if (!$uploadDao->isAccessible($upload_pk, $groupID)) {
62 return array($UploadtreeRecs, $totalUploadtreeRecsCount);
67 $SQL =
"SELECT DISTINCT uploadtree_pk, parent, upload_fk, uploadtree.pfile_fk, ufile_mode, ufile_name FROM uploadtree";
69 if ($searchtype !=
"directory") {
70 if (! empty($License)) {
71 $SQL .=
", ( SELECT license_ref.rf_shortname, license_file.rf_fk, license_file.pfile_fk 72 FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk) AS pfile_ref";
74 if (! empty($Copyright)) {
81 $sql =
"select tag_pk from tag where tag ilike '" . pg_escape_string($tag) .
"'";
84 if (pg_num_rows($result) < 1) {
86 pg_free_result($result);
87 return array($UploadtreeRecs, $totalUploadtreeRecsCount);
91 $tag_pk_array = pg_fetch_all($result);
92 pg_free_result($result);
95 $sql =
"select tag_file_pk from tag_file limit 1";
98 if (pg_num_rows($result) < 1) {
100 $NeedTagfileTable =
false;
102 $SQL .=
", tag_file";
104 pg_free_result($result);
107 $sql =
"select tag_uploadtree_pk from tag_uploadtree limit 1";
110 if (pg_num_rows($result) < 1) {
112 $NeedTaguploadtreeTable =
false;
114 $SQL .=
", tag_uploadtree";
116 pg_free_result($result);
118 if (!$NeedTagfileTable && !$NeedTaguploadtreeTable) {
119 $SQL .=
", tag_file, tag_uploadtree";
124 if (!empty($SizeMin) or !empty($SizeMax)) {
125 $SQL .=
", pfile where pfile_pk=uploadtree.pfile_fk ";
139 foreach ($tag_pk_array as $tagRec) {
144 $tag_pk = $tagRec[
'tag_pk'];
145 if ($NeedTagfileTable && $NeedTaguploadtreeTable) {
146 $SQL .=
"(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk) ";
147 }
else if ($NeedTaguploadtreeTable) {
148 $SQL .=
"uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk";
149 }
else if ($NeedTagfileTable) {
150 $SQL .=
"uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk";
152 $SQL .=
"(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk) ";
165 $SQL .=
" ufile_name ilike '". pg_escape_string($Filename) .
"'";
169 if (!empty($SizeMin) && is_numeric($SizeMin)) {
173 $SQL .=
" pfile.pfile_size >= ".pg_escape_string($SizeMin);
177 if (!empty($SizeMax) && is_numeric($SizeMax)) {
181 $SQL .=
" pfile.pfile_size <= ".pg_escape_string($SizeMax);
189 $SQL .=
" upload_fk = $upload_pk AND lft >= $lft AND rgt <= $rgt";
194 if ($searchtype ==
'containers') {
198 $SQL .=
" ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)";
201 $dir_ufile_mode = 536888320;
202 if ($searchtype ==
'directory') {
206 $SQL .=
" ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) AND (ufile_mode != $dir_ufile_mode) and pfile_fk != 0";
211 if ($searchtype !=
"directory") {
212 if (! empty($License)) {
217 $SQL .=
" uploadtree.pfile_fk=pfile_ref.pfile_fk and pfile_ref.rf_shortname ilike '" .
218 pg_escape_string($License) .
"'";
221 if (! empty($Copyright)) {
225 $SQL .=
" uploadtree.pfile_fk=copyright.pfile_fk and copyright.content ilike '%" .
226 pg_escape_string($Copyright) .
"%'";
230 $Offset = $Page * $MaxPerPage;
231 $SQL .=
" ORDER BY ufile_name, uploadtree.pfile_fk";
234 if (pg_num_rows($result)) {
235 while ($row = pg_fetch_assoc($result)) {
236 if (! $uploadDao->isAccessible($row[
'upload_fk'], $groupID)) {
239 $totalUploadtreeRecs[] = $row;
242 pg_free_result($result);
243 $UploadtreeRecs = array_slice($totalUploadtreeRecs, $Offset, $MaxPerPage);
244 $totalUploadtreeRecsCount =
sizeof($totalUploadtreeRecs);
245 return array($UploadtreeRecs, $totalUploadtreeRecsCount);
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.