/**
  * \brief test for ActiveHTTPscript
  */
 function testActiveHTTPscript()
 {
     print "Start unit test for common-active.php\n";
     print "test function ActiveHTTPscript\n";
     /** $IncludeScriptTags is default 1 */
     $html_result = ActiveHTTPscript("test");
     $script_header = "<script language='javascript'>\n<!--\n";
     $script_foot = "\n// -->\n</script>\n";
     $html_expect = "";
     $html_expect .= "var test=null;\n";
     /* Check for browser support. */
     $html_expect .= "function test_Get(Url)\n";
     $html_expect .= "{\n";
     $html_expect .= "if (window.XMLHttpRequest)\n";
     $html_expect .= "  {\n";
     $html_expect .= "  test=new XMLHttpRequest();\n";
     $html_expect .= "  }\n";
     /* Check for IE5 and IE6 */
     $html_expect .= "else if (window.ActiveXObject)\n";
     $html_expect .= "  {\n";
     $html_expect .= "  test=new ActiveXObject('Microsoft.XMLHTTP');\n";
     $html_expect .= "  }\n";
     $html_expect .= "if (test!=null)\n";
     $html_expect .= "  {\n";
     $html_expect .= "  test.onreadystatechange=test_Reply;\n";
     /***
        'true' means asynchronous request.
        Rather than waiting for the reply, the reply is
        managed by the onreadystatechange event handler.
        ***/
     $html_expect .= "  test.open('GET',Url,true);\n";
     $html_expect .= "  test.send(null);\n";
     $html_expect .= "  }\n";
     $html_expect .= "else\n";
     $html_expect .= "  {\n";
     $html_expect .= "  alert('Your browser does not support XMLHTTP.');\n";
     $html_expect .= "  return;\n";
     $html_expect .= "  }\n";
     $html_expect .= "}\n";
     $html_expect_script = $script_header . $html_expect . $script_foot;
     $this->assertEquals($html_expect_script, $html_result);
     /** $IncludeScriptTags is no default 1 */
     $html_result = ActiveHTTPscript("test", 0);
     $this->assertEquals($html_expect, $html_result);
     print "unit test for common-active.php end\n";
 }
Beispiel #2
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $folderId = intval($request->get('folder'));
     if (empty($folderId)) {
         $folderId = FolderGetTop();
     }
     $uploadId = intval($request->get('upload'));
     $agents = $request->get('agents') ?: '';
     if (!empty($uploadId) && !empty($agents) && is_array($agents)) {
         $rc = $this->agentsAdd($uploadId, $agents, $request);
         if (empty($rc)) {
             $status = GetRunnableJobList();
             $scheduler_msg = empty($status) ? _("Is the scheduler running? ") : '';
             $url = Traceback_uri() . "?mod=showjobs&upload={$uploadId}";
             $text = _("Your jobs have been added to job queue.");
             $linkText = _("View Jobs");
             $msg = "{$scheduler_msg}" . "{$text} <a href=\"{$url}\">{$linkText}</a>";
             $vars['message'] = $msg;
         } else {
             $text = _("Scheduling of Agent(s) failed: ");
             $vars['message'] = $text . $rc;
         }
     }
     $vars['uploadScript'] = ActiveHTTPscript("Uploads");
     $vars['agentScript'] = ActiveHTTPscript("Agents");
     $vars['folderId'] = $folderId;
     $vars['folderListOptions'] = FolderListOption(-1, 0, 1, $folderId);
     $vars['folderListUploads'] = FolderListUploads_perm($folderId, Auth::PERM_WRITE);
     $vars['baseUri'] = Traceback_uri();
     $vars['uploadId'] = $uploadId;
     $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents");
     $out = '<ol>';
     $parmAgentFoots = '';
     foreach ($parmAgentList as $parmAgent) {
         $agent = plugin_find($parmAgent);
         $out .= "<br/><b>" . $agent->AgentName . ":</b><br/>";
         $out .= $agent->renderContent($vars);
         $parmAgentFoots .= $agent->renderFoot($vars);
     }
     $out .= '</ol>';
     $vars['out'] = $out;
     $vars['outFoot'] = '<script language="javascript"> ' . $parmAgentFoots . '</script>';
     return $this->render('agent_adder.html.twig', $this->mergeWithDefault($vars));
 }
