<?php

    
require("functions.php");

    
$res XMLtoArray(file_get_contents("projects.xml")) or die("Unable to read the projects xml file.");

    
$id $_GET['id'];
    
$item null;

    if (!empty(
$id))
    {
        for (
$i 0$i count($res['PROJECTS']['PROJECT']); $i++)
        {
            
$thisitem $res['PROJECTS']['PROJECT'][$i];

            if (
$thisitem['ID'] == $id)
            {
                
$item $thisitem;
                break;
            }
        }
    }

?>
<!DOCTYPE html>
<html lang="en"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="JaviteSoft - Open source and code examples">
    <meta name="author" content="JaviteSoft">

    <title>JaviteSoft - Projects<?php if ($item != null) { echo " - $item[TITLE]"; } ?></title>

    <!-- Bootstrap core CSS -->
    <link href="css/bootstrap.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <link href="css/global.css" rel="stylesheet">
    <link rel="icon" href="favicon.ico">
    <link rel="apple-touch-icon" href="apple-touch-icon.png"/>
    <link rel="apple-touch-icon-precomposed" href="apple-touch-icon.png"/>
  </head>

  <body>

    <a name="top"></a>
    <div class="main-masthead fixed-nav-bar">
      <div class="container">
        <nav class="main-nav">
          <a class="main-nav-item" href="index.php">Home</a>
          <a class="main-nav-item active" href="projects.php" title="View the projects in development">Projects</a>
          <a class="main-nav-item" href="snippets.php" title="View the code snippets library">Snippets</a>
          <a class="main-nav-item" href="depends.php" title="Download any dependencies required">Dependencies</a>
          <a class="main-nav-item" href="contact.php" title="Contact JaviteSoft">Contact</a>
          <a class="main-nav-item" href="about.php" title="About JaviteSoft">About</a>
        </nav>
      </div>
    </div>

    <div class="container">

      <div class="main-header">
        <h1 class="main-title">Projects</h1>
        <p class="lead main-description">Find all our projects in development below.
          <br>All source code is GNU General Public License (GPL)</p>
      </div>

      <div class="row">

        <div class="col-sm-8 main-main">

<?php

    $base_path 
"/homepages/19/d91351804/htdocs/download/projects/sources/";
    
$viewable_file_exts = array('bas','cfg','cls','cpp','cs','ctl','def','dsp','dsw','frm','h','htm','html','ini',
        
'log','myapp','plg','rc','resx','sample','settings','sln','csproj','txt','user','vb','vbp','vbproj','xml');
    
