/** * \brief Given a folder_pk, try to add a job after checking permissions. * \param $uploadpk - the upload(upload_id) you want to delete * * \return string with the message. */ function TryToDelete($uploadpk) { if (!GetUploadPerm($uploadpk) >= Auth::PERM_WRITE) { $text = _("You dont have permissions to delete the upload"); return DisplayMessage($text); } $rc = $this->Delete($uploadpk); if (!empty($rc)) { $text = _("Deletion Scheduling failed: "); return DisplayMessage($text . $rc); } /* Need to refresh the screen */ $URL = Traceback_uri() . "?mod=showjobs&upload={$uploadpk} "; $LinkText = _("View Jobs"); $text = _("Deletion added to job queue."); $msg = "{$text} <a href={$URL}>{$LinkText}</a>"; return displayMessage($msg); }
/** * \brief Display the loaded menu and plugins. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $action = GetParm("action", PARM_STRING); $id = GetParm("id", PARM_STRING); $upload = GetParm("upload", PARM_INTEGER); if (($action == "update" || $action == "delete") && !isset($id)) { $text = _("Wrong request"); echo "<h2>{$text}</h2>"; return; } else { if (isset($id)) { list($upload, $item, $hash, $type) = explode(",", $id); } } /* check upload permissions */ $UploadPerm = GetUploadPerm($upload); if ($UploadPerm < Auth::PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}</h2>"; return; } $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload); switch ($action) { case "getData": return $this->doGetData($upload); case "update": return $this->doUpdate($item, $hash, $type); case "delete": return $this->doDelete($item, $hash, $type); case "undo": return $this->doUndo($item, $hash, $type); } }
/** * \brief Display the tagging page. */ function ShowTaggingPage($ShowMenu = 0, $ShowHeader = 0, $action) { $V = ""; $Upload = GetParm("upload", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); if (empty($Item) || empty($Upload)) { return; } /********************************** Display micro header **********************************/ if ($ShowHeader) { $V .= Dir2Browse("browse", $Item, NULL, 1, "Browse"); } // if ShowHeader /* Display exist tags for this file */ $V .= $this->ShowExistTags($Upload, $Item); /* Add AJAX script */ $V .= $this->ShowAjaxPage(); if ($action == 'edit') { $V .= $this->ShowEditTagPage($Upload, $Item); } else { /* Show create tag page */ $perm = GetUploadPerm($Upload); if ($perm >= PERM_WRITE) { $V .= $this->ShowCreateTagPage($Upload, $Item); } else { $nopermtext = _("You do not have permission to tag this upload."); $V .= $nopermtext; } /* Show delete tag page removing $V .= $this->ShowDeleteTagPage($Upload,$Item); */ } return $V; }
/** * \brief This function is called when user output is * requested. This function is responsible for content. * (OutputOpen and Output are separated so one plugin * can call another plugin's Output.) * This uses $OutputType. * The $ToStdout flag is "1" if output should go to stdout, and * 0 if it should be returned as a string. (Strings may be parsed * and used by other plugins.) */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } $Folder = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { return; } $Item = GetParm("item", PARM_INTEGER); $V = ""; switch ($this->OutputType) { case "XML": break; case "HTML": $V .= Dir2Browse("browse", $Item, NULL, 1, "View-Meta"); $V .= $this->ShowTagInfo($Upload, $Item); $V .= $this->ShowPackageinfo($Upload, $Item, 1); $V .= $this->ShowMetaView($Upload, $Item); $V .= $this->ShowSightings($Upload, $Item); $V .= $this->ShowView($Upload, $Item); break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief Display the loaded menu and plugins. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; global $PG_CONN; // make sure there is a db connection if (!$PG_CONN) { echo _("NO DB connection"); } $OutBuf = ""; $Time = microtime(true); $Max = 50; /* Input parameters */ $agent_pk = GetParm("agent", PARM_INTEGER); $uploadtree_pk = GetParm("item", PARM_INTEGER); $hash = GetParm("hash", PARM_RAW); $type = GetParm("type", PARM_RAW); $excl = GetParm("excl", PARM_RAW); $filter = GetParm("filter", PARM_RAW); if (empty($uploadtree_pk) || empty($hash) || empty($type) || empty($agent_pk)) { $text = _("is missing required parameters"); echo $this->Name . " {$text}."; return; } /* Check item1 and item2 upload permissions */ $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}"); $UploadPerm = GetUploadPerm($Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } /* get all rows */ $rows = $this->GetRows($uploadtree_pk, $agent_pk, $upload_pk); /* Get uploadtree_tablename */ $uploadtree_tablename = GetUploadtreeTableName($upload_pk); /* slim down to all rows with this hash and type, and filter */ $NumInstances = 0; $rows = $this->GetRequestedRows($rows, $hash, $type, $excl, $NumInstances, $filter); //debugprint($rows, "rows"); switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $OutBuf .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); $RowCount = count($rows); if ($RowCount) { $Content = htmlentities($rows[0]['content']); $Offset = $Page < 0 ? 0 : $Page * $Max; $PkgsOnly = false; $text = _("files"); $text1 = _("unique"); $text3 = _("copyright"); $text4 = _("email"); $text5 = _("url"); switch ($type) { case "statement": $TypeStr = "{$text3}"; break; case "email": $TypeStr = "{$text4}"; break; case "url": $TypeStr = "{$text5}"; break; } $OutBuf .= "{$NumInstances} {$TypeStr} instances found in {$RowCount} {$text}"; $OutBuf .= ": <b>{$Content}</b>"; $text = _("Display excludes files with these extensions"); if (!empty($excl)) { $OutBuf .= "<br>{$text}: {$excl}"; } /* Get the page menu */ if ($RowCount >= $Max && $Page >= 0) { $PagingMenu = "<P />\n" . MenuEndlessPage($Page, intval(($RowCount + $Offset) / $Max)) . "<P />\n"; $OutBuf .= $PagingMenu; } else { $PagingMenu = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $RowNum = $Offset; $LinkLast = "copyrightview&agent={$agent_pk}"; $ShowBox = 1; $ShowMicro = NULL; // base url $ucontent = rawurlencode($Content); $baseURL = "?mod=" . $this->Name . "&agent={$agent_pk}&item={$uploadtree_pk}&hash={$hash}&type={$type}&page=-1"; // display rows foreach ($rows as $row) { // Allow user to exclude files with this extension $FileExt = GetFileExt($row['ufile_name']); if (empty($excl)) { $URL = $baseURL . "&excl={$FileExt}"; } else { $URL = $baseURL . "&excl={$excl}:{$FileExt}"; } $text = _("Exclude this file type"); $Header = "<a href={$URL}>{$text}.</a>"; $ok = true; if ($excl) { $ExclArray = explode(":", $excl); if (in_array($FileExt, $ExclArray)) { $ok = false; } } if ($ok) { $OutBuf .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); } } } else { $OutBuf .= _("No files found"); } if (!empty($PagingMenu)) { $OutBuf .= $PagingMenu . "\n"; } $OutBuf .= "<hr>\n"; $Time = microtime(true) - $Time; $text = _("Elapsed time"); $text1 = _("seconds"); $OutBuf .= sprintf("<small>{$text}: %.2f {$text1}</small>\n", $Time); break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $OutBuf; } print $OutBuf; return; }
/** * \brief Generate the view contents in HTML and sends it * to stdout. * * \param $Name - the name for this plugin. * * \note This function is intended to be called from other plugins. */ function ShowView($Fin = NULL, $BackMod = "browse", $ShowMenu = 1, $ShowHeader = 1, $ShowText = NULL, $ViewOnly = False, $DispView = True) { if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; global $Plugins; $Upload = GetParm("upload", PARM_INTEGER); if (!empty($Upload)) { $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { return; } } $Folder = GetParm("folder", PARM_INTEGER); $Show = GetParm("show", PARM_STRING); $Item = GetParm("item", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $Page = GetParm("page", PARM_INTEGER); $bucketagent_pk = GetParm("bapk", PARM_INTEGER); if (!$Fin && (empty($Item) || empty($Upload))) { return; } if (empty($Page)) { $Page = 0; } /* Get uploadtree table name */ $uploadtree_tablename = "uploadtree"; if (!empty($Upload)) { $uploadtree_tablename = GetUploadtreeTablename($Upload); } switch (GetParm("format", PARM_STRING)) { case 'hex': $Format = 'hex'; break; case 'text': $Format = 'text'; break; case 'flow': $Format = 'flow'; break; default: /* Determine default show based on mime type */ if (empty($Item)) { $Format = 'text'; } else { $Meta = GetMimeType($Item); list($Type, $Junk) = explode("/", $Meta, 2); if ($Type == 'text') { $Format = 'flow'; } else { switch ($Meta) { case "application/octet-string": case "application/x-awk": case "application/x-csh": case "application/x-javascript": case "application/x-perl": case "application/x-shellscript": case "application/x-rpm-spec": case "application/xml": case "message/rfc822": $Format = 'flow'; break; default: $Format = 'flow'; } } } break; } /********************************** Display micro header **********************************/ if ($ShowHeader) { $Uri = Traceback_uri() . "?mod=browse"; $Opt = ""; if (!empty($Item)) { $Opt .= "&item={$Item}"; } if (!empty($Upload)) { $Opt .= "&upload={$Upload}"; } if (!empty($Folder)) { $Opt .= "&folder={$Folder}"; } if (!empty($Show)) { $Opt .= "&show={$Show}"; } /* No item */ $V .= Dir2Browse($BackMod, $Item, NULL, 1, "View", -1, '', '', $uploadtree_tablename) . "<P />\n"; } // if ShowHeader $this->SortHighlightMenu(); /*********************************** Display file contents ***********************************/ print $V; $V = ""; $openedFin = False; if (empty($Fin)) { $Fin = @fopen(RepPathItem($Item), "rb"); if ($Fin) { $openedFin = true; } if (empty($Fin)) { /* Added by vincent implement when view files which not in repository, ask user if want to reunpack*/ /** BEGIN **/ /* If this is a POST, then process the request. */ $uploadunpack = GetParm('uploadunpack', PARM_INTEGER); $uploadpk = $Upload; $flag = 0; $P =& $Plugins[plugin_find_id("ui_reunpack")]; $state = $P->CheckStatus($uploadpk, "reunpack", "ununpack"); //print "<p>$state</p>"; if ($state == 0 || $state == 2) { if (!empty($uploadunpack)) { $rc = $P->AgentAdd($uploadpk); if (empty($rc)) { /* Need to refresh the screen */ $text = _("Unpack added to job queue"); $V .= displayMessage($text); $flag = 1; $text = _("Reunpack job is running: you can see it in"); $text1 = _("jobqueue"); print "<p> <font color=red>{$text} <a href='" . Traceback_uri() . "?mod=showjobs'>{$text1}</a></font></p>"; } else { $text = _("Unpack of Upload failed"); $V .= displayMessage("{$text}: {$rc}"); } print $V; } } else { $flag = 1; $text = _("Reunpack job is running: you can see it in"); $text1 = _("jobqueue"); print "<p> <font color=red>{$text} <a href='" . Traceback_uri() . "?mod=showjobs'>{$text1}</a></font></p>"; } $text = _("File contents are not available in the repository."); print "{$text}\n"; $P =& $Plugins[plugin_find_id("ui_reunpack")]; print $P->ShowReunpackView($Item, $flag); return; } /** END **/ } rewind($Fin); $Pages = ""; $Uri = preg_replace('/&page=[0-9]*/', '', Traceback()); $HighlightMenu = ""; $HighlightMenu .= "</center>"; // some fcn left a dangling center if ($Format == 'hex') { $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_HEX, $ViewOnly, $DispView); if (!empty($HighlightMenu)) { print "<center>{$HighlightMenu}</center><hr>\n"; } $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_HEX, $Uri); $PageSize = VIEW_BLOCK_HEX * $Page; if (!empty($PageMenu)) { print "<center>{$PageMenu}</center><br>\n"; } $this->ShowHex($Fin, $PageSize, VIEW_BLOCK_HEX); if (!empty($PageMenu)) { print "<P /><center>{$PageMenu}</center><br>\n"; } } else { if ($Format == 'text') { $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_TEXT, $ViewOnly, $DispView); if (!empty($HighlightMenu)) { print "<center>{$HighlightMenu}</center><hr>\n"; } $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_TEXT, $Uri); $PageSize = VIEW_BLOCK_TEXT * $Page; if (!empty($PageMenu)) { print "<center>{$PageMenu}</center><br>\n"; } $this->ShowText($Fin, $PageSize, 0, VIEW_BLOCK_TEXT); if (!empty($PageMenu)) { print "<P /><center>{$PageMenu}</center><br>\n"; } } else { if ($Format == 'flow') { $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_TEXT, $ViewOnly, $DispView); if (!empty($HighlightMenu)) { print "<center>{$HighlightMenu}</center><hr>\n"; } $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_TEXT, $Uri); $PageSize = VIEW_BLOCK_TEXT * $Page; if (!empty($PageMenu)) { print "<center>{$PageMenu}</center><br>\n"; } if (!empty($ShowText)) { echo $ShowText, "<hr>"; } $this->ShowText($Fin, $PageSize, 1, VIEW_BLOCK_TEXT); if (!empty($PageMenu)) { print "<P /><center>{$PageMenu}</center><br>\n"; } } } } if ($openedFin) { fclose($Fin); } return; }
/** * \brief check if tagging on one upload is disabled or not * * \param $upload_id - upload id * * \return 1: enabled; 0: disabled, or no write permission */ function TagStatus($upload_id) { global $PG_CONN; $UploadPerm = GetUploadPerm($upload_id); if ($UploadPerm < PERM_WRITE) { return 0; } /** check if this upload has been disabled */ $sql = "select tag_manage_pk from tag_manage where upload_fk = {$upload_id} and is_disabled = true;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $count = pg_num_rows($result); pg_free_result($result); if ($count > 0) { return 0; } else { return 1; } }
/** * @brief Output(): * Requires:\n filter: optional filter to apply\n item1: uploadtree_pk of the column 1 tree\n item2: uploadtree_pk of the column 2 tree\n freeze: column number (1 or 2) to freeze */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $uTime = microtime(true); $V = ""; /**/ $UpdCache = GetParm("updcache", PARM_INTEGER); /* Remove "updcache" from the GET args and set $this->UpdCache * This way all the url's based on the input args won't be * polluted with updcache * Use Traceback_parm_keep to ensure that all parameters are in order */ $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("item1", "item2", "filter", "col", "freeze", "itemf")); if ($UpdCache) { $UpdCache = $_GET['updcache']; $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/", "", $_SERVER['REQUEST_URI']); unset($_GET['updcache']); $V = ReportCachePurgeByKey($CacheKey); } else { $V = ReportCacheGet($CacheKey); } /**/ if (empty($V)) { $filter = GetParm("filter", PARM_STRING); if (empty($filter)) { $filter = "none"; } $FreezeCol = GetParm("freeze", PARM_INTEGER); // which column to freeze? 1 or 2 or null $ClickedCol = GetParm("col", PARM_INTEGER); // which column was clicked on? 1 or 2 or null $ItemFrozen = GetParm("itemf", PARM_INTEGER); // frozen item or null $in_uploadtree_pk1 = GetParm("item1", PARM_INTEGER); $in_uploadtree_pk2 = GetParm("item2", PARM_INTEGER); if (empty($in_uploadtree_pk1) || empty($in_uploadtree_pk2)) { Fatal("Bad input parameters. Both item1 and item2 must be specified.", __FILE__, __LINE__); } /* If you click on a item in a frozen column, then you are a dope so ignore $ItemFrozen */ if ($FreezeCol == $ClickedCol) { $ItemFrozen = 0; $FreezeCol = 0; } /* Check item1 upload permission */ $Item1Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$in_uploadtree_pk1}"); $UploadPerm = GetUploadPerm($Item1Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text} item 1<h2>"; return; } /* Check item2 upload permission */ $Item2Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$in_uploadtree_pk2}"); $UploadPerm = GetUploadPerm($Item2Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text} item 2<h2>"; return; } $uploadtree_pk1 = $in_uploadtree_pk1; $uploadtree_pk2 = $in_uploadtree_pk2; if ($FreezeCol == 1) { $uploadtree_pk1 = $ItemFrozen; } else { if ($FreezeCol == 2) { $uploadtree_pk2 = $ItemFrozen; } } $newURL = Traceback_dir() . "?mod=" . $this->Name . "&item1={$uploadtree_pk1}&item2={$uploadtree_pk2}"; if (!empty($filter)) { $newURL .= "&filter={$filter}"; } // rewrite page with new uploadtree_pks */ if ($uploadtree_pk1 != $in_uploadtree_pk1 || $uploadtree_pk2 != $in_uploadtree_pk2) { print <<<JSOUT <script type="text/javascript"> window.location.assign('{$newURL}'); </script> JSOUT; } $TreeInfo1 = $this->GetTreeInfo($uploadtree_pk1); $TreeInfo2 = $this->GetTreeInfo($uploadtree_pk2); $ErrText = _("No license data for tree %d. Use Jobs > Agents to schedule a license scan."); $ErrMsg = ''; if ($TreeInfo1['agent_pk'] == 0) { $ErrMsg = sprintf($ErrText, 1); } else { if ($TreeInfo2['agent_pk'] == 0) { $ErrMsg = sprintf($ErrText, 2); } else { $BucketDefArray = initBucketDefArray($TreeInfo1['bucketpool_pk']); /* Get list of children */ $Children1 = GetNonArtifactChildren($uploadtree_pk1); $Children2 = GetNonArtifactChildren($uploadtree_pk2); /* Add fuzzyname to children */ FuzzyName($Children1); // add fuzzyname to children FuzzyName($Children2); // add fuzzyname to children /* add element licstr to children */ $this->AddBucketStr($TreeInfo1, $Children1, $BucketDefArray); $this->AddBucketStr($TreeInfo2, $Children2, $BucketDefArray); /* Master array of children, aligned. */ $Master = MakeMaster($Children1, $Children2); /* add linkurl to children */ FileList($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'], $filter, $this, $uploadtree_pk1, $uploadtree_pk2); /* Apply filter */ $this->FilterChildren($filter, $Master, $BucketDefArray); } } switch ($this->OutputType) { case "XML": break; case "HTML": if ($ErrMsg) { $V .= $ErrMsg; } else { $V .= $this->HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray); } break; case "Text": break; default: } $Cached = false; } else { $Cached = true; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); printf("<small>{$text}</small>", $Time); /**/ if ($Cached) { $text = _("cached"); $text1 = _("Update"); echo " <i>{$text}</i> <a href=\"{$_SERVER['REQUEST_URI']}&updcache=1\"> {$text1} </a>"; } else { // Cache Report if this took longer than 1/2 second if ($Time > 0.5) { ReportCachePut($CacheKey, $V); } } /**/ return; }
function Output() { global $PG_CONN; if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; $folder_pk = GetParm('folder', PARM_TEXT); $FolderSelectId = GetParm('selectfolderid', PARM_INTEGER); if (empty($FolderSelectId)) { $FolderSelectId = GetUserRootFolder(); } $NewName = GetArrayVal("newname", $_POST); $NewDesc = GetArrayVal("newdesc", $_POST); $upload_pk = GetArrayVal("upload_pk", $_POST); if (empty($upload_pk)) { $upload_pk = GetParm('upload', PARM_INTEGER); } /* Check Upload permission */ if (!empty($upload_pk)) { $UploadPerm = GetUploadPerm($upload_pk); if ($UploadPerm < PERM_WRITE) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } } $rc = $this->UpdateUploadProperties($upload_pk, $NewName, $NewDesc); if ($rc == 0) { $text = _("Nothing to Change"); $V .= displayMessage($text); } else { if ($rc == 1) { $text = _("Upload Properties successfully changed"); $V .= displayMessage($text); } } /* define js_url */ $V .= js_url(); /* Build the HTML form */ $V .= "<form name='formy' method='post'>\n"; // no url = this url $V .= "<ol>\n"; $text = _("Select the folder that contains the upload: \n"); $V .= "<li>{$text}"; /*** Display folder select list, on change request new page with folder= in url ***/ $Uri = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid="; $V .= "<select name='oldfolderid' onChange='window.location.href=\"{$Uri}\" + this.value'>\n"; $V .= FolderListOption(-1, 0, 1, $FolderSelectId); $V .= "</select><P />\n"; /*** Display upload select list, on change, request new page with new upload= in url ***/ $text = _("Select the upload you wish to edit: \n"); $V .= "<li>{$text}"; // Get list of all upload records in this folder $UploadList = FolderListUploads_perm($FolderSelectId, PERM_WRITE); // Make data array for upload select list. Key is upload_pk, value is a composite // of the upload_filename and upload_ts. $UploadArray = array(); foreach ($UploadList as $UploadRec) { $SelectText = htmlentities($UploadRec['name']); if (!empty($UploadRec['upload_ts'])) { $SelectText .= ", " . substr($UploadRec['upload_ts'], 0, 19); } $UploadArray[$UploadRec['upload_pk']] = $SelectText; } /* Get selected upload info to display*/ if (empty($upload_pk)) { // no upload selected, so use the top one in the select list reset($UploadArray); $upload_pk = key($UploadArray); } if ($upload_pk) { // case where upload is set in the URL $sql = "SELECT * FROM upload WHERE upload_pk = '{$upload_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) == 0) { /* Bad upload_pk */ $text = _("Missing upload."); $V .= displayMessage($text); pg_free_result($result); return 0; } $UploadRec = pg_fetch_assoc($result); pg_free_result($result); $V .= "<INPUT type='hidden' name='upload_pk' value='{$upload_pk}' />\n"; } else { // no uploads in the folder $UploadRec = array(); } $url = Traceback_uri() . "?mod=upload_properties&folder={$folder_pk}&upload="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($UploadArray, "uploadselect", $upload_pk, false, false, $onchange); /* Input upload_filename */ $text = _("Upload name: \n"); $V .= "<li>{$text}"; if (empty($UploadRec['upload_filename'])) { $upload_filename = ""; } else { $upload_filename = htmlentities($UploadRec['upload_filename']); } $V .= "<INPUT type='text' name='newname' size=40 value='{$upload_filename}' />\n"; /* Input upload_desc */ $text = _("Upload description: \n"); $V .= "<li>{$text}"; if (empty($UploadRec['upload_desc'])) { $upload_desc = ""; } else { $upload_desc = htmlentities($UploadRec['upload_desc'], ENT_QUOTES); } $V .= "<INPUT type='text' name='newdesc' size=60 value='{$upload_desc}' />\n"; $V .= "</ol>\n"; $text = _("Edit"); $V .= "<input type='submit' value='{$text}!'>\n"; $V .= "</form>\n"; if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief Get uploads and folder info, starting from $ParentFolder. * The array is sorted by folder and upload name. * Folders that are empty do not show up. * This is recursive! * NOTE: If there is a recursive loop in the folder table, then * this will loop INFINITELY. * * \param $ParentFolder folder_pk, -1 for users root folder * \param $FolderPath Used for recursion, caller should not specify. * * \return array of {upload_pk, upload_desc, name, folder} */ function FolderListUploadsRecurse($ParentFolder = -1, $FolderPath = NULL, $perm = PERM_READ) { global $PG_CONN; if (empty($PG_CONN)) { return; } if (empty($ParentFolder)) { return; } if ($ParentFolder == "-1") { $ParentFolder = FolderGetTop(); } $List = array(); /* Get list of uploads */ /** mode 1<<1 = upload_fk **/ $sql = "SELECT upload_pk, upload_desc, ufile_name, folder_name FROM folder,foldercontents,uploadtree, upload\n WHERE \n foldercontents.parent_fk = '{$ParentFolder}'\n AND foldercontents.foldercontents_mode = 2 \n AND foldercontents.child_id = upload.upload_pk\n AND folder.folder_pk = {$ParentFolder}\n AND uploadtree.upload_fk = upload.upload_pk\n AND uploadtree.parent is null\n ORDER BY uploadtree.ufile_name,upload.upload_desc;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($R = pg_fetch_assoc($result)) { if (empty($R['upload_pk'])) { continue; } /* Check upload permission */ $UploadPerm = GetUploadPerm($R['upload_pk']); if ($UploadPerm < $perm) { continue; } $New['upload_pk'] = $R['upload_pk']; $New['upload_desc'] = $R['upload_desc']; $New['name'] = $R['ufile_name']; $New['folder'] = $FolderPath . "/" . $R['folder_name']; array_push($List, $New); } pg_free_result($result); /* Get list of subfolders and recurse */ /** mode 1<<0 = folder_pk **/ $sql = "SELECT A.child_id AS id,B.folder_name AS folder,B.folder_name AS subfolder\n\tFROM foldercontents AS A\n\tINNER JOIN folder AS B ON A.parent_fk = B.folder_pk\n\tAND A.foldercontents_mode = 1\n\tAND A.parent_fk = '{$ParentFolder}'\n AND B.folder_pk = {$ParentFolder}\n\tORDER BY B.folder_name;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($R = pg_fetch_assoc($result)) { if (empty($R['id'])) { continue; } /* RECURSE! */ $SubList = FolderListUploadsRecurse($R['id'], $FolderPath . "/" . $R['folder']); $List = array_merge($List, $SubList); } pg_free_result($result); /* Return findings */ return $List; }
/** * \brief This function is called when user output is * requested. This function is responsible for content. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; global $PG_CONN; if (!$PG_CONN) { DBconnect(); if (!$PG_CONN) { $text = _("Missing database connection."); echo "<h2>{$text}</h2>"; return; } } $Item = GetParm("item", PARM_INTEGER); $text = _("Invalid item parameter"); if (empty($Item)) { echo "<h2>{$text}</h2>"; return; } $Filename = RepPathItem($Item); if (empty($Filename)) { echo "<h2>{$text}: {$Filename}</h2>"; return; } $Fin = @fopen(RepPathItem($Item), "rb"); /* note that CheckRestore() does not return. */ if (empty($Fin)) { $this->CheckRestore($Item, $Filename); } $sql = "SELECT ufile_name, upload_fk FROM uploadtree WHERE uploadtree_pk = {$Item} LIMIT 1;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); if (pg_num_rows($result) != 1) { $text = _("Missing item"); echo "<h2>{$text}: {$Item}</h2>"; pg_free_result($result); return; } $Upload = $row['upload_fk']; $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_WRITE) { $text = _("No Permission"); echo "<h2>{$text}: {$Item}</h2>"; return; } $Name = $row['ufile_name']; pg_free_result($result); if (($rv = DownloadFile($Filename, $Name)) !== True) { $text = _("Download failed"); echo "<h2>{$text}</h2>{$Filename}<br>{$rv}"; } }
/** * \brief Generate the text for this plugin. */ function Output() { global $Plugins; global $PG_CONN; global $PERM_NAMES; if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; switch ($this->OutputType) { case "XML": break; case "HTML": $text = _("Move upload to different folder."); $V .= "<H2>{$text}</H1>\n"; /* If this is a POST, then process the request. */ $OldFolderId = GetParm('oldfolderid', PARM_INTEGER); $UploadId = GetParm('uploadid', PARM_INTEGER); $TargetFolderId = GetParm('targetfolderid', PARM_INTEGER); if (!empty($OldFolderId) && !empty($TargetFolderId)) { /* check upload permission */ $UploadPerm = GetUploadPerm($UploadId); if ($UploadPerm < PERM_WRITE) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } $rc = $this->Move($UploadId, $TargetFolderId, $OldFolderId); if ($rc == 1) { /* Need to refresh the screen */ $sql = "SELECT * FROM folder where folder_pk = '{$TargetFolderId}';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $NRow = pg_fetch_assoc($result); pg_free_result($result); $sql = "SELECT pfile_fk FROM upload WHERE upload_pk='{$UploadId}';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); pg_free_result($result); $pfileNum = $row['pfile_fk']; $sql = "SELECT ufile_name FROM uploadtree WHERE " . "upload_fk='{$UploadId}' and pfile_fk={$pfileNum};"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); pg_free_result($result); $base = basename($row['ufile_name']); $sql = "SELECT * FROM folder where folder_pk = '{$OldFolderId}';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $ORow = pg_fetch_assoc($result); pg_free_result($result); $text = _("Moved"); $text1 = _("from folder"); $text2 = _("to folder"); $success = "{$text} {$base} {$text1} {$ORow['folder_name']} {$text2} {$NRow['folder_name']}"; $V .= displayMessage($success); } } /* Create the AJAX (Active HTTP) javascript for doing the reply and showing the response. */ $V .= ActiveHTTPscript("Uploads"); $V .= "<script language='javascript'>\n"; $V .= "function Uploads_Reply()\n"; $V .= " {\n"; $V .= " if ((Uploads.readyState==4) && (Uploads.status==200))\n"; $V .= " {\n"; /* Remove all options */ $V .= " document.getElementById('uploaddiv').innerHTML = '<select name=\\'uploadid\\'>' + Uploads.responseText + '</select><P />';\n"; /* Add new options */ $V .= " }\n"; $V .= " }\n"; $V .= "</script>\n"; /* Build the HTML form */ $V .= "<form name='formy' method='post'>\n"; // no url = this url /* Display the form */ $V .= "<form method='post'>\n"; // no url = this url $V .= "<ol>\n"; $text = _("Select the folder containing the upload you wish to move: \n"); $V .= "<li>{$text}"; $V .= "<select name='oldfolderid'\n"; $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=-1' "; $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n"; $root_folder_pk = GetUserRootFolder(); $V .= FolderListOption($root_folder_pk, 0); $V .= "</select><P />\n"; $text = _("Select the upload you wish to move: \n"); $V .= "<li>{$text}"; $V .= "<div id='uploaddiv'>\n"; $V .= "<select name='uploadid'>\n"; $List = FolderListUploads_perm($root_folder_pk, PERM_WRITE); foreach ($List as $L) { $V .= "<option value='" . $L['upload_pk'] . "'>"; $V .= htmlentities($L['name']); if (!empty($L['upload_desc'])) { $V .= " (" . htmlentities($L['upload_desc']) . ")"; } if (!empty($L['upload_ts'])) { $V .= " :: " . substr($L['upload_ts'], 0, 19); } $V .= "</option>\n"; } $V .= "</select><P />\n"; $V .= "</div>\n"; $text = _("Select the destination folder: \n"); $V .= "<li>{$text}"; $V .= "<select name='targetfolderid'>\n"; $V .= FolderListOption($root_folder_pk, 0); $V .= "</select><P />\n"; $V .= "</ol>\n"; $text = "Move"; $V .= "<input type='submit' value='{$text}!'>\n"; $V .= "</form>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief This function returns the scheduler status. */ function Output() { global $SysConf; global $PG_CONN; if (!$PG_CONN) { echo _("NO DB connection"); } if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $uploadtree_pk = GetParm("item", PARM_INTEGER); if (empty($uploadtree_pk)) { return; } $upload_pk = GetParm("upload", PARM_INTEGER); if (empty($upload_pk)) { return; } $UploadPerm = GetUploadPerm($upload_pk); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } if (GetParm("output", PARM_STRING) == 'dltext') { $dltext = true; } else { $dltext = false; } /* get last nomos agent_pk that has data for this upload */ $Agent_name = "nomos"; $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1); $agent_pk = $AgentRec[0]["agent_fk"]; if ($AgentRec === false) { echo _("No data available"); return; } /* how many lines of data do you want to display */ $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum']; /* get the top of tree */ $sql = "SELECT upload_fk, lft, rgt from uploadtree where uploadtree_pk='{$uploadtree_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $toprow = pg_fetch_assoc($result); pg_free_result($result); /* loop through all the records in this tree */ $sql = "select uploadtree_pk, ufile_name, lft, rgt from uploadtree\n where upload_fk='{$toprow['upload_fk']}' \n and lft>'{$toprow['lft']}' and rgt<'{$toprow['rgt']}'\n and ((ufile_mode & (1<<28)) = 0) and ((ufile_mode & (1<<29)) = 0) limit {$NomostListNum}"; $outerresult = pg_query($PG_CONN, $sql); DBCheckResult($outerresult, $sql, __FILE__, __LINE__); /* Select each uploadtree row in this tree, write out text: * filepath : license list * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity */ $uploadtree_tablename = GetUploadtreeTableName($toprow['upload_fk']); while ($row = pg_fetch_assoc($outerresult)) { $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename); $filepath = ""; foreach ($filepatharray as $uploadtreeRow) { if (!empty($filepath)) { $filepath .= "/"; } $filepath .= $uploadtreeRow['ufile_name']; } $V .= $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtree_tablename); if ($dltext) { $V .= "\n"; } else { $V .= "<br>"; } } $RealNumber = pg_num_rows($outerresult); pg_free_result($outerresult); if ($RealNumber == $NomostListNum) { $V .= _("<br><B>Warning: Only the last {$NomostListNum} lines are displayed. To see the whole list, run fo_nomos_license_list from the command line.</B><br>"); } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
$upload_pk_array = array(); if ($upload_options == 'ALL') { $SQL = "SELECT upload_pk,upload_desc,upload_filename FROM upload ORDER BY upload_pk;"; $result = pg_query($PG_CONN, $SQL); DBCheckResult($result, $SQL, __FILE__, __LINE__); while ($row = pg_fetch_assoc($result) and !empty($row['upload_pk'])) { $upload_pk_array[] = $row['upload_pk']; } pg_free_result($result); } else { if (is_array($upload_options)) { $upload_pk_array = $upload_options; } else { $upload_pk_array[] = $upload_options; } } /* check permissions */ $checked_list = array(); foreach ($upload_pk_array as $upload_pk) { $UploadPerm = GetUploadPerm($upload_pk); if ($UploadPerm < PERM_WRITE) { print "You have no permission to delete upload " . $upload_pk . "\n"; continue; } $checked_list[] = $upload_pk; } $checked_list_str = implode(",", $checked_list); /** scheduling delagent tasks on upload ids */ QueueUploadsOnDelagents($checked_list_str, $Verbose); } exit(0);
/** * \brief Display all the files for a bucket in this subtree. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; global $PG_CONN; /* Input parameters */ $bucketagent_pk = GetParm("bapk", PARM_INTEGER); $uploadtree_pk = GetParm("item", PARM_INTEGER); $bucket_pk = GetParm("bpk", PARM_INTEGER); $bucketpool_pk = GetParm("bp", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $BinNoSrc = GetParm("bns", PARM_INTEGER); // 1 if requesting binary with no src $Excl = GetParm("excl", PARM_RAW); if (empty($uploadtree_pk) || empty($bucket_pk) || empty($bucketpool_pk)) { $text = _("is missing required parameters."); echo $this->Name . " {$text}"; return; } /* Check upload permission */ $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}"); $UploadPerm = GetUploadPerm($Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text} item 1<h2>"; return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } $V = ""; $Time = time(); $Max = 200; // Create cache of bucket_pk => bucket_name // Since we are going to do a lot of lookups $sql = "select bucket_pk, bucket_name from bucket_def where bucketpool_fk={$bucketpool_pk}"; $result_name = pg_query($PG_CONN, $sql); DBCheckResult($result_name, $sql, __FILE__, __LINE__); $bucketNameCache = array(); while ($name_row = pg_fetch_assoc($result_name)) { $bucketNameCache[$name_row['bucket_pk']] = $name_row['bucket_name']; } pg_free_result($result_name); switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Get all the files under this uploadtree_pk with this bucket */ $V .= _("The following files are in bucket: '<b>"); $V .= $bucketNameCache[$bucket_pk]; $V .= "</b>'.\n"; $text = _("Display"); $text1 = _("excludes"); $text2 = _("files with these licenses"); if (!empty($Excl)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}"; } $Offset = $Page <= 0 ? 0 : $Page * $Max; $PkgsOnly = false; // Get bounds of subtree (lft, rgt) for this uploadtree_pk $sql = "SELECT lft,rgt,upload_fk FROM uploadtree\n WHERE uploadtree_pk = {$uploadtree_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; pg_free_result($result); /* Get uploadtree table */ $uploadtree_tablename = GetUploadtreeTableName($upload_pk); /* If $BinNoSrc, then only list binary packages in this subtree * that do not have Source packages. * Else list files in the asked for bucket. */ if ($BinNoSrc) { } else { $Offset = $Page < 0 ? 0 : $Page * $Max; $limit = $Page < 0 ? "ALL" : $Max; // Get all the uploadtree_pk's with this bucket (for this agent and bucketpool) // in this subtree. // It would be best to sort by pfile_pk, so that the duplicate pfiles are // correctly indented, but pfile_pk has no meaning to the user. So a compromise, // sorting by ufile_name is used. $sql = "select uploadtree.*, bucket_file.nomosagent_fk as nomosagent_fk\n from uploadtree, bucket_file, bucket_def\n where upload_fk={$upload_pk} and uploadtree.lft between {$lft} and {$rgt}\n and ((ufile_mode & (1<<28)) = 0)\n and ((ufile_mode & (1<<29))=0)\n and uploadtree.pfile_fk=bucket_file.pfile_fk\n and agent_fk={$bucketagent_pk}\n and bucket_fk={$bucket_pk}\n and bucketpool_fk={$bucketpool_pk}\n and bucket_pk=bucket_fk \n order by uploadtree.ufile_name\n limit {$limit} offset {$Offset}"; $fileresult = pg_query($PG_CONN, $sql); DBCheckResult($fileresult, $sql, __FILE__, __LINE__); $Count = pg_num_rows($fileresult); } $file_result_temp = pg_fetch_all($fileresult); $sourted_file_result = array(); // the final file list will display $max_num = $Count; /** sorting by ufile_name from DB, then reorder the duplicates indented */ for ($i = 0; $i < $max_num; $i++) { $row = $file_result_temp[$i]; if (empty($row)) { continue; } array_push($sourted_file_result, $row); for ($j = $i + 1; $j < $max_num; $j++) { $row_next = $file_result_temp[$j]; if (!empty($row_next) && $row['pfile_fk'] == $row_next['pfile_fk']) { array_push($sourted_file_result, $row_next); $file_result_temp[$j] = null; } } } if ($Count < 1.25 * $Max) { $Max = $Count; } if ($Max < 1) { $Max = 1; } // prevent div by zero in corner case of no files /* Get the page menu */ if ($Count >= $Max && $Page >= 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } // base url $baseURL = "?mod=" . $this->Name . "&bapk={$bucketagent_pk}&item={$uploadtree_pk}&bpk={$bucket_pk}&bp={$bucketpool_pk}&napk={$nomosagent_pk}&page=-1"; // for each uploadtree rec ($fileresult), find all the licenses in it and it's children $ShowBox = 1; $ShowMicro = NULL; $RowNum = $Offset; $Header = ""; $LinkLast = "list_bucket_files&bapk={$bucketagent_pk}"; /* file display loop/table */ $V .= "<table>"; $text = _("File"); $V .= "<tr><th>{$text}</th><th> "; $ExclArray = explode(":", $Excl); $ItemNumb = 0; $PrevPfile_pk = 0; if ($Count > 0) { foreach ($sourted_file_result as $row) { // get all the licenses in this subtree (bucket uploadtree_pk) $pfile_pk = $row['pfile_fk']; $licstring = GetFileLicenses_string($nomosagent_pk, $row['pfile_fk'], $row['uploadtree_pk'], $uploadtree_tablename); if (empty($licstring)) { $licstring = '-'; } $URLlicstring = urlencode($licstring); /* Allow user to exclude files with this exact license list */ if (!empty($Excl)) { $URL = $baseURL . "&excl=" . urlencode($Excl) . ":" . $URLlicstring; } else { $URL = $baseURL . "&excl={$URLlicstring}"; } $text = _("Exclude files with license"); $Header = "<a href={$URL}>{$text}: {$licstring}.</a>"; $ok = true; if ($Excl) { if (in_array($licstring, $ExclArray)) { $ok = false; } } if ($ok) { $nomosagent_pk = $row['nomosagent_fk']; $LinkLast = "view-license&bapk={$bucketagent_pk}&napk={$nomosagent_pk}"; $V .= "<tr><td>"; if ($PrevPfile_pk == $pfile_pk) { $V .= "<div style='margin-left:2em;'>"; } else { $V .= "<div>"; } $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); $V .= "</div>"; $V .= "</td>"; $V .= "<td> </td>"; // spaces to seperate licenses // show the entire license list as a single string with links to the files // in this container with that license. $V .= "<td>{$licstring}</td></tr>"; $V .= "<tr><td colspan=3><hr></td></tr>"; // separate files } $PrevPfile_pk = $pfile_pk; } } pg_free_result($fileresult); $V .= "</table>"; if (!empty($VM)) { $V .= $VM . "\n"; } $V .= "<hr>\n"; $Time = time() - $Time; $text = _("Elapsed time"); $text1 = _("seconds"); $V .= "<small>{$text}: {$Time} {$text1}</small>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }
/** * \brief This function returns the scheduler status. */ function Output() { $uTime = microtime(true); if ($this->State != PLUGIN_STATE_READY) { return 0; } $OutBuf = ""; $Folder = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); $filter = GetParm("filter", PARM_STRING); /* check upload permissions */ $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } /* Get uploadtree_tablename */ $uploadtree_tablename = GetUploadtreeTableName($Upload); $this->uploadtree_tablename = $uploadtree_tablename; /* Use Traceback_parm_keep to ensure that all parameters are in order */ /******** disable cache to see if this is fast enough without it ***** $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("upload","item","folder", "orderBy", "orderc", "ordercp")) . "&show=$Show"; if ($this->UpdCache != 0) { $OutBuf .= ""; $Err = ReportCachePurgeByKey($CacheKey); } else $OutBuf .= ReportCacheGet($CacheKey); ***********************************************/ if (empty($OutBuf)) { switch ($this->OutputType) { case "XML": break; case "HTML": $OutBuf .= "\n<script language='javascript'>\n"; /* function to replace this page specifying a new filter parameter */ $OutBuf .= "function ChangeFilter(selectObj, upload, item){"; $OutBuf .= " var selectidx = selectObj.selectedIndex;"; $OutBuf .= " var filter = selectObj.options[selectidx].value;"; $OutBuf .= ' window.location.assign("?mod=' . $this->Name . '&upload="+upload+"&item="+item +"&filter=" + filter); '; $OutBuf .= "}</script>\n"; $OutBuf .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ $OutBuf .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "<P />\n"; if (!empty($Upload)) { /** advanced interface allowing user to select dataset (agent version) */ $Agent_name = "copyright"; $dataset = "copyright_dataset"; $arstable = "copyright_ars"; /** get proper agent_id */ $Agent_pk = GetParm("agent", PARM_INTEGER); if (empty($Agent_pk)) { $Agent_pk = LatestAgentpk($Upload, $arstable); } if ($Agent_pk == 0) { $text = _("No data available. Use Jobs > Agents to schedule a copyright scan."); $Msg = "<b>{$text}</b><p>"; $OutBuf .= $Msg; break; } $AgentSelect = AgentSelect($Agent_name, $Upload, true, $dataset, $dataset, $Agent_pk, "onchange=\"addArsGo('newds', 'copyright_dataset');\""); /** change the copyright result when selecting one version of copyright */ if (!empty($AgentSelect)) { $action = Traceback_uri() . "?mod=copyrighthist&upload={$Upload}&item={$Item}"; $OutBuf .= "<script type='text/javascript'>\n function addArsGo(formid, selectid)\n {\n var selectobj = document.getElementById(selectid);\n var Agent_pk = selectobj.options[selectobj.selectedIndex].value;\n document.getElementById(formid).action='{$action}'+'&agent='+Agent_pk;\n document.getElementById(formid).submit();\n return;\n }\n </script>"; /* form to select new dataset, show dataset */ $OutBuf .= "<form action='{$action}' id='newds' method='POST'>\n"; $OutBuf .= $AgentSelect; $OutBuf .= "</form>"; } $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); /* Select list for filters */ $SelectFilter = "<select name='view_filter' id='view_filter' onchange='ChangeFilter(this,{$Upload}, {$Item})'>"; $text = _("Show all"); $Selected = $filter == 'none' ? "selected" : ""; $SelectFilter .= "<option {$Selected} value='none'>{$text}"; $text = _("Show files without licenses"); $Selected = $filter == 'nolics' ? "selected" : ""; $SelectFilter .= "<option {$Selected} value='nolics'>{$text}"; $SelectFilter .= "</select>"; $OutBuf .= $SelectFilter; $OutBuf .= $this->ShowUploadHist($Item, $Uri, $filter, $uploadtree_tablename, $Agent_pk); } $OutBuf .= "</font>\n"; break; case "Text": break; default: } /* Cache Report */ /******** disable cache to see if this is fast enough without it ***** $Cached = false; ReportCachePut($CacheKey, $OutBuf); **************************************************/ } else { $Cached = true; } if (!$this->OutputToStdout) { return $OutBuf; } print "{$OutBuf}"; $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); printf("<small>{$text}</small>", $Time); /******** disable cache to see if this is fast enough without it ***** $text = _("cached"); $text1 = _("Update"); if ($Cached) echo " <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>"; **************************************************/ return; }
/** * \brief The Picker page */ function Output() { global $PG_CONN; if ($this->State != PLUGIN_STATE_READY) { return 0; } /** * create table if it doesn't exist (not assuming Install() was run. * eg. source update */ $this->Create_file_picker(); $RtnMod = GetParm("rtnmod", PARM_TEXT); $uploadtree_pk = GetParm("item", PARM_INTEGER); $uploadtree_pk2 = GetParm("item2", PARM_INTEGER); $folder_pk = GetParm("folder", PARM_INTEGER); $user_pk = $_SESSION['UserId']; /* Item to start Browse window on */ $Browseuploadtree_pk = GetParm("bitem", PARM_INTEGER); /* Check item1 and item2 upload permissions */ $Item1Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}"); $UploadPerm = GetUploadPerm($Item1Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text} item 1<h2>"; return; } if (!empty($uploadtree_pk2)) { $Item2Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk2}"); $UploadPerm = GetUploadPerm($Item2Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text} item 2<h2>"; return; } } /** * After picking an item2, this logic will record the pick in * the picker history, and then redirect both item1 and item2 to the * comparison app. */ if (!empty($user_pk) && !empty($RtnMod) && !empty($uploadtree_pk) && !empty($uploadtree_pk2)) { // Record pick $sql = "insert into file_picker (user_fk, uploadtree_fk1, uploadtree_fk2, last_access_date)\n values({$user_pk}, {$uploadtree_pk}, {$uploadtree_pk2}, now())"; // ignore errors (most probably a duplicate key) @($result = pg_query($PG_CONN, $sql)); // Redirect to diff module $uri = Traceback_uri() . "?mod={$RtnMod}&item1={$uploadtree_pk}&item2={$uploadtree_pk2}"; echo "<script type='text/javascript'> window.location.assign('{$uri}');</script>"; exit; } $OutBuf = ""; switch ($this->OutputType) { case "XML": break; case "HTML": if (empty($uploadtree_pk)) { $OutBuf = "<h2>Picker URL is missing the first comparison file.</h2>"; } else { $PathArray = Dir2Path($uploadtree_pk, 'uploadtree'); $OutBuf .= $this->HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray); } break; case "Text": break; default: } if (!$this->OutputToStdout) { return $OutBuf; } print "{$OutBuf}"; return; }
/** * \brief This function returns the output html */ function Output() { global $PG_CONN; global $Plugins; if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $folder_pk = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); // upload_pk to browse $Item = GetParm("item", PARM_INTEGER); // uploadtree_pk to browse /* check permission if $Upload is given */ if (!empty($Upload)) { $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } } /* kludge for plugins not supplying a folder parameter. * Find what folder this upload is in. Error if in multiple folders. */ if (empty($folder_pk)) { if (empty($Upload)) { $folder_pk = GetUserRootFolder(); } else { /* Make sure the upload record exists */ $sql = "select upload_pk from upload where upload_pk={$Upload}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { echo "This upload no longer exists on this system."; return; } $sql = "select parent_fk from foldercontents where child_id={$Upload} and foldercontents_mode=2"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) > 1) { Fatal("Upload {$Upload} found in multiple folders.", __FILE__, __LINE__); } if (pg_num_rows($result) < 1) { Fatal("Upload {$Upload} missing from foldercontents.", __FILE__, __LINE__); } $row = pg_fetch_assoc($result); $folder_pk = $row['parent_fk']; pg_free_result($result); } } $Folder = $folder_pk; $Show = 'detail'; // always use detail switch ($this->OutputType) { case "XML": break; case "HTML": /************************/ /* Show the folder path */ /************************/ $uploadtree_tablename = ""; if (!empty($Item)) { /* Make sure the item is not a file */ $sql = "SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = '{$Item}';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); pg_free_result($result); $Upload = $row['upload_fk']; $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } if (!Iscontainer($row['ufile_mode'])) { /* Not a container! */ $View =& $Plugins[plugin_find_id("view")]; if (!empty($View)) { return $View->ShowView(NULL, "browse"); } } $V .= "<font class='text'>\n"; $uploadtree_tablename = GetUploadtreeTableName($row['upload_fk']); $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "\n"; } else { if (!empty($Upload)) { $V .= "<font class='text'>\n"; $uploadtree_tablename = GetUploadtreeTableName($Upload); $V .= Dir2BrowseUpload($this->Name, $Upload, NULL, 1, "Browse", $uploadtree_tablename) . "\n"; } else { $V .= "<font class='text'>\n"; } } /******************************/ /* Get the folder description */ /******************************/ if (!empty($Upload)) { if (empty($Item)) { $sql = "select uploadtree_pk from uploadtree\n where parent is NULL and upload_fk={$Upload} "; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result)) { $row = pg_fetch_assoc($result); $Item = $row['uploadtree_pk']; } else { $text = _("Missing upload tree parent for upload"); $V .= "<hr><h2>{$text} {$Upload}</h2><hr>"; break; } pg_free_result($result); } $V .= $this->ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename); } else { $V .= $this->ShowFolder($Folder, $Show); } $V .= "</font>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief This function returns the scheduler status. */ function Output() { $uTime = microtime(true); if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $Upload = GetParm("upload", PARM_INTEGER); $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } $Item = GetParm("item", PARM_INTEGER); $tag_pk = GetParm("tag", PARM_INTEGER); $updcache = GetParm("updcache", PARM_INTEGER); $this->uploadtree_tablename = GetUploadtreeTableName($Upload); /* Remove "updcache" from the GET args. * This way all the url's based on the input args won't be * polluted with updcache * Use Traceback_parm_keep to ensure that all parameters are in order */ $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item", "tag", "agent", "orderBy", "orderl", "orderc")); if ($updcache) { $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/", "", $_SERVER['REQUEST_URI']); unset($_GET['updcache']); $V = ReportCachePurgeByKey($CacheKey); } else { $V = ReportCacheGet($CacheKey); } if (empty($V)) { switch ($this->OutputType) { case "XML": break; case "HTML": $V .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $this->uploadtree_tablename) . "<P />\n"; if (!empty($Upload)) { $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); $V .= js_url(); $V .= $this->ShowUploadHist($Item, $Uri, $tag_pk); } $V .= "</font>\n"; $text = _("Loading..."); /*$V .= "<div id='ajax_waiting'><img src='images/ajax-loader.gif'>$text</div>"; */ break; case "Text": break; default: } $Cached = false; } else { $Cached = true; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); printf("<small>{$text}</small>", $Time); if ($Cached) { $text = _("cached"); $text1 = _("Update"); echo " <i>{$text}</i> <a href=\"{$_SERVER['REQUEST_URI']}&updcache=1\"> {$text1} </a>"; } else { /* Cache Report if this took longer than 1/2 second*/ if ($Time > 0.5) { ReportCachePut($CacheKey, $V); } } return; }
/** * \brief display the license changing page */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } $ObjectiveLicense = GetParm("object_license", PARM_TEXT); $ObjectiveLicense = trim($ObjectiveLicense); $Reason = GetParm("change_reason", PARM_TEXT); $Reason = trim($Reason); $Agent_pk = GetParm("napk", PARM_STRING); $upload_fk = GetParm("upload", PARM_STRING); $uploadtree_pk = GetParm("item", PARM_STRING); $fl_pk = GetParm("fl_pk", PARM_STRING); $OriginalLicense = ""; $FileName = ""; $V = ""; /* Get uploadtree table name */ $uploadtree_tablename = GetUploadtreeTablename($upload_fk); $V .= Dir2Browse('browse', $uploadtree_pk, NULL, 1, "View", -1, '', '', $uploadtree_tablename) . "<P />\n"; /** if failed to change the license, set $ObjectiveLicense as empty */ if ($this->Change($OriginalLicense, $ObjectiveLicense, $Reason, $FileName) === -1) { $ObjectiveLicense = ""; } /** check if the current user has the permission to change license */ $permission = GetUploadPerm($upload_fk); $text = _("Change License"); $V .= "<H2>{$text}</H2>\n"; if ($permission >= PERM_WRITE) { $V .= "<form enctype='multipart/form-data' method='post'>\n"; $V .= "<table border='1'>\n"; $text = _("License"); $text1 = _("Change To"); $text2 = _("Reason"); $V .= "<tr><th width='20%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n"; $V .= "<tr>\n"; /** after the original license is changed, on the UI, the origial license is changed to the object one */ if (!empty($ObjectiveLicense)) { $OriginalLicense = $ObjectiveLicense; } $V .= "<td>{$OriginalLicense}</td>\n"; // $V .= "<td> <input type='text' style='width:100%' name='object_license'></td>\n"; $V .= "<td> <select name='object_license'>\n"; $V .= $this->LicenseList(); $V .= "</select></td>"; $V .= "<td> <input type='text' style='width:100%' name='change_reason'></td>\n"; $V .= "</tr>\n"; $V .= "</table><br>\n"; $V .= "<input type='submit' value='Submit'>"; $V .= "</form>\n"; } else { $text = _("Sorry, you are an administrator, also have no write and above permission on this upload, have can not change the license of this file."); $V .= "<b>{$text}</b>"; } $V .= "<br>"; if ($this->IsChanged($fl_pk)) { // if this license has been changed, display the change trail $V .= $this->ViewLicenseAuditTrail($fl_pk, $upload_fk, $uploadtree_pk); } print $V; }
function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $Page = ""; $UploadPk = GetParm('upload', PARM_INTEGER); if (empty($UploadPk)) { $UploadPk = -1; } else { $UploadPerm = GetUploadPerm($UploadPk); if ($UploadPerm < PERM_WRITE) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } } switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Process any actions */ if (@$_SESSION['UserLevel'] >= PLUGIN_DB_WRITE) { $jq_pk = GetParm("jobid", PARM_INTEGER); $Action = GetParm("action", PARM_STRING); $UploadPk = GetParm("upload", PARM_INTEGER); if (!empty($UploadPk)) { $UploadPerm = GetUploadPerm($UploadPk); if ($UploadPerm < PERM_WRITE) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } } $Page = GetParm('page', PARM_INTEGER); if (empty($Page)) { $Page = 0; } $jqtype = GetParm("jqtype", PARM_STRING); $ThisURL = Traceback_uri() . "?mod=" . $this->Name . "&upload={$UploadPk}"; $Job = GetParm('job', PARM_INTEGER); switch ($Action) { case 'pause': if (empty($jq_pk)) { break; } $Command = "pause {$jq_pk}"; $rv = fo_communicate_with_scheduler($Command, $response_from_scheduler, $error_info); if ($rv == false) { $V .= _("Unable to pause job.") . " " . $response_from_scheduler . $error_info; } echo "<script type=\"text/javascript\"> window.location.replace(\"{$ThisURL}\"); </script>"; break; case 'restart': if (empty($jq_pk)) { break; } $Command = "restart {$jq_pk}"; $rv = fo_communicate_with_scheduler($Command, $response_from_scheduler, $error_info); if ($rv == false) { $V .= _("Unable to restart job.") . " " . $response_from_scheduler . $error_info; } echo "<script type=\"text/javascript\"> window.location.replace(\"{$ThisURL}\"); </script>"; break; case 'cancel': if (empty($jq_pk)) { break; } $Msg = "\"" . _("Killed by") . " " . @$_SESSION['User'] . "\""; $Command = "kill {$jq_pk} {$Msg}"; $rv = fo_communicate_with_scheduler($Command, $response_from_scheduler, $error_info); if ($rv == false) { $V .= _("Unable to cancel job.") . $response_from_scheduler . $error_info; } echo "<script type=\"text/javascript\"> window.location.replace(\"{$ThisURL}\"); </script>"; break; default: break; } } if (!empty($Job)) { $V .= $this->ShowJobDB($Job); } else { if ($UploadPk) { $upload_pks = array($UploadPk); $Jobs = $this->Uploads2Jobs($upload_pks, $Page); } else { $Jobs = $this->MyJobs($this->nhours); } $JobsInfo = $this->GetJobInfo($Jobs, $Page); /* Sort jobs by job_pk (so most recent comes out first) */ usort($JobsInfo, "CompareJobsInfo"); $V .= $this->Show($JobsInfo, $Page); } break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief Given a filename, return all uploadtree. * \param $Item uploadtree_pk of tree to search, if empty, do global search * \param $Filename filename or pattern to search for, false if unused * \param $tag tag (or tag pattern mytag%) to search for, false if unused * \param $Page display page number * \param $SizeMin Minimum file size, -1 if unused * \param $SizeMax Maximum file size, -1 if unused * \param $searchtype "containers" or "allfiles" * \return array of uploadtree recs. Each record contains uploadtree_pk, parent, * upload_fk, pfile_fk, ufile_mode, and ufile_name */ function GetResults($Item, $Filename, $tag, $Page, $SizeMin, $SizeMax, $searchtype, $License, $Copyright) { global $PG_CONN; $UploadtreeRecs = array(); // uploadtree record array to return $NeedTagfileTable = true; $NeedTaguploadtreeTable = true; if ($Item) { /* Find lft and rgt bounds for this $Uploadtree_pk */ $sql = "SELECT lft,rgt,upload_fk, pfile_fk FROM uploadtree WHERE uploadtree_pk = {$Item};"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); $text = _("Invalid URL, nonexistant item"); return "<h2>{$text} {$Uploadtree_pk}</h2>"; } $row = pg_fetch_assoc($result); $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; /* Check upload permission */ $UploadPerm = GetUploadPerm($upload_pk); if ($UploadPerm < PERM_READ) { return $UploadtreeRecs; } pg_free_result($result); } /* Start the result select stmt */ $SQL = "SELECT DISTINCT uploadtree_pk, parent, upload_fk, uploadtree.pfile_fk, ufile_mode, ufile_name FROM uploadtree"; if (!empty($License)) { $SQL .= ",license_file_ref"; } if (!empty($Copyright)) { $SQL .= ",copyright"; } /* Figure out the tag_pk's of interest */ if (!empty($tag)) { $sql = "select tag_pk from tag where tag ilike '{$tag}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { /* tag doesn't match anything, so no results are possible */ pg_free_result($result); return $UploadtreeRecs; } /* Make a list of the tag_pk's that satisfy the criteria */ $tag_pk_array = pg_fetch_all($result); pg_free_result($result); /* add the tables needed for the tag query */ $sql = "select tag_file_pk from tag_file limit 1"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { /* tag_file didn't have data, don't add the tag_file table for tag query */ $NeedTagfileTable = false; } else { $SQL .= ", tag_file"; } pg_free_result($result); /* add the tables needed for the tag query */ $sql = "select tag_uploadtree_pk from tag_uploadtree limit 1"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { /* tag_uploadtree didn't have data, don't add the tag_uploadtree table for tag query */ $NeedTaguploadtreeTable = false; } else { $SQL .= ", tag_uploadtree"; } pg_free_result($result); if (!$NeedTagfileTable && !$NeedTaguploadtreeTable) { $SQL .= ", tag_file, tag_uploadtree"; } } /* do we need the pfile table? Yes, if any of these are a search critieria. */ if (!empty($SizeMin) or !empty($SizeMax)) { $SQL .= ", pfile where pfile_pk=uploadtree.pfile_fk "; $NeedAnd = true; } else { $SQL .= " where "; $NeedAnd = false; } /* add the tag conditions */ if (!empty($tag)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= "("; $NeedOr = false; foreach ($tag_pk_array as $tagRec) { if ($NeedOr) { $SQL .= " OR"; } $SQL .= "("; $tag_pk = $tagRec['tag_pk']; if ($NeedTagfileTable && $NeedTaguploadtreeTable) { $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}) "; } else { if ($NeedTaguploadtreeTable) { $SQL .= "uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}"; } else { if ($NeedTagfileTable) { $SQL .= "uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}"; } else { $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}) "; } } } $SQL .= ")"; $NeedOr = 1; } $NeedAnd = 1; $SQL .= ")"; } if ($Filename) { $Filename = str_replace("'", "''", $Filename); // protect DB if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " ufile_name ilike '{$Filename}'"; $NeedAnd = 1; } if (!empty($SizeMin)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " pfile.pfile_size >= {$SizeMin}"; $NeedAnd = 1; } if (!empty($SizeMax)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " pfile.pfile_size <= {$SizeMax}"; $NeedAnd = 1; } if ($Item) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " upload_fk = {$upload_pk} AND lft >= {$lft} AND rgt <= {$rgt}"; $NeedAnd = 1; } /* search only containers */ $dir_ufile_mode = 536888320; if ($searchtype == 'containers') { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)"; $NeedAnd = 1; } if ($searchtype == 'directory') { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) AND (ufile_mode != {$dir_ufile_mode})"; $NeedAnd = 1; } /** license and copyright */ if (!empty($License)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " uploadtree.pfile_fk=license_file_ref.pfile_fk and license_file_ref.rf_shortname ilike '{$License}'"; $NeedAnd = 1; } if (!empty($Copyright)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " uploadtree.pfile_fk=copyright.pfile_fk and copyright.content ilike '%{$Copyright}%'"; } $Offset = $Page * $this->MaxPerPage; $SQL .= " ORDER BY ufile_name, uploadtree.pfile_fk"; $SQL .= " LIMIT {$this->MaxPerPage} OFFSET {$Offset};"; $result = pg_query($PG_CONN, $SQL); DBCheckResult($result, $SQL, __FILE__, __LINE__); if (pg_num_rows($result)) { while ($row = pg_fetch_assoc($result)) { $UploadPerm = GetUploadPerm($row['upload_fk']); if ($UploadPerm < PERM_READ) { continue; } $UploadtreeRecs[] = $row; } } pg_free_result($result); return $UploadtreeRecs; }