/**
  * \brief test for Isdir Isartifact Iscontainer
  */
 function test_Is()
 {
     print "Starting unit test for common-dir.php\n";
     print "test function Isdir()\n";
     $mode = 536888320;
     $result = Isdir($mode);
     $this->assertEquals(true, $result);
     $mode = 33188;
     $result = Isdir($mode);
     $this->assertEquals(false, $result);
     print "test function Isartifact()\n";
     $mode = 536888320;
     $result = Isartifact($mode);
     $this->assertEquals(false, $result);
     $mode = 805323776;
     $result = Isartifact($mode);
     $this->assertEquals(true, $result);
     print "test function Iscontainer()\n";
     $mode = 536888320;
     $result = Iscontainer($mode);
     $this->assertEquals(true, $result);
     $mode = 805323776;
     $result = Iscontainer($mode);
     $this->assertEquals(true, $result);
     print "test function DirMode2String()\n";
     $result = DirMode2String($mode);
     $this->assertEquals("a-d-----S---", $result);
     //print "Ending unit test for common-dir.php\n";
 }
Example #2
0
 /**
  * \brief Given a upload_pk, list every item in it.
  * If it is an individual file, then list the file contents.
  */
 function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename)
 {
     global $container;
     /** @var DbManager */
     $dbManager = $container->get('db.manager');
     $RowStyle1 = "style='background-color:#ecfaff'";
     // pale blue
     $RowStyle2 = "style='background-color:#ffffe3'";
     // pale yellow
     $ColorSpanRows = 3;
     // Alternate background color every $ColorSpanRows
     $RowNum = 0;
     $V = "";
     /* Use plugin "view" and "download" if they exist. */
     $Uri = Traceback_uri() . "?mod=" . $this->Name . "&folder={$Folder}";
     /* there are three types of Browse-Pfile menus */
     /* menu as defined by their plugins */
     $MenuPfile = menu_find("Browse-Pfile", $MenuDepth);
     /* menu but without Compare */
     $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare");
     /* menu with only Tag and Compare */
     $MenuTag = array();
     foreach ($MenuPfile as $value) {
         if ($value->Name == 'Tag' or $value->Name == 'Compare') {
             $MenuTag[] = $value;
         }
     }
     $Results = GetNonArtifactChildren($Item, $uploadtree_tablename);
     $ShowSomething = 0;
     $V .= "<table class='text' style='border-collapse: collapse' border=0 padding=0>\n";
     $stmtGetFirstChild = __METHOD__ . '.getFirstChild';
     $dbManager->prepare($stmtGetFirstChild, "SELECT uploadtree_pk FROM {$uploadtree_tablename} WHERE parent=\$1 limit 1");
     foreach ($Results as $Row) {
         if (empty($Row['uploadtree_pk'])) {
             continue;
         }
         $ShowSomething = 1;
         $Name = $Row['ufile_name'];
         /* Set alternating row background color - repeats every $ColorSpanRows rows */
         $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2;
         $V .= "<tr {$RowStyle}>";
         /* Check for children so we know if the file should by hyperlinked */
         $result = $dbManager->execute($stmtGetFirstChild, array($Row['uploadtree_pk']));
         $HasChildren = $dbManager->fetchArray($result);
         $dbManager->freeResult($result);
         $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk'];
         $Link = $HasChildren ? "{$Uri}&show={$Show}&upload={$Upload}&item={$Row['uploadtree_pk']}" : NULL;
         if ($Show == 'detail') {
             $V .= "<td class='mono'>" . DirMode2String($Row['ufile_mode']) . "</td>";
             if (!Isdir($Row['ufile_mode'])) {
                 $V .= "<td align='right'>&nbsp;&nbsp;" . number_format($Row['pfile_size'], 0, "", ",") . "&nbsp;&nbsp;</td>";
             } else {
                 $V .= "<td>&nbsp;</td>";
             }
         }
         $displayItem = Isdir($Row['ufile_mode']) ? "{$Name}/" : $Name;
         if (!empty($Link)) {
             $displayItem = "<a href=\"{$Link}\">{$displayItem}</a>";
         }
         if (Iscontainer($Row['ufile_mode'])) {
             $displayItem = "<b>{$displayItem}</b>";
         }
         $V .= "<td>{$displayItem}</td>\n";
         if (!Iscontainer($Row['ufile_mode'])) {
             $V .= menu_to_1list($MenuPfileNoCompare, $Parm, "<td>", "</td>\n", 1, $Upload);
         } else {
             if (!Isdir($Row['ufile_mode'])) {
                 $V .= menu_to_1list($MenuPfile, $Parm, "<td>", "</td>\n", 1, $Upload);
             } else {
                 $V .= menu_to_1list($MenuTag, $Parm, "<td>", "</td>\n", 1, $Upload);
             }
         }
     }
     /* foreach($Results as $Row) */
     $V .= "</table>\n";
     if (!$ShowSomething) {
         $text = _("No files");
         $V .= "<b>{$text}</b>\n";
     } else {
         $V .= "<hr>\n";
         if (count($Results) == 1) {
             $text = _("1 item");
             $V .= "{$text}\n";
         } else {
             $text = _("items");
             $V .= count($Results) . " {$text}\n";
         }
     }
     return $V;
 }