Beispiel #3
0
 /**
  * \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 Generate the text for this plugin.
  */
 public function Output()
 {
     $V = "";
     /* If this is a POST, then process the request. */
     $uploadpk = GetParm('upload', PARM_INTEGER);
     if (!empty($uploadpk)) {
         $rc = $this->Delete($uploadpk);
         if (empty($rc)) {
             /* Need to refresh the screen */
             $URL = Traceback_uri() . "?mod=showjobs&upload={$uploadpk} ";
             $LinkText = _("View Jobs");
             $text = _("Deletion added to job queue.");
             $msg = "{$text} <a href={$URL}>{$LinkText}</a>";
             $V .= displayMessage($msg);
         } else {
             $text = _("Deletion Scheduling failed: ");
             $V .= DisplayMessage($text . $rc);
         }
     }
     /* Create the AJAX (Active HTTP) javascript for doing the reply
        and showing the response. */
     $V .= ActiveHTTPscript("Uploads");
     $V .= "<script language='javascript'>\n";
     $V .= "function Uploads_Reply()\n";
     $V .= "  {\n";
     $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
     $V .= "    {\n";
     /* Remove all options */
     //$V.= "    document.formy.upload.innerHTML = Uploads.responseText;\n";
     $V .= "    document.getElementById('uploaddiv').innerHTML = '<BR><select name=\\'upload\\' size=\\'10\\'>' + Uploads.responseText + '</select><P />';\n";
     /* Add new options */
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     /* Build HTML form */
     $V .= "<form name='formy' method='post'>\n";
     // no url = this url
     $text = _("Select the uploaded file to");
     $text1 = _("delete");
     $V .= "{$text} <em>{$text1}</em>\n";
     $V .= "<ul>\n";
     $text = _("This will");
     $text1 = _("delete");
     $text2 = _("the upload file!");
     $V .= "<li>{$text} <em>{$text1}</em> {$text2}\n";
     $text = _("Be very careful with your selection since you can delete a lot of work!\n");
     $V .= "<li>{$text}";
     $text = _("All analysis only associated with the deleted upload file will also be deleted.\n");
     $V .= "<li>{$text}";
     $text = _("THERE IS NO UNDELETE. When you select something to delete, it will be removed from the database and file repository.\n");
     $V .= "<li>{$text}";
     $V .= "</ul>\n";
     $text = _("Select the uploaded file to delete:");
     $V .= "<P>{$text}<P>\n";
     $V .= "<ol>\n";
     $text = _("Select the folder containing the file to delete: ");
     $V .= "<li>{$text}";
     $V .= "<select name='folder' ";
     $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=-1' ";
     $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
     $root_folder_pk = GetUserRootFolder();
     $V .= FolderListOption($root_folder_pk, 0);
     $V .= "</select><P />\n";
     $text = _("Select the uploaded project to delete:");
     $V .= "<li>{$text}";
     $V .= "<div id='uploaddiv'>\n";
     $V .= "<BR><select name='upload' size='10'>\n";
     $List = FolderListUploads_perm($root_folder_pk, Auth::PERM_WRITE);
     foreach ($List as $L) {
         $V .= "<option value='" . $L['upload_pk'] . "'>";
         $V .= htmlentities($L['name']);
         if (!empty($L['upload_desc'])) {
             $V .= " (" . htmlentities($L['upload_desc']) . ")";
         }
         if (!empty($L['upload_ts'])) {
             $V .= " :: " . substr($L['upload_ts'], 0, 19);
         }
         $V .= "</option>\n";
     }
     $V .= "</select><P />\n";
     $V .= "</div>\n";
     $V .= "</ol>\n";
     $text = _("Delete");
     $V .= "<input type='submit' value='{$text}!'>\n";
     $V .= "</form>\n";
     return $V;
 }
 public function Output()
 {
     $OutBuf = "";
     $uploadId = GetParm("upload", PARM_INTEGER);
     $item = GetParm("item", PARM_INTEGER);
     $filter = GetParm("filter", PARM_STRING);
     /* check upload permissions */
     if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text}</h2>";
     }
     /* Get uploadtree_tablename */
     $uploadtree_tablename = GetUploadtreeTableName($uploadId);
     $this->uploadtree_tablename = $uploadtree_tablename;
     /************************/
     /* Show the folder path */
     /************************/
     $this->vars['dir2browse'] = Dir2Browse($this->Name, $item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename);
     if (empty($uploadId)) {
         return 'no item selected';
     }
     /** advanced interface allowing user to select dataset (agent version) */
     $dataset = $this->agentName . "_dataset";
     $arstable = $this->agentName . "_ars";
     /** get proper agent_id */
     $agentId = GetParm("agent", PARM_INTEGER);
     if (empty($agentId)) {
         $agentId = LatestAgentpk($uploadId, $arstable);
     }
     if ($agentId == 0) {
         /** schedule copyright */
         $OutBuf .= ActiveHTTPscript("Schedule");
         $OutBuf .= "<script language='javascript'>\n";
         $OutBuf .= "function Schedule_Reply()\n";
         $OutBuf .= "  {\n";
         $OutBuf .= "  if ((Schedule.readyState==4) && (Schedule.status==200 || Schedule.status==400))\n";
         $OutBuf .= "    document.getElementById('msgdiv').innerHTML = Schedule.responseText;\n";
         $OutBuf .= "  }\n";
         $OutBuf .= "</script>\n";
         $OutBuf .= "<form name='formy' method='post'>\n";
         $OutBuf .= "<div id='msgdiv'>\n";
         $OutBuf .= _("No data available.");
         $OutBuf .= "<input type='button' name='scheduleAgent' value='Schedule Agent'";
         $OutBuf .= "onClick=\"Schedule_Get('" . Traceback_uri() . "?mod=schedule_agent&upload={$uploadId}&agent=agent_{$this->agentName}')\">\n";
         $OutBuf .= "</input>";
         $OutBuf .= "</div> \n";
         $OutBuf .= "</form>\n";
         $this->vars['pageContent'] = $OutBuf;
         return;
     }
     $AgentSelect = AgentSelect($this->agentName, $uploadId, $dataset, $agentId, "onchange=\"addArsGo('newds', 'copyright_dataset');\"");
     /** change the copyright  result when selecting one version of copyright */
     if (!empty($AgentSelect)) {
         $action = Traceback_uri() . '?mod=' . GetParm('mod', PARM_RAW) . Traceback_parm_keep(array('upload', 'item'));
         $OutBuf .= "<script type='text/javascript'>\n        function addArsGo(formid, selectid)\n        {\n          var selectobj = document.getElementById(selectid);\n          var Agent_pk = selectobj.options[selectobj.selectedIndex].value;\n          document.getElementById(formid).action='{$action}'+'&agent='+Agent_pk;\n          document.getElementById(formid).submit();\n          return;\n        }\n      </script>";
         $OutBuf .= "<form action=\"{$action}\" id=\"newds\" method=\"POST\">{$AgentSelect}</form>";
     }
     $selectKey = $filter == 'nolic' ? 'nolic' : 'all';
     $OutBuf .= "<select name='view_filter' id='view_filter' onchange='ChangeFilter(this,{$uploadId}, {$item});'>";
     foreach (array('all' => _("Show all"), 'nolic' => _("Show files without licenses")) as $key => $text) {
         $selected = $selectKey == $key ? "selected" : "";
         $OutBuf .= "<option {$selected} value=\"{$key}\">{$text}</option>";
     }
     $OutBuf .= "</select>";
     $uri = preg_replace("/&item=([0-9]*)/", "", Traceback());
     list($tables, $tableVars) = $this->ShowUploadHist($uploadId, $item, $uri, $selectKey, $uploadtree_tablename, $agentId);
     $this->vars['tables'] = $tableVars;
     $this->vars['pageContent'] = $OutBuf . $tables;
     $this->vars['scriptBlock'] = $this->createScriptBlock();
     return;
 }
