        <?php
          $fol = "";
          if (isset($_GET['f'])) $fol = $_GET['f'];

/*         $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];    */
         $url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
         
         
         $n = strripos ($url, '.php');
         if ($n) { 
            $bn = basename ($url);
            $n = strripos ($url, $bn); 
            $from = substr ($url, 0, $n);
            $urlEnc = urlencode ($from);
         }
         else {
            $bn = 'index.php';
            $urlEnc = urlencode ($url);
         }
         
                      
         
         $n = strpos ($bn, '?');
         if ($n) $bn = substr ($bn, 0, $n);   
         
         $imeStiRiza = true;
         if ($fol != '') {
            chdir ($fol);
            $imeStiRiza = false;
         }
         
         if (!$imeStiRiza) {           
            $n = strripos ($fol, '/');
            if ($n) 
               $up = substr ($fol, 0, $n);
            else $up = '';
            $up = urlencode ($up);
            print "<tr><td style = 'background-color: #CCFF00'><a href = '$bn'>TOP</a></td></tr>\n        ";
            print "<tr><td style = 'background-color: #CCFF00'><a href = '$bn?f=$up'>one level UP</a></td></tr>\n        ";
         }
         
         $dir = '.';
         $files = scandir ($dir);  /* αρχεία και φάκελοι */
         foreach ($files as $v)
           if (is_dir ($v) && ($v != ".") && ($v != "..") && ($v != "depo") && ($v != "expl")) {
              $arxio = realpath ($v . "/hotpep.xml");
              if ($arxio) {
                 $fakelos = $v;
                 $dom = new DOMDocument();
                 $dom->load ($arxio);
                 $titlos = $dom->getElementsByTagName ("title")->item(0)->nodeValue;
                 $glosa = $dom->getElementsByTagName ("langa")->item(0)->nodeValue;
                 if ($glosa == '') $glosa = 'Greek?';
                 $senario = $dom->getElementsByTagName ("senario")->item(0)->nodeValue;
                 $quizID = $dom->getElementsByTagName ("id")->item(0)->nodeValue;
                 $ver = '';
                 $quiz = $dom->getElementsByTagName ('quiz')->item(0);
                 if ($quiz->hasAttributes())
                    foreach ($quiz->attributes as $attr) {
                            $name = $attr->nodeName;
                            if ($name == 'ver')
                               $ver = $attr->nodeValue;
                    }
                 if ($ver != '') $ver = '.' . $ver;
                 print "<tr><td>";

                 if ($fol == '')
                      $fakQuiz = $v;
                 else $fakQuiz = $fol . '/' . $v;
                 $bar = urlencode ($fakQuiz);
                 $foo = urlencode ($titlos . " --written by " . $senario);
                 
                 $count_q_dl = $fakelos . "/q_dl.txt";
                 if (file_exists ($count_q_dl)) {
                    $hits = file ($count_q_dl);
                    $ktipimata = $hits[0];
                 }
                 else $ktipimata = '';  
                 $hitsEnc = urlencode ($ktipimata);
                 print "<span style = 'font-size: 1vw'>$glosa</span> <a href = '0.php?t=$bar&amp;r=$foo&amp;u=$urlEnc'>$titlos</a> <span style = 'font-size: 1vw'>$senario</span> <span style = 'font-size: 1vw; color: red'>$fakQuiz</span> <span style = 'font-size: 1vw'>$quizID$ver $hitsEnc</span>";
                 print "</td></tr>\n        ";
              }
              
              /* Κοιτάζω και μέσα στον φάκελο $v αν υπάρχουν υποφάκελοι */
              $newFiles = scandir ($v);
              $subFolderExist = false;                 
              foreach ($newFiles as $vv) {
                      $vvv = $v . '/' . $vv;
                      if (is_dir ($vvv) && ($vv != ".") && ($vv != "..") && ($vv != "depo")) {
                         $subFolderExist = true;
                         break;
                      }
              } 
              if ($subFolderExist) {
                 if ($imeStiRiza) 
                      $directory = $v;
                 else $directory = $fol . '/' . $v;
                 $bar = urlencode ($directory); 
                 $onomaFakelu = $directory;
                 $showDir = '';
                 $arx = realpath ($v . "/name.txt");
                 if ($arx) {
                    $hits = file ($arx);
                    $of = $hits[0];
                    if ($of != '') {
                       $onomaFakelu = $of;
                       $showDir = ' ' . $directory;
                    }
                 }
                 print "<tr><td style = 'background-color: #FFBB00'><a href = '$bn?f=$bar'>" . $onomaFakelu . "</a><span style = 'font-size: 1vw; color: red'>" . $showDir . "</span></td></tr>\n        ";
              }
           }
        ?>