Example #3
0
 /**
  * \brief Given a upload_pk, list every item in it.
  * If it is an individual file, then list the file contents.
  */
 function ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename)
 {
     global $PG_CONN;
     $RowStyle1 = "style='background-color:#ecfaff'";
     // pale blue
     $RowStyle2 = "style='background-color:#ffffe3'";
     // pale yellow
     $ColorSpanRows = 3;
     // Alternate background color every $ColorSpanRows
     $RowNum = 0;
     $V = "";
     /* Use plugin "view" and "download" if they exist. */
     $Uri = Traceback_uri() . "?mod=" . $this->Name . "&folder={$Folder}";
     /* there are three types of Browse-Pfile menus */
     /* menu as defined by their plugins */
     $MenuPfile = menu_find("Browse-Pfile", $MenuDepth);
     /* menu but without Compare */
     $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare");
     /* menu with only Tag and Compare */
     $MenuTag = array();
     foreach ($MenuPfile as $key => $value) {
         if ($value->Name == 'Tag' or $value->Name == 'Compare') {
             $MenuTag[] = $value;
         }
     }
     /* Get the (non artifact) children  */
     $Results = GetNonArtifactChildren($Item, $uploadtree_tablename);
     $ShowSomething = 0;
     $V .= "<table class='text' style='border-collapse: collapse' border=0 padding=0>\n";
     foreach ($Results as $Row) {
         if (empty($Row['uploadtree_pk'])) {
             continue;
         }
         $ShowSomething = 1;
         $Link = NULL;
         $Name = $Row['ufile_name'];
         /* Set alternating row background color - repeats every $ColorSpanRows rows */
         $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2;
         $V .= "<tr {$RowStyle}>";
         /* Check for children so we know if the file should by hyperlinked */
         $sql = "select uploadtree_pk from uploadtree\n                where parent={$Row['uploadtree_pk']} limit 1";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $HasChildren = pg_num_rows($result);
         pg_free_result($result);
         $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk'];
         if ($HasChildren) {
             $Link = $Uri . "&show={$Show}&upload={$Upload}&item=" . $Row['uploadtree_pk'];
         }
         /* Show details children */
         if ($Show == 'detail') {
             $V .= "<td class='mono'>" . DirMode2String($Row['ufile_mode']) . "</td>";
             if (!Isdir($Row['ufile_mode'])) {
                 $V .= "<td align='right'>&nbsp;&nbsp;" . number_format($Row['pfile_size'], 0, "", ",") . "&nbsp;&nbsp;</td>";
             } else {
                 $V .= "<td>&nbsp;</td>";
             }
         }
         /* Display item */
         $V .= "<td>";
         if (Iscontainer($Row['ufile_mode'])) {
             $V .= "<b>";
         }
         if (!empty($Link)) {
             $V .= "<a href='{$Link}'>";
         }
         $V .= $Name;
         if (Isdir($Row['ufile_mode'])) {
             $V .= "/";
         }
         if (!empty($Link)) {
             $V .= "</a>";
         }
         if (Iscontainer($Row['ufile_mode'])) {
             $V .= "</b>";
         }
         $V .= "</td>\n";
         if (!Iscontainer($Row['ufile_mode'])) {
             $V .= menu_to_1list($MenuPfileNoCompare, $Parm, "<td>", "</td>\n", 1, $Upload);
         } else {
             if (!Isdir($Row['ufile_mode'])) {
                 $V .= menu_to_1list($MenuPfile, $Parm, "<td>", "</td>\n", 1, $Upload);
             } else {
                 $V .= menu_to_1list($MenuTag, $Parm, "<td>", "</td>\n", 1, $Upload);
             }
         }
         $V .= "</td>";
     }
     /* foreach($Results as $Row) */
     $V .= "</table>\n";
     if (!$ShowSomething) {
         $text = _("No files");
         $V .= "<b>{$text}</b>\n";
     } else {
         $V .= "<hr>\n";
         if (count($Results) == 1) {
             $text = _("1 item");
             $V .= "{$text}\n";
         } else {
             $text = _("items");
             $V .= count($Results) . " {$text}\n";
         }
     }
     return $V;
 }
 /**
  * \brief test for DirMode2String
  */
 public function test_DirMode2String()
 {
     // print "test function DirMode2String()\n";
     $result = DirMode2String(805323776);
     $this->assertEquals("a-d-----S---", $result);
     $result = DirMode2String(0644);
     $this->assertEquals("---rw-r--r--", $result);
 }