File "create.php"
Full Path: /home/analogde/www/filetypes/create.php
File size: 4.98 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/***************************************************************
* Copyright notice
*
* (c) 2003-2004 Tobias Bender (tobias@phpXplorer.org)
* All rights reserved
*
* This script is part of the phpXplorer project. The phpXplorer project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt distributed with these scripts.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
require(dirname(__FILE__) . "/defaultActionHead.php");
$fileName = getRequestVar("fileName");
$submitAction = getRequestVar("submitAction");
$submitOverwrite = getRequestVar("submitOverwrite");
# check for url manipulation
if(!(strpos($fileName, "..") === FALSE))
die($PXP_languages[$PXP_language]['accessDenied'] . " (804)");
$extension = $TP_extensions[basename(dirname($HTTP_SERVER_VARS["PHP_SELF"]))][0];
if(strpos($fileName, "." . $extension) === FALSE)
$fileName = $fileName . "." . $extension;
$pInfo = checkFilePermissions($fileName);
if(!$pInfo["allowOpen"] or !$pInfo["allowEdit"])
die($PXP_languages[$PXP_language]["accessDenied"] . " (809)");
if($submitAction != ""){
$bCreateFile = false;
$n = strpos($fileName, "." . $extension) === FALSE ? $currentDir . "/" . $fileName . "." . $extension : $currentDir . "/" . $fileName;
if(file_exists($n)){
if($submitOverwrite == ""){
$submitOverwrite = "overwrite";
}else{
if($submitOverwrite == "overwriteConfirm")
$bCreateFile = true;
}
}else{
$bCreateFile = true;
}
if($bCreateFile){
if(file_exists("./default.txt")){
copy("./default.txt", $n);
}else{
$handle = fopen($n, "w");
fclose($handle);
}
}
}
?>
<html>
<head>
<title>
<?php echo $PXP_languages[$PXP_language]["createFile"] ?>
</title>
<style type="text/css">
<!--
-->
</style>
<link rel="stylesheet" type="text/css" href="<?php echo $PXP_url ?>/styles/<?php echo $PXP_style ?>/main.css"/>
<script language="JavaScript" type="text/javascript">
<!--
function validate(){
var f = document.frm1
if(!f.fileName.value != ""){
alert("<?php echo $PXP_languages[$PXP_language]['pleaseInsertValue'] ?>")
f.fileName.focus()
return false
}
return true
}
function send(a, overwrite){
if(!validate())
return false
switchButton()
var f = document.frm1
f.submitAction.value = a
if(overwrite)
f.submitOverwrite.value = "overwriteConfirm"
f.submit()
}
function switchButton(){
var f = document.frm1
f.btnCreate.disabled = !f.btnCreate.disabled
f.btnCreateAndEdit.disabled = !f.btnCreateAndEdit.disabled
f.btnCancel.disabled = !f.btnCancel.disabled
}
function init(){
<?php
if($submitOverwrite == "overwrite"){
echo "if(confirm('" . $PXP_languages[$PXP_language]["allowOverwrite"] . "?')){\r\n";
echo " send('" . $submitAction . "', true)\r\n";
echo "}else{\r\n";
echo " document.frm1.fileName.focus()\r\n";
echo " document.frm1.fileName.select()\r\n";
echo "}\r\n";
}else{
switch($submitAction){
case "create":
echo "opener.refreshDir()\r\n";
echo "window.close()\r\n";
break;
case "createAndEdit":
echo "opener.refreshDir()\r\n";
echo "location.href = './edit.php?currentDir=" . urldecode($currentDir) . "&fileName=$fileName&shareId=$shareId'\r\n";
break;
case "":
echo "document.frm1.fileName.focus()\r\n";
echo "document.frm1.fileName.select()\r\n";
break;
}
}
?>
}
//-->
</script>
</head>
<body onLoad="init()">
<form name="frm1" action="./create.php" method="post" onSubmit="return false">
<input type="hidden" name="currentDir" value="<?php echo $currentDir ?>">
<input type="hidden" name="shareId" value="<?php echo $shareId ?>">
<input type="hidden" name="submitAction" value="<?php echo $submitAction ?>">
<input type="hidden" name="submitOverwrite" value="<?php echo $submitOverwrite ?>">
<?php
echo $PXP_languages[$PXP_language]["createFile"];
if($extension != "")
echo ' ("' . $extension . '")';
?>
<br><br>
<?php echo $PXP_languages[$PXP_language]["name"] ?> <input type="text" name="fileName" size="30" value="<?php echo $fileName ?>">
<br><br>
<input type="button" name="btnCreate" onClick="send('create')" value="<?php echo $PXP_languages[$PXP_language]['create'] ?>">
<input type="button" name="btnCreateAndEdit" onClick="send('createAndEdit')" value="<?php echo $PXP_languages[$PXP_language]['createAndEdit'] ?>">
<input type="button" name="btnCancel" onClick="window.close()" value="<?php echo $PXP_languages[$PXP_language]['cancel'] ?>">
</form>
</body>
</html>