• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/file_dialog.php
  • Класс: CAdminFileDialog
  • Вызов: CAdminFileDialog::Rename
static function Rename($Params)
{
	global $USER, $APPLICATION;

	$path = $site = '';

	if(CModule::IncludeModule("fileman"))
	{
		$io = CBXVirtualIo::GetInstance();
		$path = Rel2Abs("/", $APPLICATION->UnJSEscape($Params['path']));
		$path = CFileMan::SecurePathVar($path);
		$site = $Params['site'];

		$name = str_replace("/", "_", $APPLICATION->UnJSEscape($Params['name']));
		$oldName = str_replace("/", "_", $APPLICATION->UnJSEscape($Params['old_name']));

		$DOC_ROOT = CSite::GetSiteDocRoot($site);

		$oldPath = Rel2Abs($path, $oldName);
		$newPath = Rel2Abs($path, $name);
		$oldAbsPath = $DOC_ROOT.$oldPath;
		$newAbsPath = $DOC_ROOT.$newPath;
		$arPath1 = Array($site, $oldPath);
		$arPath2 = Array($site, $newPath);
		$strWarning = '';

		$type = false;
		if ($io->DirectoryExists($oldAbsPath))
			$type = 'folder';
		if ($io->FileExists($oldAbsPath))
			$type = 'file';

		if (
			$type == 'file' &&
			!$USER->CanDoOperation('edit_php') &&
			(
				mb_substr($oldName, 0, 1) == "."
				||
				mb_substr($name, 0, 1) == "."
				||
				(
					HasScriptExtension($oldName) &&
					!HasScriptExtension($name)
				)
				||
				(
					HasScriptExtension($name) &&
					!HasScriptExtension($oldName)
				)
			)
		)
		{
			$strWarning = GetMessage("ACCESS_DENIED");
		}
		elseif (!$type)
			$strWarning = GetMessage("FD_ELEMENT_NOT_FOUND", array('#PATH#' => addslashes(htmlspecialcharsbx($path))));
		elseif (!$USER->CanDoFileOperation('fm_rename_'.$type,$arPath1) || !$USER->CanDoFileOperation('fm_rename_'.$type,$arPath2))
			$strWarning = GetMessage("ACCESS_DENIED");
		else
		{
			if ($name <> '' && ($mess = self::CheckFileName($name)) !== true)
				$strWarning = $mess;
			else if($name == '')
				$strWarning = GetMessage("FD_ELEMENT_ENTER_NAME");
			else
			{
				if($io->FileExists($DOC_ROOT.$newPath) || $io->DirectoryExists($DOC_ROOT.$newPath))
					$strWarning = GetMessage("FD_ELEMENT_EXISTS");
				elseif(!$io->Rename($oldAbsPath, $newAbsPath))
					$strWarning = GetMessage("FD_RENAME_ERROR");
			}
		}
	}
	else
	{
		$strWarning = GetMessage("BX_FD_NO_FILEMAN");
	}

	self::EchoActionStatus($strWarning);

	if ($strWarning == '')
		self::LoadItems(array('path' => $path, 'site' => $site, 'bAddToMenu' => $Params['bAddToMenu'], 'loadRecursively' => false, 'getFiles' => $Params['getFiles']));
}