require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
if (!$USER->CanDoOperation('fileman_admin_folders'))
$APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/include.php");
IncludeModuleLangFile(__FILE__);
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/prolog.php");
$io = CBXVirtualIo::GetInstance();
$addUrl = 'lang='.LANGUAGE_ID.($logical == "Y"?'&logical=Y':'');
$strWarning = "";
$strNotice = "";
$site = CFileMan::__CheckSite($site);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
$path = $io->CombinePath("/", $path);
$arPath = Array($site, $path);
if (!$USER->CanDoFileOperation('fm_create_new_folder',$arPath))
$APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
$arParsedPath = CFileMan::ParsePath(Array($site, $path), true, false, "", $logical == "Y");
$abs_path = $DOC_ROOT.$path;
$module_id = "fileman";
$bMenuTypeExists = false;
$arMenuTypes = Array();
$armt = GetMenuTypes($site);
foreach($armt as $key => $title)
{
if(!$USER->CanDoFileOperation('fm_edit_existent_file',Array($site, $path."/.".$key.".menu.php")))
continue;
$arMenuTypes[] = array($key, $title);
if($key == $menutype)
$bMenuTypeExists = true;
}
//check folder access
if (!$USER->CanDoFileOperation('fm_create_new_folder',$arPath))
$strWarning = ''.GetMessage("ACCESS_DENIED");
else if(!$io->DirectoryExists($abs_path))
$strWarning = GetMessage("FILEMAN_FOLDER_NOT_FOUND");
else
{
if($REQUEST_METHOD=="POST" && $save <> '' && check_bitrix_sessid())
{
if($foldername == '')
{
$strWarning = GetMessage("FILEMAN_NEWFOLDER_ENTER_NAME");
}
elseif (($mess = CFileMan::CheckFileName($foldername)) !== true)
{
$strWarning = $mess;
}
else
{
$pathto = $io->CombinePath("/", $path, $foldername);
if($io->FileExists($DOC_ROOT.$pathto) || $io->DirectoryExists($DOC_ROOT.$pathto))
{
$strWarning = GetMessage("FILEMAN_NEWFOLDER_EXISTS");
}
else
{
$strWarning = CFileMan::CreateDir(Array($site, $pathto));
if($strWarning == '')
{
if($USER->CanDoFileOperation('fm_add_to_menu',$arPath) &&
$USER->CanDoOperation('fileman_add_element_to_menu') &&
$mkmenu=="Y" && $bMenuTypeExists)
{
$arParsedPathTmp = CFileMan::ParsePath(Array($site, $pathto), true, false, "", $logical == "Y");
$menu_path = $arParsedPathTmp["PREV"]."/.".$menutype.".menu.php";
if($USER->CanDoFileOperation('fm_view_file',Array($site, $menu_path)))
{
$res = CFileMan::GetMenuArray($DOC_ROOT.$menu_path);
$aMenuLinksTmp = $res["aMenuLinks"];
$sMenuTemplateTmp = $res["sMenuTemplate"];
$aMenuLinksTmp[] = Array($menuname, $arParsedPathTmp["PREV"]."/".$arParsedPathTmp["LAST"]."/", Array(), Array(), "");
CFileMan::SaveMenu(Array($site, $menu_path), $aMenuLinksTmp, $sMenuTemplateTmp);
if(COption::GetOptionString($module_id, "log_menu", "Y")=="Y")
{
$mt = COption::GetOptionString("fileman", "menutypes", $default_value, $site);
$mt = unserialize(str_replace("\\", "", $mt), ['allowed_classes' => false]);
$res_log['menu_name'] = $mt[$menutype];
$res_log['path'] = mb_substr($path, 1);
CEventLog::Log(
"content",
"MENU_EDIT",
"fileman",
"",
serialize($res_log)
);
}
}
}
if($sectionname <> '')
{
if(COption::GetOptionString($module_id, "log_page", "Y")=="Y")
{
$res_log['path'] = mb_substr($pathto, 1);
CEventLog::Log(
"content",
"SECTION_ADD",
"fileman",
"",
serialize($res_log)
);
}
$APPLICATION->SaveFileContent($DOC_ROOT.$pathto."/.section.php", "\n\$sSectionName=\"".CFileMan::EscapePHPString($sectionname)."\";\n?>");
}
if ($e = $APPLICATION->GetException())
$strNotice = $e->msg;
else
{
if($USER->CanDoFileOperation('fm_create_new_file',$arPath) &&
$USER->CanDoOperation('fileman_admin_files') &&
$mkindex=="Y")
{
if($toedit=="Y")
LocalRedirect("/bitrix/admin/fileman_html_edit.php?".$addUrl."&site=".$site."&template=".Urlencode($template)."&path=".UrlEncode($pathto)."&filename=index.php&new=Y".($back_url == '' ?"":"&back_url=".UrlEncode($back_url)).($gotonewpage == ''?"":"&gotonewpage=".UrlEncode($gotonewpage)).($backnewurl == ''?"":"&backnewurl=".UrlEncode($backnewurl)));
else
$APPLICATION->SaveFileContent($DOC_ROOT.$pathto."/index.php", CFileman::GetTemplateContent($template));
}
}
if ($e = $APPLICATION->GetException())
$strNotice = $e->msg;
elseif ($apply == '' && $strNotice == '')
{
if($back_url <> '')
LocalRedirect("/".ltrim($back_url, "/"));
else
{
$arPathtoParsed = CFileMan::ParsePath(Array($site, $pathto), false, false, "", $logical == "Y");
LocalRedirect("/bitrix/admin/fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($arPathtoParsed["PREV"]));
}
}
}
}
}
}
else
{
$mkindex="Y";
$toedit="Y";
}
}
foreach ($arParsedPath["AR_PATH"] as $chainLevel)
{
$adminChain->AddItem(
array(
"TEXT" => htmlspecialcharsex($chainLevel["TITLE"]),
"LINK" => (($chainLevel["LINK"] <> '') ? $chainLevel["LINK"] : ""),
)
);
}
$APPLICATION->SetTitle(GetMessage("FILEMAN_NEW_FOLDER_TITLE"));
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
if($strWarning == '')
$filename = $arParsedPath["LAST"];
$aMenu = array(
array(
"TEXT" => GetMessage("FILEMAN_BACK"),
"LINK" => "fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($path),
"ICON" => "btn_list"
)
);
$context = new CAdminContextMenu($aMenu);
$context->Show();
?>
if ($USER->CanDoFileOperation('fm_create_new_folder',$arPath))
{
?>