$image_file_exts = array('bmp','gif','ico','jpg','jpeg','png');

    if (!empty(
$id))
    {
        if (
$item != null)
        {
            
$file null;
            
$filepath '';

            foreach (
$item['SOURCES'] as $key1 => $val1)
            {
                foreach (
$val1['FILE'] as $key2 => $val2)
                {
                    
$file $val2;
                    break;
                }
                break;
            }

            if (!
is_null($file)) $filepath $base_path basename($file['URL']);

            print <<<END_OF_HTML

          <div class="main-post"><a name="
$item[ID]"></a>
            <h2 class="main-post-title">
$item[TITLE]</h2>
            <p class="main-post-meta">
$item[CREATED] by <a href="contact.php">Java</a></p>

END_OF_HTML;

            if (
file_exists($filepath))
            {
                
$zip zip_open($filepath);

                if (
is_resource($zip))
                {  
                    
$selected $_GET['file'];

                    if (empty(
$selected))
                    {
                        echo 
"<p>Browsing <a href=\"$file[URL]\">" basename($file['URL']) . "</a></p>";
                        echo 
'<pre><code>';

                        while (
$zip_entry zip_read($zip))
                        {
                            if (
zip_entry_filesize($zip_entry) > 0)
                                echo 
"<a href=\"browse.php?id=$id&file=" urlencode(zip_entry_name($zip_entry)) . "\">" zip_entry_name($zip_entry) . "</a> <small>(" format_bytes(zip_entry_filesize($zip_entry)) . ")</small>\r\n";
                        }

                        echo 
'</code></pre>';
                        echo 
"<p><a href=\"$file[URL]\">Download " basename($file['URL']) . "</a></p>";
                    }
                    else
                    {
                        
$found false;

                        while (
$zip_entry zip_read($zip))
                        {
                           if (
$selected == zip_entry_name($zip_entry))
                           {
                               
$found true;
                               break;
                           }
                        }

                        if (
$found)
                        {
                            
$filename zip_entry_name($zip_entry);

                            echo 
"<p>Browsing <a href=\"file.php?id=$id&file=" urlencode($filename) . "\">" $filename "</a> <small>(" format_bytes(zip_entry_filesize($zip_entry)) . ")</small></p>";
                            echo 
'<pre><code>';

                            
$path_parts pathinfo($filename);

                            if (
in_array($path_parts['extension'], $viewable_file_exts))
                            {
                                if (
zip_entry_open($zip$zip_entry"r"))
                                {
                                    
$buff1 zip_entry_read($zip_entryzip_entry_filesize($zip_entry));
                                    
$buff2 htmlspecialchars($buff1);

                                    if (!empty(
$buff2)) echo $buff2;
                                    else echo 
$buff1;

                                    
zip_entry_close($zip_entry);
                                }
                                else
                                {
                                    echo 
"Unable to display file contents.";
                                }
                            }
                            else if (
in_array($path_parts['extension'], $image_file_exts))
                            {
                                echo 
"<img src=\"file.php?id=$id&file=" urlencode($filename) . "\" alt=\"$filename\" />";
                            }
                            else
                            {
                                echo 
"Unable to display file contents.";
                            }

                            echo 
'</code></pre>';
                            echo 
"<p><a href=\"file.php?id=$id&file=" urlencode($filename) . "\">Download " $filename "</a></p>";
                        }
                        else
                        {
                            echo 
'<p>File not found.</p>';
                        }

                        echo 
"<p><a href=\"browse.php?id=$id\">Back to file list</a></p>";
                    }

                    
zip_close($zip);
                }
            }
            else
            {
                echo 
'<p>File not found.</p>';
            }

            print <<<END_OF_HTML

            <hr>
            <p><a href="projects.php?
$id">Back to project page</a></p>

          </div><!-- /.main-post -->
        </div><!-- /.main-main -->

        <div class="col-sm-3 col-sm-offset-1 main-sidebar">

          <div class="sidebar-module">
            <h4>Downloads</h4>
            <ol class="list-unstyled">
              <li><hr></li>
              <li style="border-bottom: 1px solid black;">Binaries</li>

END_OF_HTML;

            foreach (
$item['BINARIES'] as $key1 => $val1)
            {
                foreach (
$val1['FILE'] as $key2 => $val2)
                {
                    
$file $val2;

                    print <<<END_OF_HTML

              <li><br><ul><li><h4>
$file[VERSION]</h4><small>$file[RELEASED]</small><br><a href="$file[URL]">$file[NAME]</a></li></ul></li>
              <li><hr></li>

END_OF_HTML;
                }
                break;
            }

            print <<<END_OF_HTML

              <li style="border-bottom: 1px solid black;">Sources</li>

END_OF_HTML;

            foreach (
$item['SOURCES'] as $key1 => $val1)
            {
                foreach (
$val1['FILE'] as $key2 => $val2)
                {
                    
$file $val2;

                    print <<<END_OF_HTML

              <li><br><ul><li><h4>
$file[VERSION]</h4><small>$file[RELEASED]</small><br><a href="$file[URL]">$file[NAME]</a></li></ul></li>
              <li><hr></li>

END_OF_HTML;
                }
                break;
            }

            print <<<END_OF_HTML

            </ol>
          </div>

        </div><!-- /.main-sidebar -->

END_OF_HTML;

        }
        else
        {
            print <<<END_OF_HTML

          <div class="main-post">
            <h2 class="main-post-title">Project not found</h2>
            <p>The project you are looking for is no longer available.</p>
            <hr>
            <p><a href="projects.php">Back to Projects page</a></p>

          </div><!-- /.main-post -->
        </div><!-- /.main-main -->

END_OF_HTML;

        }
    }
    else
    {
        print <<<END_OF_HTML

          <div class="main-post">
            <h2 class="main-post-title">Project not found</h2>
            <p>The project you are looking for is no longer available.</p>
            <hr>
            <p><a href="projects.php">Back to Projects page</a></p>

          </div><!-- /.main-post -->
        </div><!-- /.main-main -->

END_OF_HTML;

    }

?>
      </div><!-- /.row -->

    </div><!-- /.container -->

    <footer class="main-footer">
      <p>Copyright &copy; 2015 JaviteSoft. All Rights Reserved.</p>
      <p>
        <a href="#top">Back to top</a>
      </p>
      <p>
        <a href="browse.phps"><small>View page source</small></a>
      </p>
    </footer>


    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="js/ie10-viewport-bug-workaround.js"></script>
    <!-- Fix for local page links -->
    <script src="js/fix_anchors.js"></script>
  
</body>
</html>