/** * \brief testing for GetFilesWithLicense */ function testGetFilesWithLicense() { print "test function GetFilesWithLicense()\n"; global $PG_CONN; global $uploadtree_pk_parent; global $pfile_pk_parent; global $agent_pk; /** get a license short name */ $sql = "SELECT rf_shortname from license_ref where rf_pk = 1;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $rf_shortname = $row['rf_shortname']; pg_free_result($result); $files_result = GetFilesWithLicense($agent_pk, $rf_shortname, $uploadtree_pk_parent, false, 0, "ALL", "", null, $this->uploadtree_tablename); $row = pg_fetch_assoc($files_result); $pfile_id_actual = $row['pfile_fk']; pg_free_result($files_result); $this->assertEquals($pfile_pk_parent, $pfile_id_actual); }
/** * \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 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 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; }