Ejemplo n.º 1
0
 /**
  * \brief test for MenuPage()
  */
 function test_MenuPage()
 {
     print "Starting unit test for common-menu.php\n";
     print "test function MenuPage()\n";
     $Page = 10;
     $TotalPage = 15;
     $Uri = "http://fossology.org/repo/";
     $expected = "<a href='http:\\/\\/fossology.org\\/repo\\/&page=9'>\\[Prev\\]<\\/a>";
     $result = MenuPage($Page, $TotalPage, $Uri);
     $this->assertRegExp("/<b>11<\\/b>/", $result);
     $this->assertRegExp("/{$expected}/", $result);
 }
Ejemplo n.º 2
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     global $PG_CONN;
     // make sure there is a db connection
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     $OutBuf = "";
     $Time = microtime(true);
     $Max = 50;
     /*  Input parameters */
     $agent_pk = GetParm("agent", PARM_INTEGER);
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     $hash = GetParm("hash", PARM_RAW);
     $type = GetParm("type", PARM_RAW);
     $excl = GetParm("excl", PARM_RAW);
     $filter = GetParm("filter", PARM_RAW);
     if (empty($uploadtree_pk) || empty($hash) || empty($type) || empty($agent_pk)) {
         $this->vars['pageContent'] = $this->Name . _("is missing required parameters");
         return;
     }
     /* Check item1 and item2 upload permissions */
     $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}");
     $UploadPerm = GetUploadPerm($Row['upload_fk']);
     if ($UploadPerm < Auth::PERM_READ) {
         $this->vars['pageContent'] = "<h2>" . _("Permission Denied") . "</h2>";
         return;
     }
     $Page = GetParm("page", PARM_INTEGER);
     if (empty($Page)) {
         $Page = 0;
     }
     list($tableName, $modBack, $viewName) = $this->getTableName($type);
     /* get all rows */
     $upload_pk = -1;
     $rows = $this->GetRows($uploadtree_pk, $agent_pk, $upload_pk, $hash, $type, $tableName);
     /* Get uploadtree_tablename */
     $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
     /* slim down to all rows with this hash and type,  and filter */
     $NumInstances = 0;
     $rows = $this->GetRequestedRows($rows, $excl, $NumInstances, $filter);
     // micro menus
     $OutBuf .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0);
     $RowCount = count($rows);
     if ($RowCount) {
         $Content = htmlentities($rows[0]['content']);
         $Offset = $Page < 0 ? 0 : $Page * $Max;
         $PkgsOnly = false;
         $text = _("files");
         $text1 = _("unique");
         $text3 = _("copyright");
         $text4 = _("email");
         $text5 = _("url");
         switch ($type) {
             case "statement":
                 $TypeStr = "{$text3}";
                 break;
             case "email":
                 $TypeStr = "{$text4}";
                 break;
             case "url":
                 $TypeStr = "{$text5}";
                 break;
             case "ecc":
                 $TypeStr = _("export restriction");
                 break;
         }
         $OutBuf .= "{$NumInstances} {$TypeStr} instances found in {$RowCount}  {$text}";
         $OutBuf .= ": <b>{$Content}</b>";
         $text = _("Display excludes files with these extensions");
         if (!empty($excl)) {
             $OutBuf .= "<br>{$text}: {$excl}";
         }
         /* Get the page menu */
         if ($RowCount >= $Max && $Page >= 0) {
             $PagingMenu = "<P />\n" . MenuPage($Page, intval(($RowCount + $Offset) / $Max)) . "<P />\n";
             $OutBuf .= $PagingMenu;
         } else {
             $PagingMenu = "";
         }
         /* Offset is +1 to start numbering from 1 instead of zero */
         $LinkLast = "{$viewName}&agent={$agent_pk}";
         $ShowBox = 1;
         $ShowMicro = NULL;
         $baseURL = "?mod=" . $this->Name . "&agent={$agent_pk}&item={$uploadtree_pk}&hash={$hash}&type={$type}&page=-1";
         // display rows
         $RowNum = 0;
         foreach ($rows as $row) {
             ++$RowNum;
             if ($RowNum < $Offset) {
                 continue;
             }
             // Allow user to exclude files with this extension
             $FileExt = GetFileExt($row['ufile_name']);
             if (empty($excl)) {
                 $URL = $baseURL . "&excl={$FileExt}";
             } else {
                 $URL = $baseURL . "&excl={$excl}:{$FileExt}";
             }
             $text = _("Exclude this file type");
             $Header = "<a href={$URL}>{$text}.</a>";
             $ok = true;
             if ($excl) {
                 $ExclArray = explode(":", $excl);
                 if (in_array($FileExt, $ExclArray)) {
                     $ok = false;
                 }
             }
             if ($ok) {
                 $OutBuf .= Dir2Browse($modBack, $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, $RowNum, $Header, '', $uploadtree_tablename);
             }
         }
     } else {
         $OutBuf .= _("No files found");
     }
     if (!empty($PagingMenu)) {
         $OutBuf .= $PagingMenu . "\n";
     }
     $OutBuf .= "<hr>\n";
     $Time = microtime(true) - $Time;
     $text = _("Elapsed time");
     $text1 = _("seconds");
     $OutBuf .= sprintf("<small>{$text}: %.2f {$text1}</small>\n", $Time);
     $this->vars['pageContent'] = $OutBuf;
     return;
 }
Ejemplo n.º 3
0
<?php

include 'phplib/prepend.php';
page_open(array("sess" => $_ENV["SessionClass"], "auth" => $_ENV["AuthClass"], "perm" => $_ENV["PermClass"]));
MenuPage($MenuId);
page_close();