/** * \brief Display the loaded menu and plugins. */ function Output() { global $PG_CONN; if ($this->State != PLUGIN_STATE_READY) { return; } if (!$PG_CONN) { return "NO DB connection"; } $bucket_pk = GetParm("bucket_pk", PARM_RAW); $uploadtree_pk = GetParm("item", PARM_INTEGER); /* Get the uploadtree table name */ $uploadtree_rec = GetSingleRec("uploadtree", "where uploadtree_pk='{$uploadtree_pk}'"); $uploadtree_tablename = GetUploadtreeTableName($uploadtree_rec['upload_fk']); /* Get all the non-artifact children */ $children = GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename); /* Loop through children and create a list of those that contain $bucket_pk */ $outstr = $bucket_pk; foreach ($children as $child) { if (BucketInTree($bucket_pk, $child['uploadtree_pk'])) { $outstr .= ",{$child['uploadtree_pk']}"; } } return $outstr; }
/** * \brief This function returns the scheduler status. */ public function Output() { $uTime = microtime(true); $V = ""; $Upload = GetParm("upload", PARM_INTEGER); /** @var UploadDao $uploadDao */ $uploadDao = $GLOBALS['container']->get('dao.upload'); if (!$uploadDao->isAccessible($Upload, Auth::getGroupId())) { $text = _("Permission Denied"); return "<h2>{$text}</h2>"; } $Item = GetParm("item", PARM_INTEGER); if (!$Item) { return _('No item selected'); } $updcache = GetParm("updcache", PARM_INTEGER); $tagbucket = GetParm("tagbucket", PARM_INTEGER); $this->uploadtree_tablename = GetUploadtreeTableName($Upload); /* 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("upload", "item", "folder", "ars")); 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($tagbucket)) { $bucketagent_pk = GetParm("bapk", PARM_INTEGER); $bucket_pk = GetParm("bpk", PARM_INTEGER); $bucketpool_pk = GetParm("bp", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $this->TagBucket($Upload, $Item, $bucketagent_pk, $bucket_pk, $bucketpool_pk, $nomosagent_pk); } $Cached = !empty($V); if (!$Cached) { $V .= "<font class='text'>\n"; $Children = GetNonArtifactChildren($Item, $this->uploadtree_tablename); if (count($Children) == 0) { // no children, display View-Meta micromenu $V .= Dir2Browse($this->Name, $Item, NULL, 1, "View-Meta", -1, '', '', $this->uploadtree_tablename) . "<P />\n"; } else { // has children, display Browse micormenu $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 .= $this->ShowUploadHist($Item, $Uri); } $V .= "</font>\n"; $text = _("Loading..."); } $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); $V .= sprintf("<p><small>{$text}</small>", $Time); if ($Cached) { $text = _("cached"); $text1 = _("Update"); echo " <i>{$text}</i> <a href=\"{$_SERVER['REQUEST_URI']}&updcache=1\"> {$text1} </a>"; } else { if ($Time > 0.5) { ReportCachePut($CacheKey, $V); } } return $V; }
/** * \brief Find the non artifact children of an uploadtree pk. * If any children are artifacts, resolve them until you get * to a non-artifact. * * \param $uploadtree_pk * \param $uploadtree_tablename * * \return list of child uploadtree recs + pfile_size + pfile_mimetypefk on success. * list may be empty if there are no children. * Child list is sorted by ufile_name. */ function GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename = 'uploadtree') { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); /* Find all the children */ $sql = "select {$uploadtree_tablename}.*, pfile_size, pfile_mimetypefk from {$uploadtree_tablename}\n left outer join pfile on (pfile_pk=pfile_fk)\n where parent=\$1 ORDER BY lft"; $dbManager->prepare($stmt = __METHOD__ . "{$uploadtree_tablename}", $sql); $result = $dbManager->execute($stmt, array($uploadtree_pk)); $children = $dbManager->fetchAll($result); $dbManager->freeResult($result); if (count($children) == 0) { return $children; } /* Loop through each child and replace any artifacts with their non artifact child. Or skip them if they are not containers. */ $foundChildren = array(); foreach ($children as $key => $child) { if (Isartifact($child['ufile_mode'])) { if (Iscontainer($child['ufile_mode'])) { unset($children[$key]); $NonAChildren = GetNonArtifactChildren($child['uploadtree_pk'], $uploadtree_tablename); if ($NonAChildren) { $foundChildren = array_merge($foundChildren, $NonAChildren); } } else { unset($children[$key]); } } else { $foundChildren[$key] = $child; } } // uasort($foundChildren, '_DirCmp'); return $foundChildren; }
/** * @param $Uploadtree_pk * @param $Uri * @param $uploadtree_tablename * @param $Agent_pk * @param $upload_pk * @return array */ protected function getFileListing($Uploadtree_pk, $Uri, $uploadtree_tablename, $Agent_pk, $upload_pk) { $VF = ""; // return values for file listing /******* File Listing ************/ /* Get ALL the items under this Uploadtree_pk */ $Children = GetNonArtifactChildren($Uploadtree_pk, $uploadtree_tablename); $ChildCount = 0; $ChildLicCount = 0; $ChildDirCount = 0; /* total number of directory or containers */ foreach ($Children as $c) { if (Iscontainer($c['ufile_mode'])) { $ChildDirCount++; } } $VF .= "<table border=0>"; foreach ($Children as $child) { if (empty($child)) { continue; } $ChildCount++; global $Plugins; $ModLicView =& $Plugins[plugin_find_id($this->viewName)]; /* Determine the hyperlink for non-containers to view-license */ if (!empty($child['pfile_fk']) && !empty($ModLicView)) { $LinkUri = Traceback_uri(); $LinkUri .= "?mod=" . $this->viewName . "&agent={$Agent_pk}&upload={$upload_pk}&item={$child['uploadtree_pk']}"; } else { $LinkUri = NULL; } /* Determine link for containers */ if (Iscontainer($child['ufile_mode'])) { $uploadtree_pk = DirGetNonArtifact($child['uploadtree_pk'], $uploadtree_tablename); $LicUri = "{$Uri}&item=" . $uploadtree_pk; } else { $LicUri = NULL; } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ $LicCount = 0; $cellContent = Isdir($child['ufile_mode']) ? $child['ufile_name'] . '/' : $child['ufile_name']; if (Iscontainer($child['ufile_mode'])) { $cellContent = "<a href='{$LicUri}'><b>{$cellContent}</b></a>"; } else { if (!empty($LinkUri)) { $cellContent = "<a href='{$LinkUri}'>{$cellContent}</a>"; } } $VF .= "<tr><td id='{$child['uploadtree_pk']}' align='left'>{$cellContent}</td><td>"; if ($LicCount) { $VF .= "[" . number_format($LicCount, 0, "", ",") . " "; $VF .= "license" . ($LicCount == 1 ? "" : "s"); $VF .= "</a>"; $VF .= "]"; $ChildLicCount += $LicCount; } $VF .= "</td></tr>\n"; } $VF .= "</table>\n"; return array($ChildCount, $VF); }
/** * @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; }
/** * \brief Given an $Uploadtree_pk, display: * - The histogram for the directory BY LICENSE. * - The file listing for the directory. */ function ShowUploadHist($Uploadtree_pk, $Uri, $tag_pk) { global $PG_CONN; $VF = ""; // return values for file listing $VLic = ""; // return values for license histogram $V = ""; // total return value $UniqueTagArray = array(); global $Plugins; $ModLicView =& $Plugins[plugin_find_id("view-license")]; /******* Get license names and counts ******/ /* Find lft and rgt bounds for this $Uploadtree_pk */ $sql = "SELECT lft,rgt,upload_fk FROM {$this->uploadtree_tablename}\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); if (empty($lft)) { $text = _("Job unpack/adj2nest hasn't completed."); $VLic = "<b>{$text}</b><p>"; return $VLic; } /* Find total number of files for this $Uploadtree_pk * Exclude artifacts and directories. */ $sql = "SELECT count(*) as count FROM {$this->uploadtree_tablename}\n WHERE upload_fk = {$upload_pk} \n and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt}\n and ((ufile_mode & (1<<28))=0) \n and ((ufile_mode & (1<<29))=0) and pfile_fk!=0"; //$uTime = microtime(true); $result = pg_query($PG_CONN, $sql); //printf( "<small>count files Elapsed time: %.2f seconds</small>", microtime(true) - $uTime); // convert usecs to secs DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $FileCount = $row["count"]; pg_free_result($result); /* Get the counts for each license under this UploadtreePk*/ if (empty($tag_pk)) { $TagTable = ""; $TagClause = ""; } else { $TagTable = " right join tag_file on tag_file.pfile_fk=license_file_ref.pfile_fk "; $TagClause = " and tag_fk={$tag_pk}"; } /** advanced interface allowing user to select dataset (agent version) */ $Agent_name = 'nomos'; $dataset = "nomos_dataset"; $Agent_pk = GetParm("agent", PARM_STRING); /** if do not specify agent, get the latest agent result for this upload */ if (empty($Agent_pk)) { $Agent_pk = LatestAgentpk($upload_pk, "nomos_ars"); } if ($Agent_pk == 0) { $text = _("No data available. Use Jobs > Agents to schedule a license scan."); $VLic = "<b>{$text}</b><p>"; return $VLic; } /** get nomos select dataset */ $AgentSelect = AgentSelect($Agent_name, $upload_pk, true, $dataset, $dataset, $Agent_pk, "onchange=\"addArsGo('newds', 'nomos_dataset');\""); /** change the nomos license result when selecting one version of nomos */ if (!empty($AgentSelect)) { $action = Traceback_uri() . "?mod=nomoslicense&upload={$upload_pk}&item={$Uploadtree_pk}"; $VLic .= "<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 */ $VLic .= "<form action='{$action}' id='newds' method='POST'>\n"; $VLic .= $AgentSelect; $VLic .= "</form>"; } $orderBy = array('count', 'license_name'); $ordersql = "liccount desc"; static $ordercount = 1; static $orderlic = 1; /** sorting by count/licnese name */ if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) { $order = $_GET['orderBy']; if (isset($_GET['orderc'])) { $ordercount = $_GET['orderc']; } if (isset($_GET['orderl'])) { $orderlic = $_GET['orderl']; } if ('count' == $order && 1 == $ordercount) { $ordersql = "liccount desc"; $ordercount = 0; } else { if ('count' == $order && 0 == $ordercount) { $ordersql = "liccount "; $ordercount = 1; } else { if ('license_name' == $order && 1 == $orderlic) { $ordersql = "rf_shortname "; $orderlic = 0; } else { if ('license_name' == $order && 0 == $orderlic) { $ordersql = "rf_shortname desc"; $orderlic = 1; } } } } } // Void ARE EXCLUDED FROM LICENSE COUNT $sql = "SELECT distinct(SS.rf_shortname) as licname, count(SS.rf_shortname) as liccount, SS.rf_shortname from \n (SELECT distinct(license_file_ref.pfile_fk), rf_shortname\n from license_file_ref {$TagTable}\n right join {$this->uploadtree_tablename} on license_file_ref.pfile_fk={$this->uploadtree_tablename}.pfile_fk \n where rf_shortname <> 'Void' and upload_fk='{$upload_pk}' and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt} \n and agent_fk={$Agent_pk} {$TagClause} group by license_file_ref.pfile_fk, rf_shortname\n ) as SS\n group by rf_shortname order by {$ordersql}"; //$uTime = microtime(true); $result = pg_query($PG_CONN, $sql); //$Time = microtime(true) - $uTime; // convert usecs to secs //$text = _("histogram Elapsed time: %.2f seconds"); //printf( "<small>$text</small>", $Time); DBCheckResult($result, $sql, __FILE__, __LINE__); /* Write license histogram to $VLic */ $LicCount = 0; $UniqueLicCount = 0; $NoLicFound = 0; $VLic .= "<table border=1 width='100%' id='lichistogram'>\n"; $text = _("Count"); $VLic .= "<tr><th>"; $VLic .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "tag", "agent")) . "&orderBy=count&orderc={$ordercount}>{$text}</a>"; $VLic .= "</th>"; $text = _("Files"); $VLic .= "<th width='10%'>{$text}</th>"; $text = _("License Name"); $VLic .= "<th>"; $VLic .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "tag", "agent")) . "&orderBy=license_name&orderl={$orderlic}>{$text}</a>"; $VLic .= "</th></tr>\n"; while ($row = pg_fetch_assoc($result)) { $UniqueLicCount++; $LicCount += $row['liccount']; /* Count */ $VLic .= "<tr><td align='right'>{$row['liccount']}</td>"; /* Show */ $VLic .= "<td align='center'><a href='"; $VLic .= Traceback_uri(); $text = _("Show"); $tagClause = $tag_pk ? "&tag={$tag_pk}" : ""; $VLic .= "?mod=list_lic_files&napk={$Agent_pk}&item={$Uploadtree_pk}&lic=" . urlencode($row['rf_shortname']) . $tagClause . "'>{$text}</a></td>"; /* License name */ $VLic .= "<td align='left'>"; $rf_shortname = rawurlencode($row['rf_shortname']); $VLic .= "<a id='{$rf_shortname}' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filelic&napk={$Agent_pk}&item={$Uploadtree_pk}&lic={$rf_shortname}&ut={$this->uploadtree_tablename}\")'"; $VLic .= ">{$row['licname']} </a>"; $VLic .= "</td>"; $VLic .= "</tr>\n"; if ($row['licname'] == "No_license_found") { $NoLicFound = $row['liccount']; } } $VLic .= "</table>\n"; $VLic .= "<p>\n"; $VLic .= _("Hint: Click on the license name to "); $text = _("highlight"); $VLic .= "<span style='background-color:{$this->HighlightColor}'>{$text} </span>"; $VLic .= _("where the license is found in the file listing.<br>\n"); $VLic .= "<table border=0 id='licsummary'>"; $text = _("Unique licenses"); $VLic .= "<tr><td align=right>{$UniqueLicCount}</td><td>{$text}</td></tr>"; $NetLic = $LicCount - $NoLicFound; $text = _("Licenses found"); $VLic .= "<tr><td align=right>{$NetLic}</td><td>{$text}</td></tr>"; $text = _("Files with no licenses"); $VLic .= "<tr><td align=right>{$NoLicFound}</td><td>{$text}</td></tr>"; $text = _("Files"); $VLic .= "<tr><td align=right>{$FileCount}</td><td>{$text}</td></tr>"; $VLic .= "</table>"; pg_free_result($result); /******* File Listing ************/ /* Get ALL the items under this Uploadtree_pk */ $Children = GetNonArtifactChildren($Uploadtree_pk, $this->uploadtree_tablename); /* Filter out Children that don't have tag */ if (!empty($tag_pk)) { TagFilter($Children, $tag_pk, $this->uploadtree_tablename); } $ChildCount = 0; $ChildLicCount = 0; //$uTime = microtime(true); if (!empty($Children)) { /* For alternating row background colors */ $RowStyle1 = "style='background-color:#ecfaff'"; // pale blue $RowStyle2 = "style='background-color:#ffffe3'"; // pale yellow $ColorSpanRows = 1; // Alternate background color every $ColorSpanRows $RowNum = 0; $VF .= "<table border=0 id='dirlist'>"; foreach ($Children as $C) { if (empty($C)) { continue; } $IsDir = Isdir($C['ufile_mode']); $IsContainer = Iscontainer($C['ufile_mode']); /* Determine the hyperlink for non-containers to view-license */ if (!empty($C['pfile_fk']) && !empty($ModLicView)) { $LinkUri = Traceback_uri(); $LinkUri .= "?mod=view-license&napk={$Agent_pk}&upload={$upload_pk}&item={$C['uploadtree_pk']}"; } else { $LinkUri = NULL; } /* Determine link for containers */ if (Iscontainer($C['ufile_mode'])) { $uploadtree_pk = DirGetNonArtifact($C['uploadtree_pk'], $this->uploadtree_tablename); $LicUri = "{$Uri}&item=" . $uploadtree_pk; } else { $LicUri = NULL; } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ /* Set alternating row background color - repeats every $ColorSpanRows rows */ $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2; $VF .= "<tr {$RowStyle}>"; $VF .= "<td id='{$C['uploadtree_pk']}' align='left'>"; $HasHref = 0; $HasBold = 0; if ($IsContainer) { $VF .= "<a href='{$LicUri}'>"; $HasHref = 1; $VF .= "<b>"; $HasBold = 1; } else { if (!empty($LinkUri)) { $VF .= "<a href='{$LinkUri}'>"; $HasHref = 1; } } $VF .= $C['ufile_name']; if ($IsDir) { $VF .= "/"; } if ($HasBold) { $VF .= "</b>"; } if ($HasHref) { $VF .= "</a>"; } /* show licenses under file name */ $VF .= "<br>"; $VF .= GetFileLicenses_string($Agent_pk, $C['pfile_fk'], $C['uploadtree_pk'], $this->uploadtree_tablename); $VF .= "</td><td valign='top'>"; /* display file links */ $VF .= FileListLinks($C['upload_fk'], $C['uploadtree_pk'], $Agent_pk, $C['pfile_fk'], true, $UniqueTagArray, $this->uploadtree_tablename); $VF .= "</td>"; $VF .= "</tr>\n"; $ChildCount++; } $VF .= "</table>\n"; } //$Time = microtime(true) - $uTime; // convert usecs to secs //$text = _("Sum of children Elapsed time: %.2f seconds"); //printf( "<small>$text</small>", $Time); /*************************************** Problem: $ChildCount can be zero! This happens if you have a container that does not unpack to a directory. For example: file.gz extracts to archive.txt that contains a license. Same problem seen with .pdf and .Z files. Solution: if $ChildCount == 0, then just view the license! $ChildCount can also be zero if the directory is empty. ***************************************/ if ($ChildCount == 0) { $sql = "SELECT * FROM {$this->uploadtree_tablename} WHERE uploadtree_pk = '{$Uploadtree_pk}';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); pg_free_result($result); if (IsDir($row['ufile_mode'])) { return; } $ModLicView =& $Plugins[plugin_find_id("view-license")]; return $ModLicView->Output(); } $V .= ActiveHTTPscript("FileColor"); /* Add javascript for color highlighting This is the response script needed by ActiveHTTPscript responseText is license name',' followed by a comma seperated list of uploadtree_pk's */ $script = "\n <script type=\"text/javascript\" charset=\"utf-8\">\n var Lastutpks=''; /* save last list of uploadtree_pk's */\n var LastLic=''; /* save last License (short) name */\n var color = '{$this->HighlightColor}';\n function FileColor_Reply()\n {\n if ((FileColor.readyState==4) && (FileColor.status==200))\n {\n /* remove previous highlighting */\n var numpks = Lastutpks.length;\n if (numpks > 0) document.getElementById(LastLic).style.backgroundColor='white';\n while (numpks)\n {\n document.getElementById(Lastutpks[--numpks]).style.backgroundColor='white';\n }\n\n utpklist = FileColor.responseText.split(',');\n LastLic = utpklist.shift();\n numpks = utpklist.length;\n Lastutpks = utpklist;\n\n /* apply new highlighting */\n elt = document.getElementById(LastLic);\n if (elt != null) elt.style.backgroundColor=color;\n while (numpks)\n {\n document.getElementById(utpklist[--numpks]).style.backgroundColor=color;\n }\n }\n return;\n }\n </script>\n "; $V .= $script; /****** Filters *******/ /* Only display the filter pulldown if there are filters available * Currently, this is only tags. */ /** @todo qualify with tag namespace to avoid tag name collisions. **/ /* turn $UniqueTagArray into key value pairs ($SelectData) for select list */ $SelectData = array(); if (count($UniqueTagArray)) { foreach ($UniqueTagArray as $UTA_row) { $SelectData[$UTA_row['tag_pk']] = $UTA_row['tag_name']; } $V .= "Tag filter"; $myurl = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item")); $Options = " id='filterselect' onchange=\"js_url(this.value, '{$myurl}&tag=')\""; $V .= Array2SingleSelectTag($SelectData, "tag_ns_pk", $tag_pk, true, false, $Options); } /****** Combine VF and VLic ********/ $V .= "<table border=0 width='100%'>\n"; $V .= "<tr><td valign='top' >{$VLic}</td><td valign='top'>{$VF}</td></tr>\n"; $V .= "</table>\n"; $V .= "<hr />\n"; return $V; }
/** * \brief file browser * * \return the HTML for the File browser. */ function BrowsePick($uploadtree_pk, $inBrowseuploadtree_pk, $infolder_pk, $PathArray) { $OutBuf = ""; if (empty($inBrowseuploadtree_pk)) { $Browseuploadtree_pk = $uploadtree_pk; } else { $Browseuploadtree_pk = $inBrowseuploadtree_pk; } if (empty($infolder_pk)) { $folder_pk = GetFolderFromItem("", $Browseuploadtree_pk); } else { $folder_pk = $infolder_pk; } // Get list of folders that this $Browseuploadtree_pk is in $FolderList = Folder2Path($folder_pk); // If you aren't browsing folders, // Get list of directories that this $Browseuploadtree_pk is in if (empty($infolder_pk)) { $DirectoryList = Dir2Path($Browseuploadtree_pk, 'uploadtree'); } else { $DirectoryList = ''; } // Get HTML for folder/directory list. // This is the stuff in the yellow bar. $OutBuf .= $this->HTMLPath($uploadtree_pk, $FolderList, $DirectoryList); /* Get list of folders in this folder * That is, $DirectoryList is empty */ if (empty($infolder_pk)) { $FolderContents = array(); $Children = GetNonArtifactChildren($Browseuploadtree_pk); } else { $Children = array(); $FolderContents = $this->GetFolderContents($folder_pk); } $OutBuf .= $this->HTMLFileList($uploadtree_pk, $Children, $FolderContents); return $OutBuf; }
/** * \brief Given an $Uploadtree_pk, display: \n * (1) The histogram for the directory BY LICENSE. \n * (2) The file listing for the directory. * * \param $Uploadtree_pk * \param $Uri * \param $filter * \param $uploadtree_tablename * \param $Agent_pk - agent id */ function ShowUploadHist($Uploadtree_pk, $Uri, $filter, $uploadtree_tablename, $Agent_pk) { global $PG_CONN; $VF = ""; // return values for file listing $VLic = ""; // return values for license histogram $V = ""; // total return value $upload_pk = ""; $VCopyright = ''; global $Plugins; $ModLicView =& $Plugins[plugin_find_id("copyrightview")]; $rows = $this->GetRows($Uploadtree_pk, $Agent_pk, $upload_pk, 0, $filter); if (!is_array($rows)) { return $rows; } $orderBy = array('count', 'copyright'); static $ordercount = 1; static $ordercopyright = 1; $order = ""; /** sorting by count/copyright statement */ if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) { $order = $_GET['orderBy']; if (isset($_GET['orderc'])) { $ordercount = $_GET['orderc']; } if (isset($_GET['ordercp'])) { $ordercopyright = $_GET['ordercp']; } if ('count' == $order && 1 == $ordercount) { $ordercount = 0; } else { if ('count' == $order && 0 == $ordercount) { $ordercount = 1; } else { if ('copyright' == $order && 1 == $ordercopyright) { $ordercopyright = 0; } else { if ('copyright' == $order && 0 == $ordercopyright) { $ordercopyright = 1; } } } } } /* Write license histogram to $VLic */ $CopyrightCount = 0; $UniqueCopyrightCount = 0; $NoCopyrightFound = 0; $VCopyright = ""; $VCopyright .= "<table border=1 width='100%' id='copyright'>\n"; $text = _("Count"); $text1 = _("Files"); $text2 = _("Copyright Statements"); $text3 = _("Email"); $text4 = _("URL"); $VCopyright .= "<tr><th>"; $VCopyright .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "filter", "agent")) . "&orderBy=count&orderc={$ordercount}>{$text}</a>"; $VCopyright .= "</th>"; $VCopyright .= "<th width='10%'>{$text1}</th>"; $VCopyright .= "<th>"; $VCopyright .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "filter", "agent")) . "&orderBy=copyright&ordercp={$ordercopyright}>{$text2}</a>"; $VCopyright .= "</th>"; $VCopyright .= "</th></tr>\n"; $EmailCount = 0; $UniqueEmailCount = 0; $NoEmailFound = 0; $VEmail = "<table border=1 width='100%'id='copyrightemail'>\n"; $VEmail .= "<tr><th width='10%'>{$text}</th>"; $VEmail .= "<th width='10%'>{$text1}</th>"; $VEmail .= "<th>{$text3}</th></tr>\n"; $UrlCount = 0; $UniqueUrlCount = 0; $NoUrlFound = 0; $VUrl = "<table border=1 width='100%' id='copyrighturl'>\n"; $VUrl .= "<tr><th width='10%'>{$text}</th>"; $VUrl .= "<th width='10%'>{$text1}</th>"; $VUrl .= "<th>{$text4}</th></tr>\n"; if (!is_array($rows)) { $VCopyright .= "<tr><td colspan=3>{$rows}</td></tr>"; } else { foreach ($rows as $row) { $hash = $row['hash']; if ($row['type'] == 'statement') { $UniqueCopyrightCount++; $CopyrightCount += $row['copyright_count']; $VCopyright .= "<tr><td align='right'>{$row['copyright_count']}</td>"; $VCopyright .= "<td align='center'><a href='"; $VCopyright .= Traceback_uri(); $URLargs = "?mod=copyrightlist&agent={$Agent_pk}&item={$Uploadtree_pk}&hash=" . $hash . "&type=" . $row['type']; if (!empty($filter)) { $URLargs .= "&filter={$filter}"; } $VCopyright .= $URLargs . "'>Show</a></td>"; $VCopyright .= "<td align='left'>"; /* strip out characters we don't want to see This is a hack until the agent stops writing these chars to the db. */ $S = $row['content']; $S = htmlentities($S); $S = str_replace("Â", "", $S); // comes from utf-8 copyright symbol $VCopyright .= $S; /* Debugging $hex = bin2hex($S); $VCopyright .= "<br>$hex" ; End Debugging */ $VCopyright .= "</td>"; $VCopyright .= "</tr>\n"; } else { if ($row['type'] == 'email') { $UniqueEmailCount++; $EmailCount += $row['copyright_count']; $VEmail .= "<tr><td align='right'>{$row['copyright_count']}</td>"; $VEmail .= "<td align='center'><a href='"; $VEmail .= Traceback_uri(); $VEmail .= "?mod=copyrightlist&agent={$Agent_pk}&item={$Uploadtree_pk}&hash=" . $hash . "&type=" . $row['type'] . "'>Show</a></td>"; $VEmail .= "<td align='left'>"; $VEmail .= htmlentities($row['content']); $VEmail .= "</td>"; $VEmail .= "</tr>\n"; } else { if ($row['type'] == 'url') { $UniqueUrlCount++; $UrlCount += $row['copyright_count']; $VUrl .= "<tr><td align='right'>{$row['copyright_count']}</td>"; $VUrl .= "<td align='center'><a href='"; $VUrl .= Traceback_uri(); $VUrl .= "?mod=copyrightlist&agent={$Agent_pk}&item={$Uploadtree_pk}&hash=" . $hash . "&type=" . $row['type'] . "'>Show</a></td>"; $VUrl .= "<td align='left'>"; $VUrl .= htmlentities($row['content']); $VUrl .= "</td>"; $VUrl .= "</tr>\n"; } } } } } $VCopyright .= "</table>\n"; $VCopyright .= "<p>\n"; $text = _("Unique Copyrights"); $text1 = _("Total Copyrights"); $VCopyright .= "{$text}: {$UniqueCopyrightCount}<br>\n"; $NetCopyright = $CopyrightCount; $VCopyright .= "{$text1}: {$NetCopyright}"; $VEmail .= "</table>\n"; $VEmail .= "<p>\n"; $text = _("Unique Emails"); $text1 = _("Total Emails"); $VEmail .= "{$text}: {$UniqueEmailCount}<br>\n"; $NetEmail = $EmailCount; $VEmail .= "{$text1}: {$NetEmail}"; $VUrl .= "</table>\n"; $VUrl .= "<p>\n"; $text = _("Unique URLs"); $text1 = _("Total URLs"); $VUrl .= "{$text}: {$UniqueUrlCount}<br>\n"; $NetUrl = $UrlCount; $VUrl .= "{$text1}: {$NetUrl}"; /******* File Listing ************/ /* Get ALL the items under this Uploadtree_pk */ $Children = GetNonArtifactChildren($Uploadtree_pk, $uploadtree_tablename); $ChildCount = 0; $ChildLicCount = 0; $ChildDirCount = 0; /* total number of directory or containers */ foreach ($Children as $C) { if (Iscontainer($C['ufile_mode'])) { $ChildDirCount++; } } $VF .= "<table border=0>"; foreach ($Children as $C) { if (empty($C)) { continue; } $IsDir = Isdir($C['ufile_mode']); $IsContainer = Iscontainer($C['ufile_mode']); /* Determine the hyperlink for non-containers to view-license */ if (!empty($C['pfile_fk']) && !empty($ModLicView)) { $LinkUri = Traceback_uri(); $LinkUri .= "?mod=view-license&agent={$Agent_pk}&upload={$upload_pk}&item={$C['uploadtree_pk']}"; } else { $LinkUri = NULL; } /* Determine link for containers */ if (Iscontainer($C['ufile_mode'])) { $uploadtree_pk = DirGetNonArtifact($C['uploadtree_pk'], $uploadtree_tablename); $LicUri = "{$Uri}&item=" . $uploadtree_pk; } else { $LicUri = NULL; } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ $LicCount = 0; $VF .= "<tr><td id='{$C['uploadtree_pk']}' align='left'>"; $HasHref = 0; $HasBold = 0; if ($IsContainer) { $VF .= "<a href='{$LicUri}'>"; $HasHref = 1; $VF .= "<b>"; $HasBold = 1; } else { if (!empty($LinkUri)) { $VF .= "<a href='{$LinkUri}'>"; $HasHref = 1; } } $VF .= $C['ufile_name']; if ($IsDir) { $VF .= "/"; } if ($HasBold) { $VF .= "</b>"; } if ($HasHref) { $VF .= "</a>"; } $VF .= "</td><td>"; if ($LicCount) { $VF .= "[" . number_format($LicCount, 0, "", ",") . " "; $VF .= "license" . ($LicCount == 1 ? "" : "s"); $VF .= "</a>"; $VF .= "]"; $ChildLicCount += $LicCount; } $VF .= "</td>"; $VF .= "</tr>\n"; $ChildCount++; } $VF .= "</table>\n"; /*************************************** Problem: $ChildCount can be zero! This happens if you have a container that does not unpack to a directory. For example: file.gz extracts to archive.txt that contains a license. Same problem seen with .pdf and .Z files. Solution: if $ChildCount == 0, then just view the license! $ChildCount can also be zero if the directory is empty. ***************************************/ if ($ChildCount == 0) { $sql = "SELECT * FROM {$this->uploadtree_tablename} WHERE uploadtree_pk = '{$Uploadtree_pk}';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); pg_free_result($result); if (IsDir($row['ufile_mode'])) { return; } $ModLicView =& $Plugins[plugin_find_id("copyrightview")]; return $ModLicView->Output(); } /* Combine VF and VLic */ $text = _("Jump to"); $text1 = _("Emails"); $text2 = _("Copyright Statements"); $text3 = _("URLs"); $V .= "<table border=0 width='100%'>\n"; $V .= "<tr><td><a name=\"statements\"></a>{$text}: <a href=\"#emails\">{$text1}</a> | <a href=\"#urls\">{$text3}</a></td><td></td></tr>\n"; $V .= "<tr><td valign='top' width='50%'>{$VCopyright}</td><td valign='top'>{$VF}</td></tr>\n"; $V .= "<tr><td><a name=\"emails\"></a>Jump to: <a href=\"#statements\">{$text2}</a> | <a href=\"#urls\">{$text3}</a></td><td></td></tr>\n"; $V .= "<tr><td valign='top' width='50%'>{$VEmail}</td><td valign='top'></td></tr>\n"; $V .= "<tr><td><a name=\"urls\"></a>Jump To: <a href=\"#statements\">{$text2}</a> | <a href=\"#emails\">{$text1}</a></td><td></td></tr>\n"; $V .= "<tr><td valign='top' width='50%'>{$VUrl}</td><td valign='top'></td></tr>\n"; $V .= "</table>\n"; $V .= "<hr />\n"; return $V; }
/** * \brief This function returns the scheduler status. */ function Output() { $uTime = microtime(true); if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $Folder = GetParm("folder", PARM_INTEGER); $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); $updcache = GetParm("updcache", PARM_INTEGER); $tagbucket = GetParm("tagbucket", PARM_INTEGER); $this->uploadtree_tablename = GetUploadtreeTableName($Upload); /* 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("upload", "item", "folder", "ars")); 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($tagbucket)) { $bucketagent_pk = GetParm("bapk", PARM_INTEGER); $bucket_pk = GetParm("bpk", PARM_INTEGER); $bucketpool_pk = GetParm("bp", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $this->TagBucket($Upload, $Item, $bucketagent_pk, $bucket_pk, $bucketpool_pk, $nomosagent_pk); } if (empty($V)) { switch ($this->OutputType) { case "XML": break; case "HTML": $V .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ /* Get ALL the items under this Uploadtree_pk */ $Children = GetNonArtifactChildren($Item, $this->uploadtree_tablename); if (count($Children) == 0) { // no children, display View micromenu $V .= Dir2Browse($this->Name, $Item, NULL, 1, "View", -1, '', '', $this->uploadtree_tablename) . "<P />\n"; } else { // has children, display Browse micormenu $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 .= $this->ShowUploadHist($Item, $Uri); } $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("<p><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 Given an uploadtree_pk, find all the non-artifact, immediate children * (uploadtree_pk's) that have license $rf_shortname. * By "immediate" I mean the earliest direct non-artifact. * For example: * A > B, C (A has children B and C) * If C is an artifact, descend that tree till you find the first non-artifact * and consider that non-artifact an immediate child. * * \param $agent_pk - agent id * \param $rf_shortname - short name of one license, like GPL, APSL, MIT, ... * \param $uploadtree_pk sets scope of request * \param $PkgsOnly - if true, only list packages, default is false (all files are listed) * $PkgsOnly is not yet implemented. * * \returns Array of uploadtree_pk ==> ufile_name */ function Level1WithLicense($agent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly = false, $uploadtree_tablename) { $pkarray = array(); $Children = GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename); /* Loop throught each top level uploadtree_pk */ $offset = 0; $limit = 1; $order = ""; $tag_pk = null; $result = NULL; foreach ($Children as $row) { //$uTime2 = microtime(true); $result = GetFilesWithLicense($agent_pk, $rf_shortname, $row['uploadtree_pk'], $PkgsOnly, $offset, $limit, $order, $tag_pk, $uploadtree_tablename); //$Time = microtime(true) - $uTime2; //printf( "GetFilesWithLicense($row[ufile_name]) time: %.2f seconds<br>", $Time); if (pg_num_rows($result) > 0) { $pkarray[$row['uploadtree_pk']] = $row['ufile_name']; } } if ($result) { pg_free_result($result); } return $pkarray; }
/** * \brief Find the non artifact children of an uploadtree pk. * If any children are artifacts, resolve them until you get * to a non-artifact. * * This function replaces DirGetList() * * \param $uploadtree_pk * \param $uploadtree_tablename * * \return list of child uploadtree recs + pfile_size + pfile_mimetypefk on success. * list may be empty if there are no children. * Child list is sorted by ufile_name. */ function GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename = 'uploadtree') { global $PG_CONN; $foundChildren = array(); /* Find all the children */ $sql = "select {$uploadtree_tablename}.*, pfile_size, pfile_mimetypefk from {$uploadtree_tablename}\n left outer join pfile on (pfile_pk=pfile_fk)\n where parent={$uploadtree_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) == 0) { pg_free_result($result); return $foundChildren; } $children = pg_fetch_all($result); pg_free_result($result); /* Loop through each child and replace any artifacts with their non artifact child. Or skip them if they are not containers. */ foreach ($children as $key => $child) { if (Isartifact($child['ufile_mode'])) { if (Iscontainer($child['ufile_mode'])) { unset($children[$key]); $NonAChildren = GetNonArtifactChildren($child['uploadtree_pk'], $uploadtree_tablename); if ($NonAChildren) { $foundChildren = array_merge($foundChildren, $NonAChildren); } } else { unset($children[$key]); } } else { $foundChildren[$key] = $child; } } uasort($foundChildren, '_DirCmp'); return $foundChildren; }
/** * \brief Given a upload_pk, list every item in it. * If it is an individual file, then list the file contents. */ function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename) { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); $RowStyle1 = "style='background-color:#ecfaff'"; // pale blue $RowStyle2 = "style='background-color:#ffffe3'"; // pale yellow $ColorSpanRows = 3; // Alternate background color every $ColorSpanRows $RowNum = 0; $V = ""; /* Use plugin "view" and "download" if they exist. */ $Uri = Traceback_uri() . "?mod=" . $this->Name . "&folder={$Folder}"; /* there are three types of Browse-Pfile menus */ /* menu as defined by their plugins */ $MenuPfile = menu_find("Browse-Pfile", $MenuDepth); /* menu but without Compare */ $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare"); /* menu with only Tag and Compare */ $MenuTag = array(); foreach ($MenuPfile as $value) { if ($value->Name == 'Tag' or $value->Name == 'Compare') { $MenuTag[] = $value; } } $Results = GetNonArtifactChildren($Item, $uploadtree_tablename); $ShowSomething = 0; $V .= "<table class='text' style='border-collapse: collapse' border=0 padding=0>\n"; $stmtGetFirstChild = __METHOD__ . '.getFirstChild'; $dbManager->prepare($stmtGetFirstChild, "SELECT uploadtree_pk FROM {$uploadtree_tablename} WHERE parent=\$1 limit 1"); foreach ($Results as $Row) { if (empty($Row['uploadtree_pk'])) { continue; } $ShowSomething = 1; $Name = $Row['ufile_name']; /* Set alternating row background color - repeats every $ColorSpanRows rows */ $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2; $V .= "<tr {$RowStyle}>"; /* Check for children so we know if the file should by hyperlinked */ $result = $dbManager->execute($stmtGetFirstChild, array($Row['uploadtree_pk'])); $HasChildren = $dbManager->fetchArray($result); $dbManager->freeResult($result); $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk']; $Link = $HasChildren ? "{$Uri}&show={$Show}&upload={$Upload}&item={$Row['uploadtree_pk']}" : NULL; if ($Show == 'detail') { $V .= "<td class='mono'>" . DirMode2String($Row['ufile_mode']) . "</td>"; if (!Isdir($Row['ufile_mode'])) { $V .= "<td align='right'> " . number_format($Row['pfile_size'], 0, "", ",") . " </td>"; } else { $V .= "<td> </td>"; } } $displayItem = Isdir($Row['ufile_mode']) ? "{$Name}/" : $Name; if (!empty($Link)) { $displayItem = "<a href=\"{$Link}\">{$displayItem}</a>"; } if (Iscontainer($Row['ufile_mode'])) { $displayItem = "<b>{$displayItem}</b>"; } $V .= "<td>{$displayItem}</td>\n"; if (!Iscontainer($Row['ufile_mode'])) { $V .= menu_to_1list($MenuPfileNoCompare, $Parm, "<td>", "</td>\n", 1, $Upload); } else { if (!Isdir($Row['ufile_mode'])) { $V .= menu_to_1list($MenuPfile, $Parm, "<td>", "</td>\n", 1, $Upload); } else { $V .= menu_to_1list($MenuTag, $Parm, "<td>", "</td>\n", 1, $Upload); } } } /* foreach($Results as $Row) */ $V .= "</table>\n"; if (!$ShowSomething) { $text = _("No files"); $V .= "<b>{$text}</b>\n"; } else { $V .= "<hr>\n"; if (count($Results) == 1) { $text = _("1 item"); $V .= "{$text}\n"; } else { $text = _("items"); $V .= count($Results) . " {$text}\n"; } } return $V; }
/** * \brief Given a upload_pk, list every item in it. * If it is an individual file, then list the file contents. */ function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename) { global $PG_CONN; $RowStyle1 = "style='background-color:#ecfaff'"; // pale blue $RowStyle2 = "style='background-color:#ffffe3'"; // pale yellow $ColorSpanRows = 3; // Alternate background color every $ColorSpanRows $RowNum = 0; $V = ""; /* Use plugin "view" and "download" if they exist. */ $Uri = Traceback_uri() . "?mod=" . $this->Name . "&folder={$Folder}"; /* there are three types of Browse-Pfile menus */ /* menu as defined by their plugins */ $MenuPfile = menu_find("Browse-Pfile", $MenuDepth); /* menu but without Compare */ $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare"); /* menu with only Tag and Compare */ $MenuTag = array(); foreach ($MenuPfile as $key => $value) { if ($value->Name == 'Tag' or $value->Name == 'Compare') { $MenuTag[] = $value; } } /* Get the (non artifact) children */ $Results = GetNonArtifactChildren($Item, $uploadtree_tablename); $ShowSomething = 0; $V .= "<table class='text' style='border-collapse: collapse' border=0 padding=0>\n"; foreach ($Results as $Row) { if (empty($Row['uploadtree_pk'])) { continue; } $ShowSomething = 1; $Link = NULL; $Name = $Row['ufile_name']; /* Set alternating row background color - repeats every $ColorSpanRows rows */ $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2; $V .= "<tr {$RowStyle}>"; /* Check for children so we know if the file should by hyperlinked */ $sql = "select uploadtree_pk from uploadtree\n where parent={$Row['uploadtree_pk']} limit 1"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $HasChildren = pg_num_rows($result); pg_free_result($result); $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk']; if ($HasChildren) { $Link = $Uri . "&show={$Show}&upload={$Upload}&item=" . $Row['uploadtree_pk']; } /* Show details children */ if ($Show == 'detail') { $V .= "<td class='mono'>" . DirMode2String($Row['ufile_mode']) . "</td>"; if (!Isdir($Row['ufile_mode'])) { $V .= "<td align='right'> " . number_format($Row['pfile_size'], 0, "", ",") . " </td>"; } else { $V .= "<td> </td>"; } } /* Display item */ $V .= "<td>"; if (Iscontainer($Row['ufile_mode'])) { $V .= "<b>"; } if (!empty($Link)) { $V .= "<a href='{$Link}'>"; } $V .= $Name; if (Isdir($Row['ufile_mode'])) { $V .= "/"; } if (!empty($Link)) { $V .= "</a>"; } if (Iscontainer($Row['ufile_mode'])) { $V .= "</b>"; } $V .= "</td>\n"; if (!Iscontainer($Row['ufile_mode'])) { $V .= menu_to_1list($MenuPfileNoCompare, $Parm, "<td>", "</td>\n", 1, $Upload); } else { if (!Isdir($Row['ufile_mode'])) { $V .= menu_to_1list($MenuPfile, $Parm, "<td>", "</td>\n", 1, $Upload); } else { $V .= menu_to_1list($MenuTag, $Parm, "<td>", "</td>\n", 1, $Upload); } } $V .= "</td>"; } /* foreach($Results as $Row) */ $V .= "</table>\n"; if (!$ShowSomething) { $text = _("No files"); $V .= "<b>{$text}</b>\n"; } else { $V .= "<hr>\n"; if (count($Results) == 1) { $text = _("1 item"); $V .= "{$text}\n"; } else { $text = _("items"); $V .= count($Results) . " {$text}\n"; } } return $V; }
public function htmlContent() { $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; } /* @var $uploadDao UploadDao */ $uploadDao = $GLOBALS['container']->get('dao.upload'); /* Check item1 upload permission */ $Item1Row = $uploadDao->getUploadEntry($in_uploadtree_pk1); if (!$uploadDao->isAccessible($Item1Row['upload_fk'], Auth::getGroupId())) { $text = _("Permission Denied"); return "<h2>{$text} item 1</h2>"; } /* Check item2 upload permission */ $Item2Row = $uploadDao->getUploadEntry($in_uploadtree_pk2); if (!$uploadDao->isAccessible($Item2Row['upload_fk'], Auth::getGroupId())) { $text = _("Permission Denied"); return "<h2>{$text} item 2</h2>"; } $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 { $BucketDefArray1 = initBucketDefArray($TreeInfo1['bucketpool_pk']); $BucketDefArray2 = initBucketDefArray($TreeInfo2['bucketpool_pk']); $BucketDefArray = $BucketDefArray1 + $BucketDefArray2; /* 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); } } if ($this->OutputType == 'HTML') { if ($ErrMsg) { $V .= $ErrMsg; } else { $V .= $this->HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray); } } return $V; }