<?
$dataToWrite = $str->fromHTML($_POST['fileContent']);
$fileSizeToWrite = strlen($dataToWrite);



if ($permissions['unlimitedSpace']){
	$continueSaving = true;
} else {
	if ($quota->canAddToSpace($fileSizeToWrite)) {
		$continueSaving = true;
	} else {
		$continueSaving = false;
		$tmp['msg'] = $lang->get("You have excedeed your space quota. The text file was not created.");
	}
}


if ($continueSaving) {
	if (file_exists($filepath)) {
		$msg = $lang->get("A file named \"%1\" already exists.", array($sys['filename']));
		$statusBarMessage[] = array($msg, 1);
	} else {
		$js = "";
		if ($fm->newFile($filepath, $dataToWrite)) {
			$log->act("0", "new text file", $filepath);
			//$url = glueURL(array("path"=>$str->safeJS($str->forURL($sys['path']))));
			$js .= "if(window.opener.AfianHandler){window.opener.MyFilesSync(window.opener.AfianHandler['allTabs']['".$_GET['tabid']."']);}";
			$_GET['new'] = "0";
			$msg = $lang->get("New text file created.");
			$statusBarMessage[] = array($msg, 0);
			$showTextFromFile = true;
		} else {
			$msg = $lang->get("Failed to create new text file. System error: %1", array($fm->errorMsg));
			$statusBarMessage[] = array($msg, 1);
		}
	}
} else {
	$msg = $tmp['msg'];
	$statusBarMessage[] = array($msg, 1);
}

?>