Beispiel #6
0
 /**
  * \brief Display the package info associated with
  * the rpm/debian package.
  */
 function ShowPackageInfo($Upload, $Item, $ShowMenu = 0)
 {
     global $PG_CONN;
     $V = "";
     $Require = "";
     $MIMETYPE = "";
     $Count = 0;
     $rpm_info = array("Package" => "pkg_name", "Alias" => "pkg_alias", "Architecture" => "pkg_arch", "Version" => "version", "License" => "license", "Group" => "pkg_group", "Packager" => "packager", "Release" => "release", "BuildDate" => "build_date", "Vendor" => "vendor", "URL" => "url", "Summary" => "summary", "Description" => "description", "Source" => "source_rpm");
     $deb_binary_info = array("Package" => "pkg_name", "Architecture" => "pkg_arch", "Version" => "version", "Section" => "section", "Priority" => "priority", "Installed Size" => "installed_size", "Maintainer" => "maintainer", "Homepage" => "homepage", "Source" => "source", "Summary" => "summary", "Description" => "description");
     $deb_source_info = array("Format" => "format", "Source" => "source", "Binary" => "pkg_name", "Architecture" => "pkg_arch", "Version" => "version", "Maintainer" => "maintainer", "Uploaders" => "uploaders", "Standards-Version" => "standards_version");
     if (empty($Item) || empty($Upload)) {
         return;
     }
     /**********************************
        Check if pkgagent disabled
        ***********************************/
     $sql = "SELECT agent_enabled FROM agent WHERE agent_name ='pkgagent' order by agent_ts LIMIT 1;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     pg_free_result($result);
     if (isset($row) && $row['agent_enabled'] == 'f') {
         return;
     }
     /**********************************
        Display package info
        **********************************/
     $text = _("Package Info");
     $V .= "<H2>{$text}</H2>\n";
     /* If pkgagent_ars table didn't exists, don't show the result. */
     $sql = "SELECT typlen  FROM pg_type where typname='pkgagent_ars' limit 1;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $numrows = pg_num_rows($result);
     pg_free_result($result);
     if ($numrows <= 0) {
         $V .= _("No data available. Use Jobs > Agents to schedule a pkgagent scan.");
         return $V;
     }
     /* If pkgagent_ars table didn't have record for this upload, don't show the result. */
     $agent_status = AgentARSList('pkgagent_ars', $Upload);
     if (empty($agent_status)) {
         /** schedule pkgagent */
         $V .= ActiveHTTPscript("Schedule");
         $V .= "<script language='javascript'>\n";
         $V .= "function Schedule_Reply()\n";
         $V .= "  {\n";
         $V .= "  if ((Schedule.readyState==4) && (Schedule.status==200))\n";
         $V .= "    document.getElementById('msgdiv').innerHTML = Schedule.responseText;\n";
         $V .= "  }\n";
         $V .= "</script>\n";
         $V .= "<form name='formy' method='post'>\n";
         $V .= "<div id='msgdiv'>\n";
         $V .= _("No data available.");
         $V .= "<input type='button' name='scheduleAgent' value='Schedule Agent'";
         $V .= "onClick='Schedule_Get(\"" . Traceback_uri() . "?mod=schedule_agent&upload={$Upload}&agent=agent_pkgagent \")'>\n";
         $V .= "</input>";
         $V .= "</div> \n";
         $V .= "</form>\n";
         return $V;
     }
     $sql = "SELECT mimetype_name\n        FROM uploadtree\n        INNER JOIN pfile ON uploadtree_pk = {$Item}\n        AND pfile_fk = pfile_pk\n        INNER JOIN mimetype ON pfile_mimetypefk = mimetype_pk;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     while ($row = pg_fetch_assoc($result)) {
         if (!empty($row['mimetype_name'])) {
             $MIMETYPE = $row['mimetype_name'];
         }
     }
     pg_free_result($result);
     /** RPM Package Info **/
     if ($MIMETYPE == "application/x-rpm") {
         $sql = "SELECT *\n                FROM pkg_rpm\n                INNER JOIN uploadtree ON uploadtree_pk = {$Item}\n                AND uploadtree.pfile_fk = pkg_rpm.pfile_fk;";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $R = pg_fetch_assoc($result);
         if (!empty($R['source_rpm']) and trim($R['source_rpm']) != "(none)") {
             $V .= _("RPM Binary Package");
         } else {
             $V .= _("RPM Source Package");
         }
         $Count = 1;
         $V .= "<table border='1' name='pkginfo'>\n";
         $text = _("Item");
         $text1 = _("Type");
         $text2 = _("Value");
         $V .= "<tr><th width='5%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n";
         if (!empty($R['pkg_pk'])) {
             $Require = $R['pkg_pk'];
             foreach ($rpm_info as $key => $value) {
                 $text = _($key);
                 $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                 $V .= "</td><td>" . htmlentities($R["{$value}"]) . "</td></tr>\n";
                 $Count++;
             }
             pg_free_result($result);
             $sql = "SELECT * FROM pkg_rpm_req WHERE pkg_fk = {$Require};";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) {
                 $text = _("Requires");
                 $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                 $Val = htmlentities($R['req_value']);
                 $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i", "<a href='\$1'>\$1</a>", $Val);
                 $V .= "</td><td>{$Val}</td></tr>\n";
                 $Count++;
             }
             pg_free_result($result);
         }
         $V .= "</table>\n";
         $Count--;
     } else {
         if ($MIMETYPE == "application/x-debian-package") {
             $V .= _("Debian Binary Package\n");
             $sql = "SELECT *\n                FROM pkg_deb\n                INNER JOIN uploadtree ON uploadtree_pk = {$Item}\n                AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             $Count = 1;
             $V .= "<table border='1'>\n";
             $text = _("Item");
             $text1 = _("Type");
             $text2 = _("Value");
             $V .= "<tr><th width='5%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n";
             if (pg_num_rows($result)) {
                 $R = pg_fetch_assoc($result);
                 $Require = $R['pkg_pk'];
                 foreach ($deb_binary_info as $key => $value) {
                     $text = _($key);
                     $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                     $V .= "</td><td>" . htmlentities($R["{$value}"]) . "</td></tr>\n";
                     $Count++;
                 }
                 pg_free_result($result);
                 $sql = "SELECT * FROM pkg_deb_req WHERE pkg_fk = {$Require};";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) {
                     $text = _("Depends");
                     $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                     $Val = htmlentities($R['req_value']);
                     $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i", "<a href='\$1'>\$1</a>", $Val);
                     $V .= "</td><td>{$Val}</td></tr>\n";
                     $Count++;
                 }
                 pg_free_result($result);
             }
             $V .= "</table>\n";
             $Count--;
         } else {
             if ($MIMETYPE == "application/x-debian-source") {
                 $V .= _("Debian Source Package\n");
                 $sql = "SELECT *\n                FROM pkg_deb\n                INNER JOIN uploadtree ON uploadtree_pk = {$Item}\n                AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 $Count = 1;
                 $V .= "<table border='1'>\n";
                 $text = _("Item");
                 $text1 = _("Type");
                 $text2 = _("Value");
                 $V .= "<tr><th width='5%'>{$text}</th><th width='20%'>{$text1}</th><th>{$text2}</th></tr>\n";
                 if (pg_num_rows($result)) {
                     $R = pg_fetch_assoc($result);
                     $Require = $R['pkg_pk'];
                     foreach ($deb_source_info as $key => $value) {
                         $text = _($key);
                         $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                         $V .= "</td><td>" . htmlentities($R["{$value}"]) . "</td></tr>\n";
                         $Count++;
                     }
                     pg_free_result($result);
                     $sql = "SELECT * FROM pkg_deb_req WHERE pkg_fk = {$Require};";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) {
                         $text = _("Build-Depends");
                         $V .= "<tr><td align='right'>{$Count}</td><td>{$text}";
                         $Val = htmlentities($R['req_value']);
                         $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i", "<a href='\$1'>\$1</a>", $Val);
                         $V .= "</td><td>{$Val}</td></tr>\n";
                         $Count++;
                     }
                     pg_free_result($result);
                 }
                 $V .= "</table>\n";
                 $Count--;
             } else {
                 /* Not a package */
                 return "";
             }
         }
     }
     return $V;
 }
 /**
  * \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 Generate the text for this plugin.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /* If this is a POST, then process the request. */
             $Folder = GetParm('folder', PARM_INTEGER);
             if (empty($Folder)) {
                 $Folder = FolderGetTop();
             }
             $uploadpk = GetParm('upload', PARM_INTEGER);
             if (array_key_exists('agents', $_REQUEST)) {
                 $agents = $_POST['agents'];
             } else {
                 $agents = '';
             }
             if (!empty($uploadpk) && !empty($agents) && is_array($agents)) {
                 $rc = $this->AgentsAdd($uploadpk, $agents);
                 if (empty($rc)) {
                     $URL = Traceback_uri() . "?mod=showjobs&upload={$uploadpk} ";
                     /* Need to refresh the screen */
                     $text = _("Your jobs have been added to job queue.");
                     $LinkText = _("View Jobs");
                     $msg = "{$text} <a href={$URL}>{$LinkText}</a>";
                     $V .= displayMessage($msg);
                 } else {
                     $text = _("Scheduling of Agent(s) failed: ");
                     $V .= displayMessage($text . $rc);
                 }
             }
             /**
              * Create the AJAX (Active HTTP) javascript for doing the reply
              * and showing the response. 
              */
             $V .= ActiveHTTPscript("Uploads");
             $V .= "<script language='javascript'>\n";
             $V .= "function Uploads_Reply()\n";
             $V .= "  {\n";
             $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
             $V .= "    {\n";
             /* Remove all options */
             $V .= "    document.getElementById('uploaddiv').innerHTML = '<select size=\\'10\\' name=\\'upload\\' onChange=\\'Agents_Get(\"" . Traceback_uri() . "?mod=upload_agent_options&upload=\" + this.value)\\'>' + Uploads.responseText + '</select><P />';\n";
             //$V .= "alert(document.getElementById('uploaddiv').innerHTML)\n";
             $V .= "    document.getElementById('agentsdiv').innerHTML = '';\n";
             /* Add new options */
             $V .= "    }\n";
             $V .= "  }\n";
             $V .= "</script>\n";
             $V .= ActiveHTTPscript("Agents");
             $V .= "<script language='javascript'>\n";
             $V .= "function Agents_Reply()\n";
             $V .= "  {\n";
             $V .= "  if ((Agents.readyState==4) && (Agents.status==200))\n";
             $V .= "    {\n";
             /* Remove all options */
             $V .= "    document.getElementById('agentsdiv').innerHTML = '<select multiple size=\\'10\\' id=\\'agents\\' name=\\'agents[]\\'>' + Agents.responseText + '</select>';\n";
             /* Add new options */
             $V .= "    }\n";
             $V .= "  }\n";
             $V .= "</script>\n";
             /*************************************************************/
             /* Display the form */
             $V .= "<form name='formy' method='post'>\n";
             // no url = this url
             $V .= _("Select an uploaded file for additional analysis.\n");
             $V .= "<ol>\n";
             $text = _("Select the folder containing the upload you wish to analyze:");
             $V .= "<li>{$text}<br>\n";
             $V .= "<select name='folder'\n";
             $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder={$Folder}' ";
             $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
             $V .= FolderListOption(-1, 0, 1, $Folder);
             $V .= "</select><P />\n";
             $text = _("Select the upload to analyze:");
             $V .= "<li>{$text}<br>";
             $V .= "<div id='uploaddiv'>\n";
             $V .= "<select size='10' name='upload' onChange='Agents_Get(\"" . Traceback_uri() . "?mod=upload_agent_options&upload=\" + this.value)'>\n";
             $List = FolderListUploads_perm($Folder, PERM_WRITE);
             foreach ($List as $L) {
                 $V .= "<option value='" . $L['upload_pk'] . "'>";
                 $V .= htmlentities($L['name']);
                 if (!empty($L['upload_desc'])) {
                     $V .= " (" . htmlentities($L['upload_desc']) . ")";
                 }
                 $V .= "</option>\n";
             }
             $V .= "</select><P />\n";
             $V .= "</div>\n";
             $text = _("Select additional analysis.");
             $V .= "<li>{$text}<br>\n";
             $V .= "<div id='agentsdiv'>\n";
             $V .= "<select multiple size='10' id='agents' name='agents[]'></select>\n";
             $V .= "</div>\n";
             $V .= "</ol>\n";
             $text = _("Analyze");
             $V .= "<input type='submit' value='{$text}!'>\n";
             $V .= "</form>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
 /**
  * \brief output the scheduler admin UI
  **/
 function Output()
 {
     global $Plugins;
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $status_msg = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             $this->operation_array = array("status" => array(_("Status"), _("Display job or scheduler status.")), "database" => array(_("Check job queue"), _("Check for new jobs.")), "reload" => array(_("Reload"), _("Reload fossology.conf.")), "agents" => array(_("Agents"), _("Show a list of enabled agents.")), "verbose" => array(_("Verbose"), _("Change the verbosity level of the scheduler or a job.")), "stop" => array(_("Shutdown Scheduler"), _("Shutdown the scheduler gracefully and stop all background processing.  This can take a while for all the agents to quit.")), "restart" => array(_("Unpause a job"), _("Unpause a job.")), "pause" => array(_("Pause a running job"), _("Pause a running job.")), "priority" => array(_("Priority"), _("Change the priority of a job.")));
             $operation = GetParm('operation', PARM_TEXT);
             $job_id = GetParm('job_list', PARM_TEXT);
             $priority_id = GetParm('priority_list', PARM_TEXT);
             $level_id = GetParm('level_list', PARM_TEXT);
             if (!empty($operation)) {
                 $report = "";
                 $response_from_scheduler = $this->OperationSubmit($operation, $job_id, $priority_id, $level_id);
                 $operation_text = $this->GetOperationText($operation);
                 if (empty($this->error_info)) {
                     $text = _("successfully");
                     $status_msg .= "{$operation_text} {$text}.";
                     if (!empty($response_from_scheduler)) {
                         $report .= "<hr style='border-style:dashed'>";
                         /* add one dashed line */
                         $report .= $response_from_scheduler;
                     }
                 } else {
                     $text = _("failed");
                     $status_msg .= "{$operation_text} {$text}.";
                     $report .= $this->error_info;
                 }
                 echo displayMessage($status_msg, $report);
             }
             $text = _("List of operations:");
             $V .= $text;
             $V .= "<ul>";
             foreach ($this->operation_array as $value) {
                 $V .= "<li><b>{$value['0']}</b>: {$value['1']}</li>";
             }
             $V .= "</ul>";
             $V .= "<hr>";
             $text = _("Select an operation");
             $V .= "<form id='operation_form' method='post'>";
             $V .= "<p><li>{$text}: ";
             $V .= "<select name='operation' id='operation' onchange='OperationSwich_Get(\"" . Traceback_uri() . "?mod=ajax_admin_scheduler&operation=\"+this.value)'<br />\n";
             $V .= $this->OperationListOption();
             $V .= "</select>\n";
             $V .= "<br><br>";
             $V .= "<div id='div_operation'>";
             $text = _("Select the scheduler or a job");
             $V .= "{$text}: <select name='job_list' id='job_list'>";
             $V .= $this->JobListOption('status');
             $V .= "</select>";
             $V .= "</div>";
             $V .= "<hr>";
             $text = _("Submit");
             $V .= "<input type='submit' value='{$text}' />\n";
             $V .= "</form>";
             $choice = ActiveHTTPscript("OperationSwich");
             $choice .= "<script language='javascript'>\n\n        function OperationSwich_Reply()\n\n        {\n\n          if ((OperationSwich.readyState==4) && (OperationSwich.status==200)) \n\n          {\n\n            document.getElementById('div_operation').innerHTML = OperationSwich.responseText;\n\n          }\n\n        }\n\n        </script>\n";
             $V .= $choice;
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Beispiel #10
0
 /**
  * \brief Display the ajax page.
  */
 function ShowAjaxPage()
 {
     $VA = "";
     /* Create AJAX javascript */
     $VA .= ActiveHTTPscript("Tags");
     $VA .= "<script language='javascript'>\n";
     $VA .= "var swtemp=0,objtemp;\n";
     $VA .= "function mouseout(o){\n";
     $VA .= "     o.style.display = \"none\";\n";
     $VA .= "     swtemp = 0;\n";
     $VA .= "}\n";
     $VA .= "function removediv(inputid){\n";
     $VA .= "     getobj(inputid+\"mydiv\").style.display=\"none\";\n";
     $VA .= "}\n";
     $VA .= "function creatediv(_parent,_element,_id,_css){\n";
     $VA .= "     var newObj = document.createElement(_element);\n";
     $VA .= "     if(_id && _id!=\"\")newObj.id=_id;\n";
     $VA .= "     if(_css && _css!=\"\"){\n";
     $VA .= "             newObj.setAttribute(\"style\",_css);\n";
     $VA .= "             newObj.style.cssText = _css;\n";
     $VA .= "     }\n";
     $VA .= "     if(_parent && _parent!=\"\"){\n";
     $VA .= "             var theObj=getobj(_parent);\n";
     $VA .= "             var parent = theObj.parentNode;\n";
     $VA .= "             if(parent.lastChild == theObj){\n";
     $VA .= "                     theObj.appendChild(newObj);\n";
     $VA .= "             }\n";
     $VA .= "             else{\n";
     $VA .= "                     theObj.insertBefore(newObj, theObj.nextSibling);\n";
     $VA .= "             }\n";
     $VA .= "     }\n";
     $VA .= "     else        document.body.appendChild(newObj);\n";
     $VA .= "}\n";
     $VA .= "function getobj(o){\n";
     $VA .= "     return document.getElementById(o);\n";
     $VA .= "}\n";
     $VA .= "function Tags_Reply()\n";
     $VA .= "{\n";
     $VA .= "  if ((Tags.readyState==4) && (Tags.status==200))\n";
     $VA .= "  {\n";
     $VA .= "    var list = Tags.responseText;\n";
     $VA .= "    var text_list = list.split(\",\")\n";
     $VA .= "    var inputid = getobj(\"tag_name\");\n";
     $VA .= "    if (swtemp==1){getobj(objtemp+\"mydiv\").style.display=\"none\";}\n";
     $VA .= "    if (!getobj(inputid+\"mydiv\") && list!=\"\"){\n";
     $VA .= "        var divcss=\"width:240px;font-size:12px;position:absolute;left:\"+(inputid.offsetLeft+0)+\"px;top:\"+(inputid.offsetTop+23)+\"px;border:1px solid\";\n";
     $VA .= "        creatediv(\"\",\"div\",inputid+\"mydiv\",divcss);\n";
     $VA .= "        for (var i=0;i<text_list.length-1;i++){\n";
     $VA .= "            creatediv(inputid+\"mydiv\",\"li\",inputid+\"li\"+i,\"color:#000;background:#fff;list-style-type:none;padding:9px;margin:0;CURSOR:pointer\");\n";
     $VA .= "            getobj(inputid+\"li\"+i).innerHTML=text_list[i];\n";
     $VA .= "            getobj(inputid+\"li\"+i).onmouseover=function(){this.style.background=\"#eee\";}\n";
     $VA .= "            getobj(inputid+\"li\"+i).onmouseout=function(){this.style.background=\"#fff\"}\n";
     $VA .= "            getobj(inputid+\"li\"+i).onclick=function(){\n";
     $VA .= "                                                        inputid.value=this.innerHTML;\n";
     $VA .= "                                                        removediv(inputid);\n";
     $VA .= "                                                       }\n";
     $VA .= "        }\n";
     $VA .= "    }\n";
     $VA .= "    var newdiv=getobj(inputid+\"mydiv\");\n";
     //$VA .= "    newdiv.onclick=function(){removediv(inputid);}\n";
     $VA .= "    document.body.onclick = function(){removediv(inputid);}\n";
     $VA .= "    newdiv.onblur=function(){mouseout(this);}\n";
     $VA .= "    newdiv.style.display=\"block\";\n";
     $VA .= "    swtemp=1;\n";
     $VA .= "    objtemp=inputid;\n";
     $VA .= "    newdiv.focus();\n";
     $VA .= "  }\n";
     $VA .= "}\n;";
     $VA .= "</script>\n";
     return $VA;
 }
 public function Output()
 {
     $V = "";
     $upload_id = GetParm('upload', PARM_INTEGER);
     $manage = GetParm('manage', PARM_TEXT);
     /* If this is a POST, then process the request. */
     $Folder = GetParm('folder', PARM_INTEGER);
     if (empty($Folder)) {
         $Folder = FolderGetTop();
     }
     $rc = $this->ManageTag($Folder, $upload_id, $manage);
     if (1 == $rc) {
         $text1 = _("all uploads in folder");
         $text2 = _("in folder");
         $folder_path = FolderGetName($Folder);
         $upload_name = GetUploadName($upload_id);
         if (empty($upload_id)) {
             $text = $text1;
         } else {
             $text = "'{$upload_name}' {$text2}";
         }
         $Msg = "{$manage} {$text} '{$folder_path}'";
         $this->vars['message'] = $Msg;
         // reset form fields
     }
     /**
      * Create the AJAX (Active HTTP) javascript for doing the reply
      * and showing the response.
      * get upload list under one folder
      */
     $V .= ActiveHTTPscript("Uploads");
     $V .= "<script language='javascript'>\n";
     $V .= "function Uploads_Reply()\n";
     $V .= "  {\n";
     $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
     $V .= "    {\n";
     $V .= "    document.getElementById('tagdiv').innerHTML = '<select size=\\'10\\' name=\\'upload\\' onChange=\\'Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)\\'>' + Uploads.responseText+ '</select><P/>';\n";
     $V .= "    document.getElementById('manage_tag').style.display= 'none';\n";
     $V .= "    document.getElementById('manage_tag_all').style.display= 'block';\n";
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     /** select one upload */
     $V .= ActiveHTTPscript("Tagging");
     $V .= "<script language='javascript'>\n";
     $V .= "function Tagging_Reply()\n";
     $V .= "  {\n";
     $V .= "  if ((Tagging.readyState==4) && (Tagging.status==200))\n";
     $V .= "    {\n";
     $V .= "    document.getElementById('manage_tag_all').style.display= 'none';\n";
     $V .= "    document.getElementById('manage_tag').style.display= 'block';\n";
     $V .= "    document.getElementById('manage_tag').innerHTML = Tagging.responseText;\n";
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     $V .= "<form name='formy' method='post'>\n";
     // no url = this url
     $V .= _("Displaying tags while browsing can be slow for large uploads.  This interface allows you to select an upload to disable (or enable) the tag display.  By default the tag display is enabled.<p>\n");
     $V .= "<ol>\n";
     $text = _("Select the folder containing the upload you wish to enable/disable:");
     $V .= "<li>{$text}<br>\n";
     $V .= "<select name='folder'\n";
     $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder={$Folder}' ";
     $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
     $V .= FolderListOption(-1, 0, 1, $Folder);
     $V .= "</select><P />\n";
     $text = _("Select the upload to  enable/disable:");
     $V .= "<li>{$text}<br>";
     $V .= "<div id='tagdiv'>\n";
     $V .= "<select size='10' name='upload' onChange='Tagging_Get(\"" . Traceback_uri() . "?mod=upload_tagging&upload=\" + this.value)'>\n";
     $List = FolderListUploads_perm($Folder, Auth::PERM_WRITE);
     foreach ($List as $L) {
         $V .= "<option value='" . $L['upload_pk'] . "'>";
         $V .= htmlentities($L['name']);
         if (!empty($L['upload_desc'])) {
             $V .= " (" . htmlentities($L['upload_desc']) . ")";
         }
         $V .= "</option>\n";
     }
     $V .= "</select><P />\n";
     $V .= "</div>\n";
     $V .= "<div id='manage_tag_all'>";
     $text = _("Disable");
     $V .= "<input type='submit' name='manage'  value='{$text}'>\n";
     $text = _("Enable");
     $V .= "<input type='submit' name='manage' value='{$text}'>\n";
     $V .= "</div>";
     $V .= "<div id='manage_tag'>";
     $V .= "</div>";
     return $V;
 }
/**
 * SelectBucketDataset
 * \brief Return a select list showing all the successful bucket
 *        runs on a particular $upload_pk.
 *        This list can be included in UI's to let the user select
 *        which data they wish to view.
 *        The most recent results are the default selection.
 *
 * \param string $upload_pk
 * \param string &$ars_pk    return ars_pk of the selected element, may be zero
 *                           if there are no data.  This is also used to pass in
 *                           the selected ars_pk.
 * \param string $id         HTML element id
 * \param string $extra      Extra info for the select element, e.g. "onclick=..."
 *
 * \return select string, select value is $ars_pk
 *         If there are no rows to select, $ars_pk is returned 0
 *         and a simple string $NoData is returned;
 *         If there are only 1 row, an empty string is returned, and $ars_pk is
 *         set to that row.
 */
function SelectBucketDataset($upload_pk, &$ars_pk, $id = "selectbucketdataset", $extra = "")
{
    global $PG_CONN;
    /** schedule bucket */
    $NoData = ActiveHTTPscript("Schedule");
    $NoData .= "<script language='javascript'>\n";
    $NoData .= "function Schedule_Reply()\n";
    $NoData .= "  {\n";
    $NoData .= "  if ((Schedule.readyState==4) && (Schedule.status==200))\n";
    $NoData .= "    document.getElementById('msgdiv').innerHTML = Schedule.responseText;\n";
    $NoData .= "  }\n";
    $NoData .= "</script>\n";
    $NoData .= "<form name='formy' method='post'>\n";
    $NoData .= "<div id='msgdiv'>\n";
    $NoData .= _("No data available.");
    $NoData .= "<input type='button' name='scheduleAgent' value='Schedule Agent'";
    $NoData .= "onClick='Schedule_Get(\"" . Traceback_uri() . "?mod=schedule_agent&upload={$upload_pk}&agent=agent_bucket \")'>\n";
    $NoData .= "</input>";
    $NoData .= "</div> \n";
    $NoData .= "</form>\n";
    $name = $id;
    $select = "<select name='{$name}' id='{$id}' {$extra}>";
    /* get the bucketpool recs */
    $sql = "select ars_pk, bucketpool_pk, bucketpool_name, version from bucketpool, bucket_ars where active='Y' and bucketpool_fk=bucketpool_pk and ars_success=True and upload_fk='{$upload_pk}' order by ars_starttime desc";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $NumRows = pg_num_rows($result);
    if ($NumRows == 0) {
        return $NoData;
    }
    $rows = pg_fetch_all($result);
    pg_free_result($result);
    if ($NumRows == 1) {
        $ars_pk = $rows[0]['ars_pk'];
        return "";
        /* only one row */
    }
    /* Find the users default_bucketpool_fk */
    $sql = "select default_bucketpool_fk from users where user_pk='{$_SESSION['UserId']}'";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    $DefaultBucketpool_pk = $row['default_bucketpool_fk'];
    pg_free_result($result);
    /* Find the default selected row if ars_pk wasn't passed in */
    if (empty($ars_pk)) {
        foreach ($rows as $row) {
            if ($row['bucketpool_pk'] == $DefaultBucketpool_pk) {
                $ars_pk = $row['ars_pk'];
                break;
            }
        }
        reset($rows);
    }
    //  $select .= "<option value=''";
    foreach ($rows as $row) {
        $select .= "<option value='{$row['ars_pk']}'";
        if (empty($ars_pk)) {
            $select .= " SELECTED ";
            $ars_pk = $row["ars_pk"];
        } else {
            if ($ars_pk == $row['ars_pk']) {
                $select .= " SELECTED ";
            }
        }
        $select .= ">{$row['bucketpool_name']}, v {$row['version']}\n";
    }
    $select .= "</select>";
    return $select;
}
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     global $Plugins;
     global $PG_CONN;
     global $PERM_NAMES;
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             $text = _("Move upload to different folder.");
             $V .= "<H2>{$text}</H1>\n";
             /* If this is a POST, then process the request. */
             $OldFolderId = GetParm('oldfolderid', PARM_INTEGER);
             $UploadId = GetParm('uploadid', PARM_INTEGER);
             $TargetFolderId = GetParm('targetfolderid', PARM_INTEGER);
             if (!empty($OldFolderId) && !empty($TargetFolderId)) {
                 /* check upload permission */
                 $UploadPerm = GetUploadPerm($UploadId);
                 if ($UploadPerm < PERM_WRITE) {
                     $text = _("Permission Denied");
                     echo "<h2>{$text}<h2>";
                     return;
                 }
                 $rc = $this->Move($UploadId, $TargetFolderId, $OldFolderId);
                 if ($rc == 1) {
                     /* Need to refresh the screen */
                     $sql = "SELECT * FROM folder where folder_pk = '{$TargetFolderId}';";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $NRow = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $sql = "SELECT pfile_fk FROM upload WHERE upload_pk='{$UploadId}';";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $row = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $pfileNum = $row['pfile_fk'];
                     $sql = "SELECT ufile_name FROM uploadtree WHERE " . "upload_fk='{$UploadId}' and pfile_fk={$pfileNum};";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $row = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $base = basename($row['ufile_name']);
                     $sql = "SELECT * FROM folder where folder_pk = '{$OldFolderId}';";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     $ORow = pg_fetch_assoc($result);
                     pg_free_result($result);
                     $text = _("Moved");
                     $text1 = _("from folder");
                     $text2 = _("to folder");
                     $success = "{$text} {$base} {$text1} {$ORow['folder_name']} {$text2} {$NRow['folder_name']}";
                     $V .= displayMessage($success);
                 }
             }
             /* Create the AJAX (Active HTTP) javascript for doing the reply
                and showing the response. */
             $V .= ActiveHTTPscript("Uploads");
             $V .= "<script language='javascript'>\n";
             $V .= "function Uploads_Reply()\n";
             $V .= "  {\n";
             $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
             $V .= "    {\n";
             /* Remove all options */
             $V .= "    document.getElementById('uploaddiv').innerHTML = '<select name=\\'uploadid\\'>' + Uploads.responseText + '</select><P />';\n";
             /* Add new options */
             $V .= "    }\n";
             $V .= "  }\n";
             $V .= "</script>\n";
             /* Build the  HTML form */
             $V .= "<form name='formy' method='post'>\n";
             // no url = this url
             /* Display the form */
             $V .= "<form method='post'>\n";
             // no url = this url
             $V .= "<ol>\n";
             $text = _("Select the folder containing the upload you wish to move:  \n");
             $V .= "<li>{$text}";
             $V .= "<select name='oldfolderid'\n";
             $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=-1' ";
             $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
             $root_folder_pk = GetUserRootFolder();
             $V .= FolderListOption($root_folder_pk, 0);
             $V .= "</select><P />\n";
             $text = _("Select the upload you wish to move:  \n");
             $V .= "<li>{$text}";
             $V .= "<div id='uploaddiv'>\n";
             $V .= "<select name='uploadid'>\n";
             $List = FolderListUploads_perm($root_folder_pk, PERM_WRITE);
             foreach ($List as $L) {
                 $V .= "<option value='" . $L['upload_pk'] . "'>";
                 $V .= htmlentities($L['name']);
                 if (!empty($L['upload_desc'])) {
                     $V .= " (" . htmlentities($L['upload_desc']) . ")";
                 }
                 if (!empty($L['upload_ts'])) {
                     $V .= " :: " . substr($L['upload_ts'], 0, 19);
                 }
                 $V .= "</option>\n";
             }
             $V .= "</select><P />\n";
             $V .= "</div>\n";
             $text = _("Select the destination folder:  \n");
             $V .= "<li>{$text}";
             $V .= "<select name='targetfolderid'>\n";
             $V .= FolderListOption($root_folder_pk, 0);
             $V .= "</select><P />\n";
             $V .= "</ol>\n";
             $text = "Move";
             $V .= "<input type='submit' value='{$text}!'>\n";
             $V .= "</form>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }