/** * \brief test for GetPkgMimetypes() */ function test_GetPkgMimetypes() { print "test function GetPkgMimetypes()\n"; global $PG_CONN; #prepare database testdata $mimeType = "application/x-rpm"; /** delete test data pre testing */ $sql = "DELETE FROM mimetype where mimetype_name in ('{$mimeType}');"; $result = pg_query($PG_CONN, $sql); pg_free_result($result); /** insert on record */ $sql = "INSERT INTO mimetype(mimetype_pk, mimetype_name) VALUES(10000, '{$mimeType}');"; $result = pg_query($PG_CONN, $sql); pg_free_result($result); #begin test GetPkgMimetypes() $sql = "select * from mimetype where\n mimetype_name='application/x-rpm'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $expected = $row['mimetype_pk']; pg_free_result($result); $result = GetPkgMimetypes(); $this->assertContains($expected, $result); /** delete test data post testing */ $sql = "DELETE FROM mimetype where mimetype_name in ('{$mimeType}');"; $result = pg_query($PG_CONN, $sql); pg_free_result($result); }
/** * \brief Given an $Uploadtree_pk, display: \n * (1) The histogram for the directory BY bucket. \n * (2) The file listing for the directory. */ function ShowUploadHist($Uploadtree_pk, $Uri) { global $PG_CONN; $VF = ""; // return values for file listing $VLic = ""; // return values for output $V = ""; // total return value $UniqueTagArray = array(); global $Plugins; $ModLicView =& $Plugins[plugin_find_id("view-license")]; /******* Get Bucket 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__); if (pg_num_rows($result) < 1) { pg_free_result($result); $text = _("Invalid URL, nonexistant item"); return "<h2>{$text} {$Uploadtree_pk}</h2>"; } $row = pg_fetch_assoc($result); $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; pg_free_result($result); /* Get the ars_pk of the scan to display, also the select list */ $ars_pk = GetArrayVal("ars", $_GET); $BucketSelect = SelectBucketDataset($upload_pk, $ars_pk, "selectbdata", "onchange=\"addArsGo('newds','selectbdata');\""); if ($ars_pk == 0) { /* No bucket data for this upload */ return $BucketSelect; } /* Get scan keys */ $sql = "select agent_fk, nomosagent_fk, bucketpool_fk from bucket_ars where ars_pk={$ars_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $bucketagent_pk = $row["agent_fk"]; $nomosagent_pk = $row["nomosagent_fk"]; $bucketpool_pk = $row["bucketpool_fk"]; pg_free_result($result); /* Create bucketDefArray as individual query this is MUCH faster than incorporating it with a join in the following queries. */ $bucketDefArray = initBucketDefArray($bucketpool_pk); /*select all the buckets for entire tree for this bucketpool */ $sql = "SELECT distinct(bucket_fk) as bucket_pk,\n count(bucket_fk) as bucketcount, bucket_reportorder\n from bucket_file, bucket_def,\n (SELECT distinct(pfile_fk) as PF from {$this->uploadtree_tablename} \n where upload_fk={$upload_pk} \n and ((ufile_mode & (1<<28))=0)\n and ((ufile_mode & (1<<29))=0)\n and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt}) as SS\n where PF=pfile_fk and agent_fk={$bucketagent_pk} \n and bucket_file.nomosagent_fk={$nomosagent_pk}\n and bucket_pk=bucket_fk\n and bucketpool_fk={$bucketpool_pk}\n group by bucket_fk,bucket_reportorder\n order by bucket_reportorder asc"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $historows = pg_fetch_all($result); pg_free_result($result); /* Show dataset list */ if (!empty($BucketSelect)) { $action = Traceback_uri() . "?mod=bucketbrowser&upload={$upload_pk}&item={$Uploadtree_pk}"; $VLic .= "<script type='text/javascript'>\nfunction addArsGo(formid, selectid ) \n{\nvar selectobj = document.getElementById(selectid);\nvar ars_pk = selectobj.options[selectobj.selectedIndex].value;\ndocument.getElementById(formid).action='{$action}'+'&ars='+ars_pk;\ndocument.getElementById(formid).submit();\nreturn;\n}\n</script>"; /* form to select new dataset (ars_pk) */ $VLic .= "<form action='{$action}' id='newds' method='POST'>\n"; $VLic .= $BucketSelect; $VLic .= "</form>"; } $sql = "select bucketpool_name, version from bucketpool where bucketpool_pk={$bucketpool_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $bucketpool_name = $row['bucketpool_name']; $bucketpool_version = $row['version']; pg_free_result($result); /* Write bucket histogram to $VLic */ $bucketcount = 0; $Uniquebucketcount = 0; $NoLicFound = 0; if (is_array($historows)) { $text = _("Bucket Pool"); $VLic .= "{$text}: {$bucketpool_name} v{$bucketpool_version}<br>"; $VLic .= "<table border=1 width='100%'>\n"; $text = _("Count"); $VLic .= "<tr><th width='10%'>{$text}</th>"; $text = _("Files"); $VLic .= "<th width='10%'>{$text}</th>"; $text = _("Bucket"); $VLic .= "<th align='left'>{$text}</th></tr>\n"; foreach ($historows as $bucketrow) { $Uniquebucketcount++; $bucket_pk = $bucketrow['bucket_pk']; $bucketcount = $bucketrow['bucketcount']; $bucket_name = $bucketDefArray[$bucket_pk]['bucket_name']; $bucket_color = $bucketDefArray[$bucket_pk]['bucket_color']; /* Count */ $VLic .= "<tr><td align='right' style='background-color:{$bucket_color}'>{$bucketcount}</td>"; /* Show */ $VLic .= "<td align='center'><a href='"; $VLic .= Traceback_uri(); $text = _("Show"); $VLic .= "?mod=list_bucket_files&bapk={$bucketagent_pk}&item={$Uploadtree_pk}&bpk={$bucket_pk}&bp={$bucketpool_pk}&napk={$nomosagent_pk}" . "'>{$text}</a></td>"; /* Bucket name */ $VLic .= "<td align='left'>"; $VLic .= "<a id='{$bucket_pk}' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filebucket&bapk={$bucketagent_pk}&item={$Uploadtree_pk}&bucket_pk={$bucket_pk}\")'"; $VLic .= ">{$bucket_name} </a>"; /* Allow users to tag an entire bucket */ /* Future, maybe v 2.1 $TagHref = "<a href=" . Traceback_uri() . "?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk&bapk=$bucketagent_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk&tagbucket=1>Tag</a>"; $VLic .= " [$TagHref]"; */ $VLic .= "</td>"; $VLic .= "</tr>\n"; // if ($row['bucket_name'] == "No Buckets Found") $NoLicFound = $row['bucketcount']; } $VLic .= "</table>\n"; $VLic .= "<p>\n"; $text = _("Unique buckets"); $VLic .= "{$text}: {$Uniquebucketcount}<br>\n"; } /******* File Listing ************/ /* Get ALL the items under this Uploadtree_pk */ $Children = GetNonArtifactChildren($Uploadtree_pk, $this->uploadtree_tablename); if (count($Children) == 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 (empty($row) || IsDir($row['ufile_mode'])) { return; } // $ModLicView = &$Plugins[plugin_find_id("view-license")]; // return($ModLicView->Output() ); } $ChildCount = 0; $Childbucketcount = 0; /* Countd disabled until we know we need them $NumSrcPackages = 0; $NumBinPackages = 0; $NumBinNoSrcPackages = 0; */ /* get mimetypes for packages */ $MimetypeArray = GetPkgMimetypes(); $VF .= "<table border=0>"; foreach ($Children as $C) { if (empty($C)) { continue; } /* update package counts */ /* This is an expensive count. Comment out until we know we really need it IncrSrcBinCounts($C, $MimetypeArray, $NumSrcPackages, $NumBinPackages, $NumBinNoSrcPackages); */ $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={$nomosagent_pk}&bapk={$bucketagent_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); $tmpuri = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "folder", "ars")); $LicUri = "{$tmpuri}&item=" . $uploadtree_pk; } else { $LicUri = NULL; } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ $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>"; } /* print buckets */ $VF .= "<br>"; $VF .= "<span style='position:relative;left:1em'>"; /* get color coded string of bucket names */ $VF .= GetFileBuckets_string($nomosagent_pk, $bucketagent_pk, $C['uploadtree_pk'], $bucketDefArray, ",", True); $VF .= "</span>"; $VF .= "</td><td valign='top'>"; /* display item links */ $VF .= FileListLinks($C['upload_fk'], $C['uploadtree_pk'], $nomosagent_pk, $C['pfile_fk'], True, $UniqueTagArray, $this->uploadtree_tablename); $VF .= "</td>"; $VF .= "</tr>\n"; $ChildCount++; } $VF .= "</table>\n"; $V .= ActiveHTTPscript("FileColor"); /* Add javascript for color highlighting This is the response script needed by ActiveHTTPscript responseText is bucket_pk',' 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 Lastbupk=''; /* save last bucket_pk */\n var color = '#4bfe78';\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(Lastbupk).style.backgroundColor='white';\n while (numpks)\n {\n document.getElementById(Lastutpks[--numpks]).style.backgroundColor='white';\n }\n\n utpklist = FileColor.responseText.split(',');\n Lastbupk = utpklist.shift();\n numpks = utpklist.length;\n Lastutpks = utpklist;\n\n /* apply new highlighting */\n elt = document.getElementById(Lastbupk);\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; /* Display source, binary, and binary missing source package counts */ /* Counts disabled above until we know we need these $VLic .= "<ul>"; $text = _("source packages"); $VLic .= "<li> $NumSrcPackages $text"; $text = _("binary packages"); $VLic .= "<li> $NumBinPackages $text"; $text = _("binary packages with no source package"); $VLic .= "<li> $NumBinNoSrcPackages $text"; $VLic .= "</ul>"; */ /* Combine VF and VLic */ $V .= "<table border=0 width='100%'>\n"; $V .= "<tr><td valign='top' width='50%'>{$VLic}</td><td valign='top'>{$VF}</td></tr>\n"; $V .= "</table>\n"; $V .= "<hr />\n"; return $V; }
/** * \brief Add a new Tag. */ function CreateTag($tag_array) { global $PG_CONN; $Upload = GetParm("upload", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); if (empty($Item) || empty($Upload)) { return; } if (isset($tag_array)) { $tag_name = $tag_array["tag_name"]; $tag_notes = $tag_array["tag_notes"]; $tag_file = $tag_array["tag_file"]; $tag_package = $tag_array["tag_package"]; $tag_container = $tag_array["tag_container"]; $tag_desc = $tag_array["tag_desc"]; $tag_dir = $tag_array["tag_dir"]; } else { $tag_name = GetParm('tag_name', PARM_TEXT); $tag_notes = GetParm('tag_notes', PARM_TEXT); $tag_file = GetParm('tag_file', PARM_TEXT); $tag_package = GetParm('tag_package', PARM_TEXT); $tag_container = GetParm('tag_container', PARM_TEXT); $tag_desc = GetParm('tag_desc', PARM_TEXT); $tag_dir = GetParm('tag_dir', PARM_TEXT); } /* Debug print "<pre>"; print "Create Tag: TagName is:$tag_name\n"; print "Create Tag: TagNotes is:$tag_notes\n"; print "Create Tag: TagFile is:$tag_file\n"; print "Create Tag: TagPackage is:$tag_package\n"; print "Create Tag: TagContainer is:$tag_container\n"; print "Upload: $Upload\n"; print "Item: $Item\n"; print "</pre>"; */ if (empty($tag_name)) { $text = _("TagName must be specified. Tag Not created."); return $text; } /* Need select tag file/package/container */ if (empty($tag_dir) && empty($tag_file) && empty($tag_package) && empty($tag_container)) { $text = _("Need to select one option (dir/file/package/container) to create tag."); return $text; } pg_exec("BEGIN;"); /* See if the tag already exists */ $sql = "SELECT * FROM tag WHERE tag = '{$tag_name}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); $Val = str_replace("'", "''", $tag_name); $Val1 = str_replace("'", "''", $tag_desc); $sql = "INSERT INTO tag (tag,tag_desc) VALUES ('{$Val}', '{$Val1}');"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } else { pg_free_result($result); } /* Make sure it was added */ $sql = "SELECT * FROM tag WHERE tag = '{$tag_name}' LIMIT 1;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); $text = _("Failed to create tag."); return $text; } $row = pg_fetch_assoc($result); $tag_pk = $row["tag_pk"]; pg_free_result($result); $pfileArray = array(); $i = 0; if (!empty($tag_file)) { /* Get pfile_fk from uploadtree_pk */ $sql = "SELECT pfile_fk FROM uploadtree\n WHERE uploadtree_pk = {$Item} LIMIT 1"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($row = pg_fetch_assoc($result)) { $pfileArray[$i] = $row['pfile_fk']; $i++; } pg_free_result($result); } if (!empty($tag_package)) { /* GetPkgMimetypes */ $MimetypeArray = GetPkgMimetypes(); $sql = "SELECT distinct pfile.pfile_pk FROM uploadtree, pfile WHERE uploadtree.pfile_fk = pfile.pfile_pk AND (pfile.pfile_mimetypefk = {$MimetypeArray['0']} OR pfile.pfile_mimetypefk = {$MimetypeArray['1']} OR pfile.pfile_mimetypefk = {$MimetypeArray['2']}) AND uploadtree.upload_fk = {$Upload} AND uploadtree.lft >= (SELECT lft FROM uploadtree WHERE uploadtree_pk = {$Item}) AND uploadtree.rgt <= (SELECT rgt FROM uploadtree WHERE uploadtree_pk = {$Item});"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($row = pg_fetch_assoc($result)) { $pfileArray[$i] = $row['pfile_pk']; $i++; } pg_free_result($result); } if (!empty($tag_container)) { $sql = "SELECT distinct pfile_fk FROM uploadtree WHERE upload_fk = {$Upload} AND lft >= (SELECT lft FROM uploadtree WHERE uploadtree_pk = {$Item}) AND rgt <= (SELECT rgt FROM uploadtree WHERE uploadtree_pk = {$Item}) AND ((ufile_mode & (1<<28))=0) AND pfile_fk!=0;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($row = pg_fetch_assoc($result)) { $pfileArray[$i] = $row['pfile_fk']; $i++; } pg_free_result($result); } //echo sizeof($pfileArray); if (!empty($tag_dir)) { $sql = "SELECT tag_uploadtree_pk FROM tag_uploadtree WHERE tag_fk = {$tag_pk} AND uploadtree_fk = {$Item};"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); /* Add record to tag_uploadtree table */ $Val = str_replace("'", "''", $tag_notes); $sql = "INSERT INTO tag_uploadtree (tag_fk,uploadtree_fk,tag_uploadtree_date,tag_uploadtree_text) VALUES ({$tag_pk}, {$Item}, now(), '{$Val}');"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } else { $text = _("This Tag already associated with this Directory!"); pg_exec("ROLLBACK;"); pg_free_result($result); return $text; } } else { foreach ($pfileArray as $pfile) { $sql = "SELECT tag_file_pk FROM tag_file WHERE tag_fk = {$tag_pk} AND pfile_fk = {$pfile};"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { pg_free_result($result); /* Add record to tag_file table */ $Val = str_replace("'", "''", $tag_notes); $sql = "INSERT INTO tag_file (tag_fk,pfile_fk,tag_file_date,tag_file_text) VALUES ({$tag_pk}, {$pfile}, now(), '{$Val}');"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); pg_free_result($result); } else { $text = _("This Tag already associated with this File!"); pg_exec("ROLLBACK;"); pg_free_result($result); return $text; } } } pg_exec("COMMIT;"); return NULL; }