/** * \brief Generate output. */ function Output() { global $PG_CONN; global $Plugins; // make sure there is a db connection since I've pierced the core-db abstraction if (!$PG_CONN) { DBconnect(); if (!$PG_CONN) { echo "NO DB connection"; } } if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; // tmp $this->popmd5(); switch ($this->OutputType) { case "XML": break; case "Text": break; case "HTML": // micro menus $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); //debugprint($_REQUEST, "_REQUEST"); $errorstr = "License not added"; // update the db if (@$_POST["updateit"]) { $resultstr = $this->Updatedb($_POST); $V .= $resultstr; if (strstr($resultstr, $errorstr)) { $V .= $this->Updatefm(0); } else { $V .= $this->Inputfm(); } break; } if (@$_REQUEST['add'] == 'y') { $V .= $this->Updatefm(0); break; } // Add new rec to db if (@$_POST["addit"]) { $resultstr = $this->Adddb($_POST); $V .= $resultstr; if (strstr($resultstr, $errorstr)) { $V .= $this->Updatefm(0); } else { $V .= $this->Inputfm(); } break; } // bring up the update form $rf_pk = @$_REQUEST['rf_pk']; if ($rf_pk) { $V .= $this->Updatefm($rf_pk); break; } $V .= $this->Inputfm(); if (@$_POST["req_shortname"]) { $V .= $this->LicenseList($_POST["req_shortname"], $_POST["req_marydone"]); } break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }
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 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 Get an html linked string of a file browse path. * * \param $Mod - Module name (e.g. "browse") * \param $UploadtreePk * \param $LinkLast - create link (a href) for last item and use LinkLast as the module name * \param $ShowBox - true to draw a box around the string * \param $ShowMicro - true to show micro menu * \param $Enumerate - if >= zero number the folder/file path (the stuff in the yellow bar) * starting with the value $Enumerate * \param $PreText - optional additional text to preceed the folder path * \param $PostText - optional text to follow the folder path * \param $uploadtree_tablename * * \return string of browse paths */ function Dir2Browse($Mod, $UploadtreePk, $LinkLast = NULL, $ShowBox = 1, $ShowMicro = NULL, $Enumerate = -1, $PreText = '', $PostText = '', $uploadtree_tablename = "uploadtree") { $V = ""; if ($ShowBox) { $V .= "<div style='border: thin dotted gray; background-color:lightyellow'>\n"; } if ($Enumerate >= 0) { $V .= "<table border=0 width='100%'><tr><td width='5%'>"; $V .= "<font size='+2'>" . number_format($Enumerate, 0, "", ",") . ":</font>"; $V .= "</td><td>"; } $Opt = Traceback_parm_keep(array("folder", "show")); $Uri = Traceback_uri() . "?mod={$Mod}"; /* Get array of upload recs for this path, in top down order. This does not contain artifacts. */ $Path = Dir2Path($UploadtreePk, $uploadtree_tablename); $Last =& $Path[count($Path) - 1]; $V .= "<font class='text'>\n"; /* Add in additional text */ if (!empty($PreText)) { $V .= "{$PreText}<br>\n"; } /* Get the FOLDER list for the upload */ $text = _("Folder"); $V .= "<b>{$text}</b>: "; if (array_key_exists(0, $Path)) { $List = FolderGetFromUpload($Path[0]['upload_fk']); $Uri2 = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array("show")); for ($i = 0; $i < count($List); $i++) { $Folder = $List[$i]['folder_pk']; $FolderName = htmlentities($List[$i]['folder_name']); $V .= "<b><a href='{$Uri2}&folder={$Folder}'>{$FolderName}</a></b>/ "; } } $FirstPath = 1; /* every firstpath belongs on a new line */ /* Print the upload, itself (on the next line since it is not a folder) */ if (count($Path) == -1) { $Upload = $Path[0]['upload_fk']; $UploadName = htmlentities($Path[0]['ufile_name']); $UploadtreePk = $Path[0]['uploadtree_pk']; $V .= "<br><b><a href='{$Uri2}&folder={$Folder}&upload={$Upload}&item={$UploadtreePk}'>{$UploadName}</a></b>"; // $FirstPath=0; } else { $V .= "<br>"; } /* Show the path within the upload */ if ($FirstPath != 0) { for ($p = 0; !empty($Path[$p]['uploadtree_pk']); $p++) { $P =& $Path[$p]; if (empty($P['ufile_name'])) { continue; } $UploadtreePk = $P['uploadtree_pk']; if (!$FirstPath) { $V .= "/ "; } if (!empty($LinkLast) || $P != $Last) { if ($P == $Last) { $Uri = Traceback_uri() . "?mod={$LinkLast}"; } $V .= "<a href='{$Uri}&upload=" . $P['upload_fk'] . $Opt . "&item=" . $UploadtreePk . "'>"; } if (Isdir($P['ufile_mode'])) { $V .= $P['ufile_name']; } else { if (!$FirstPath && Iscontainer($P['ufile_mode'])) { $V .= "<br>\n "; } $V .= "<b>" . $P['ufile_name'] . "</b>"; } if (!empty($LinkLast) || $P != $Last) { $V .= "</a>"; } $FirstPath = 0; } } $V .= "</font>\n"; if (!empty($ShowMicro)) { $MenuDepth = 0; /* unused: depth of micro menu */ $V .= menu_to_1html(menu_find($ShowMicro, $MenuDepth), 1); } if ($Enumerate >= 0) { if ($PostText) { $V .= " {$PostText}"; } $V .= "</td></tr></table>"; } if ($ShowBox) { $V .= "</div>\n"; } return $V; }
/** * \brief Display the loaded menu and plugins. */ function Output() { $uploadtree_pk = GetParm("item", PARM_INTEGER); $rf_shortname = GetParm("lic", PARM_RAW); $tag_pk = GetParm("tag", PARM_INTEGER); $Excl = GetParm("excl", PARM_RAW); $Exclic = GetParm("exclic", PARM_RAW); if (empty($uploadtree_pk) || empty($rf_shortname)) { $text = _("is missing required parameters."); return $this->Name . " {$text}"; } $Max = 50; $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } // Get upload_pk and $uploadtree_tablename $UploadtreeRec = GetSingleRec("uploadtree", "where uploadtree_pk={$uploadtree_pk}"); global $container; /** @var UploadDao */ $uploadDao = $container->get('dao.upload'); $uploadtree_tablename = $uploadDao->getUploadtreeTableName($UploadtreeRec['upload_fk']); // micro menus $V = menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Load licenses */ $Offset = $Page < 0 ? 0 : $Page * $Max; $order = ""; $PkgsOnly = false; // Count is uploadtree recs, not pfiles $agentId = GetParm('agentId', PARM_INTEGER); if (empty($agentId)) { $agentId = "any"; } $CountArray = $this->countFilesWithLicense($agentId, $rf_shortname, $uploadtree_pk, $tag_pk, $uploadtree_tablename); if (empty($CountArray)) { $V .= _("<b> No files found for license {$rf_shortname} !</b>\n"); } else { $Count = $CountArray['count']; $Unique = $CountArray['unique']; $text = _("files found"); $text2 = _("with license"); $V .= "{$Unique} {$text} {$text2} <b>{$rf_shortname}</b>"; if ($Count < $Max) { $Max = $Count; } $limit = $Page < 0 ? "ALL" : $Max; $order = " order by ufile_name asc"; /** should delete $filesresult yourself */ $filesresult = GetFilesWithLicense($agentId, $rf_shortname, $uploadtree_pk, $PkgsOnly, $Offset, $limit, $order, $tag_pk, $uploadtree_tablename); $NumFiles = pg_num_rows($filesresult); $file_result_temp = pg_fetch_all($filesresult); $sorted_file_result = array(); // the final file list will display $max_num = $NumFiles; /** 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($sorted_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($sorted_file_result, $row_next); $file_result_temp[$j] = null; } } } $text = _("Display"); $text1 = _("excludes"); $text2 = _("files with these extensions"); if (!empty($Excl)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}"; } $text2 = _("files with these licenses"); if (!empty($Exclic)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Exclic}"; } /* Get the page menu */ if ($Max > 0 && $Count >= $Max && $Page >= 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $RowNum = $Offset; $LinkLast = "view-license"; $ShowBox = 1; $ShowMicro = NULL; // base url $ushortname = rawurlencode($rf_shortname); $baseURL = "?mod=" . $this->Name . "&item={$uploadtree_pk}&lic={$ushortname}&page=-1"; $V .= "<table>"; $text = _("File"); $V .= "<tr><th>{$text}</th><th> "; $LastPfilePk = -1; $ExclArray = explode(":", $Excl); $ExclicArray = explode(":", $Exclic); foreach ($sorted_file_result as $row) { $pfile_pk = $row['pfile_fk']; $licstring = GetFileLicenses_string($row['agent_pk'], $pfile_pk, $row['uploadtree_pk'], $uploadtree_tablename); $URLlicstring = urlencode($licstring); // Allow user to exclude files with this extension $FileExt = GetFileExt($row['ufile_name']); $URL = $baseURL; if (!empty($Excl)) { $URL .= "&excl={$Excl}:{$FileExt}"; } else { $URL .= "&excl={$FileExt}"; } if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic); } $text = _("Exclude this file type."); $Header = "<a href={$URL}>{$text}</a>"; /* Allow user to exclude files with this exact license list */ $URL = $baseURL; if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic) . ":" . $URLlicstring; } else { $URL .= "&exclic={$URLlicstring}"; } if (!empty($Excl)) { $URL .= "&excl={$Excl}"; } $text = _("Exclude files with license"); $Header .= "<br><a href={$URL}>{$text}: {$licstring}.</a>"; $excludeByType = $Excl && in_array($FileExt, $ExclArray); $excludeByLicense = $Exclic && in_array($licstring, $ExclicArray); if (!empty($licstring) && !$excludeByType && !$excludeByLicense) { $V .= "<tr><td>"; /* Tack on pfile to url - information only */ $LinkLastpfile = $LinkLast . "&pfile={$pfile_pk}"; if ($LastPfilePk == $pfile_pk) { $indent = "<div style='margin-left:2em;'>"; $outdent = "</div>"; } else { $indent = ""; $outdent = ""; } $V .= $indent; $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLastpfile, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); $V .= $outdent; $V .= "</td>"; $V .= "<td> </td>"; $V .= "<td>{$row['agent_name']}: {$licstring}</td></tr>"; $V .= "<tr><td colspan=3><hr></td></tr>"; } $LastPfilePk = $pfile_pk; } pg_free_result($filesresult); $V .= "</table>"; if (!empty($VM)) { $V .= $VM . "\n"; } } return $V; }
/** * \brief test for menu_functions() */ function test_menu_functions() { print "test function menu_insert()\n"; global $MenuList; $Path = "TestMenu::Test1::Test2"; $LastOrder = 0; $URI = "TestURI"; $Title = "TestTitle"; $Target = "TestTarget"; $HTML = "TestHTML"; $countMenuListBefore = count($MenuList); $result = menu_insert($Path, $LastOrder, $URI, $Title, $Target, $HTML); $this->assertEquals($Path, $MenuList[$countMenuListBefore]->FullName); print "test function menu_find)\n"; $depth = 2; $result = menu_find("Test1", $depth); print "test function menu_to_1html)\n"; $result = menu_to_1html($MenuList); $this->assertRegExp("/TestMenu/", $result); print "test function menu_to_1list)\n"; $Parm = ""; $result = menu_to_1list($MenuList, $Parm, "", ""); $this->assertRegExp("/TestMenu/", $result); print "Ending unit test for common-menu.php\n"; }
/** * \brief Display the loaded menu and plugins. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; $V = ""; $Time = time(); $Max = 50; /* Input parameters */ $nomosagent_pk = GetParm("napk", PARM_INTEGER); $uploadtree_pk = GetParm("item", PARM_INTEGER); $rf_shortname = GetParm("lic", PARM_RAW); $tag_pk = GetParm("tag", PARM_INTEGER); $Excl = GetParm("excl", PARM_RAW); $Exclic = GetParm("exclic", PARM_RAW); $rf_shortname = rawurldecode($rf_shortname); if (empty($uploadtree_pk) || empty($rf_shortname)) { $text = _("is missing required parameters."); echo $this->Name . " {$text}"; return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } // Get upload_pk and $uploadtree_tablename $UploadtreeRec = GetSingleRec("uploadtree", "where uploadtree_pk={$uploadtree_pk}"); $UploadRec = GetSingleRec("upload", "where upload_pk={$UploadtreeRec['upload_fk']}"); $uploadtree_tablename = $UploadRec['uploadtree_tablename']; switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Load licenses */ $Offset = $Page < 0 ? 0 : $Page * $Max; $order = ""; $PkgsOnly = false; $CheckOnly = false; // Count is uploadtree recs, not pfiles $CountArray = CountFilesWithLicense($nomosagent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly, $CheckOnly, $tag_pk, $uploadtree_tablename); $Count = $CountArray['count']; $Unique = $CountArray['unique']; $text = _("files found"); $text1 = _("unique"); $text2 = _("with license"); $V .= "{$Count} {$text} ({$Unique} {$text1}) {$text2} <b>{$rf_shortname}</b>"; if ($Count < $Max) { $Max = $Count; } $limit = $Page < 0 ? "ALL" : $Max; $order = " order by ufile_name asc"; /** should delete $filesresult yourself */ $filesresult = GetFilesWithLicense($nomosagent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly, $Offset, $limit, $order, $tag_pk, $uploadtree_tablename); $NumFiles = pg_num_rows($filesresult); $file_result_temp = pg_fetch_all($filesresult); $sorted_file_result = array(); // the final file list will display $max_num = $NumFiles; /** 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($sorted_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($sorted_file_result, $row_next); $file_result_temp[$j] = null; } } } $text = _("Display"); $text1 = _("excludes"); $text2 = _("files with these extensions"); if (!empty($Excl)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}"; } $text2 = _("files with these licenses"); if (!empty($Exclic)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Exclic}"; } /* Get the page menu */ if ($Max > 0 && $Count >= $Max && $Page >= 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $RowNum = $Offset; $LinkLast = "view-license&napk={$nomosagent_pk}"; $ShowBox = 1; $ShowMicro = NULL; // base url $ushortname = rawurlencode($rf_shortname); $baseURL = "?mod=" . $this->Name . "&napk={$nomosagent_pk}&item={$uploadtree_pk}&lic={$ushortname}&page=-1"; $V .= "<table>"; $text = _("File"); $V .= "<tr><th>{$text}</th><th> "; $LastPfilePk = -1; $ExclArray = explode(":", $Excl); $ExclicArray = explode(":", $Exclic); foreach ($sorted_file_result as $row) { $pfile_pk = $row['pfile_fk']; $licstring = GetFileLicenses_string($nomosagent_pk, $pfile_pk, $row['uploadtree_pk'], $uploadtree_tablename); $URLlicstring = urlencode($licstring); // Allow user to exclude files with this extension $FileExt = GetFileExt($row['ufile_name']); $URL = $baseURL; if (!empty($Excl)) { $URL .= "&excl={$Excl}:{$FileExt}"; } else { $URL .= "&excl={$FileExt}"; } if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic); } $text = _("Exclude this file type."); $Header = "<a href={$URL}>{$text}</a>"; /* Allow user to exclude files with this exact license list */ $URL = $baseURL; if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic) . ":" . $URLlicstring; } else { $URL .= "&exclic={$URLlicstring}"; } if (!empty($Excl)) { $URL .= "&excl={$Excl}"; } $text = _("Exclude files with license"); $Header .= "<br><a href={$URL}>{$text}: {$licstring}.</a>"; $ok = true; /* exclude by type */ if ($Excl) { if (in_array($FileExt, $ExclArray)) { $ok = false; } } /* exclude by license */ if ($Exclic) { if (in_array($licstring, $ExclicArray)) { $ok = false; } } if (empty($licstring)) { $ok = false; } if ($ok) { $V .= "<tr><td>"; /* Tack on pfile to url - information only */ $LinkLastpfile = $LinkLast . "&pfile={$pfile_pk}"; if ($LastPfilePk == $pfile_pk) { $indent = "<div style='margin-left:2em;'>"; $outdent = "</div>"; } else { $indent = ""; $outdent = ""; } $V .= $indent; $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLastpfile, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); $V .= $outdent; $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 } $LastPfilePk = $pfile_pk; } pg_free_result($filesresult); $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; }
public function Output() { $page = ""; $uploadPk = GetParm('upload', PARM_INTEGER); if (empty($uploadPk)) { $uploadPk = -1; } elseif ($uploadPk > 0) { if (!$this->uploadDao->isEditable($uploadPk, Auth::getGroupId())) { $this->vars['message'] = _("Permission Denied"); return; } } $this->vars['uploadId'] = $uploadPk; /* Process any actions */ $action = GetParm("action", PARM_STRING); $page = GetParm('page', PARM_INTEGER) ?: 0; if ($_SESSION[Auth::USER_LEVEL] >= PLUGIN_DB_WRITE && !empty($action)) { $jq_pk = GetParm("jobid", PARM_INTEGER); $uploadPk = GetParm("upload", PARM_INTEGER); if (!($uploadPk === -1 && ($_SESSION[Auth::USER_LEVEL] >= PLUGIN_DB_ADMIN || $this->jobDao->hasActionPermissionsOnJob($jq_pk, Auth::getUserId(), Auth::getGroupId()))) && !$this->uploadDao->isEditable($uploadPk, Auth::getGroupId())) { $this->vars['message'] = _("Permission Denied to perform action"); } else { $thisURL = Traceback_uri() . "?mod=" . $this->Name . "&upload={$uploadPk}"; 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) { $this->vars['errorInfo'] = _("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) { $this->vars['errorInfo'] = _("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[Auth::USER_NAME] . "\""; $command = "kill {$jq_pk} {$Msg}"; $rv = fo_communicate_with_scheduler($command, $response_from_scheduler, $error_info); if ($rv == false) { $this->vars['errorInfo'] = _("Unable to cancel job.") . $response_from_scheduler . $error_info; } echo "<script type=\"text/javascript\"> window.location.replace(\"{$thisURL}\"); </script>"; break; } } } $job = GetParm('job', PARM_INTEGER); if (!empty($job)) { $this->vars['jobId'] = $job; $this->vars['uploadName'] = $this->getUploadNameForGeekyScan($job); } else { $allusersval = GetParm("allusers", PARM_INTEGER); if (!$allusersval) { $allusersval = 0; } $this->vars['allusersval'] = $allusersval; if (!$page) { $page = 0; } $this->vars['page'] = $page; $this->vars['clockTime'] = $this->getTimeToRefresh(); $this->vars['allusersdiv'] = menu_to_1html(menu_find($this->Name, $MenuDepth), 0); $this->vars['injectedFoot'] = GetParm("injectedFoot", PARM_TEXT); $this->vars['message'] = GetParm("injectedMessage", PARM_TEXT); } }
/** * \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; }