if ($arrfile['name']) {
            $filename = iconv("UTF-8", $target_encoding, basename($arrfile['name']));
            $filename = str_replace('\\', '', $filename);
            $filename = str_replace('/', '', $filename);
            // delete  file if it exists
            while (file_exists($dest . $filename)) {
                unlink($dest . $filename);
                $filename = "new_" . $filename;
            }
            // save the file
            if (!move_uploaded_file($arrfile['tmp_name'], $dest . $filename)) {
                $message = "Upload {$filename} failed.<br/>";
            } else {
                $ext = substr(strrchr($filename, '.'), 1);
                StaticAsset::createStaticAsset($save, $filename, $ext);
                $location = ViewUrl::getViewUrl($save);
                if ($location) {
                    header("location: view.php?location=" . $location);
                } else {
                    header("location: view.php");
                }
            }
        }
    }
}
//get default value for the textarea (either from selecting an item in the history, or from the current active record)
$name = empty($save) ? $_GET['name'] : $save;
if ($_GET['init']) {
    $row = StaticAsset::getStaticAssetById($_GET['init']);
} else {
    $row = StaticAsset::getStaticAssetByName($name);
    // save assets
    $index = 0;
    $assetArray = StructuredFieldAsset::getAssets($save);
    if ($assetArray) {
        foreach ($assetArray as $asset) {
            if ($storedfile[$index]) {
                $asset[2] = $storedfile[$index];
                $asset[3] = $ext[$index];
            }
            StructuredFieldAsset::updateAsset($asset[0], $asset[2], $_POST['asset' . $index], $asset[3]);
            $index++;
        }
    }
    // redirect if needed
    if ($_POST['submitAndView']) {
        $location = ViewUrl::getViewUrl($name);
        if ($location) {
            header("location: view.php?location=" . $location);
        } else {
            header("location: view.php");
        }
    }
    $init = $save;
    $name = $_POST['name'];
    $message .= "The record has been updated";
} else {
    $init = $_GET['init'];
    $name = $_GET['name'];
}
// create a new record
$new = $_GET['new'];
if (!swValidate('s_username')) {
    header("location: ../index.php");
}
connect();
$type = $_POST["type"];
$name = $_POST["name"];
$id = $_POST["id"];
$url = $_POST["url"];
if ($type) {
    switch ($type) {
        case 'getViewUrl':
            $result = ViewUrl::getViewUrl($name);
            break;
        case 'setViewUrl':
            ViewUrl::setViewUrl($name, $url);
            $result = "URL set:" . ViewUrl::getViewUrl($name);
            break;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>simple CMS - unit test</title>
<link rel="shortcut icon" href="../images/favicon.ico" />

</head>
<body>
<form method="post" action="<?php 
echo $_SERVER['PHP_SELF'];