<?
require_once("conf/config.php");

        echo "<script type=\"text/javascript\">";
        if(isset($_FILES["user_file"])) {
            $p = pathinfo($_FILES["user_file"]["name"]);
            $newName = $_REQUEST["user_id"]."_".$_REQUEST["wid"]."_".time().".".$p["extension"];
            if(move_uploaded_file($_FILES["user_file"]["tmp_name"], "var/tmp/".$newName)) {
                echo "parent.kernel.getWidget(".$_REQUEST["wid"].").importFromUrl(\"".$newName."\");";
            } else {
                echo "parent.kernel.getWidget(".$_REQUEST["wid"].").importFromUrl(null);";
            }
        } else {
            echo "parent.kernel.getWidget(".$_REQUEST["wid"].").importError();";
        }
        echo "</script>";
?>