PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/fileman/admin/fileman_newfolder.php

https://gitlab.com/alexprowars/bitrix
PHP | 302 lines | 275 code | 26 blank | 1 comment | 49 complexity | 858f6dc110ca0c2b7d102b21fa7c200b MD5 | raw file
  1. <?
  2. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. if (!$USER->CanDoOperation('fileman_admin_folders'))
  4. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  5. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/include.php");
  6. IncludeModuleLangFile(__FILE__);
  7. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/prolog.php");
  8. $io = CBXVirtualIo::GetInstance();
  9. $addUrl = 'lang='.LANGUAGE_ID.($logical == "Y"?'&logical=Y':'');
  10. $strWarning = "";
  11. $strNotice = "";
  12. $site = CFileMan::__CheckSite($site);
  13. $DOC_ROOT = CSite::GetSiteDocRoot($site);
  14. $path = $io->CombinePath("/", $path);
  15. $arPath = Array($site, $path);
  16. if (!$USER->CanDoFileOperation('fm_create_new_folder',$arPath))
  17. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  18. $arParsedPath = CFileMan::ParsePath(Array($site, $path), true, false, "", $logical == "Y");
  19. $abs_path = $DOC_ROOT.$path;
  20. $module_id = "fileman";
  21. $bMenuTypeExists = false;
  22. $arMenuTypes = Array();
  23. $armt = GetMenuTypes($site);
  24. foreach($armt as $key => $title)
  25. {
  26. if(!$USER->CanDoFileOperation('fm_edit_existent_file',Array($site, $path."/.".$key.".menu.php")))
  27. continue;
  28. $arMenuTypes[] = array($key, $title);
  29. if($key == $menutype)
  30. $bMenuTypeExists = true;
  31. }
  32. //check folder access
  33. if (!$USER->CanDoFileOperation('fm_create_new_folder',$arPath))
  34. $strWarning = '<img src="/bitrix/images/fileman/deny.gif" width="28" height="28" border="0" align="left" alt="">'.GetMessage("ACCESS_DENIED");
  35. else if(!$io->DirectoryExists($abs_path))
  36. $strWarning = GetMessage("FILEMAN_FOLDER_NOT_FOUND");
  37. else
  38. {
  39. if($REQUEST_METHOD=="POST" && $save <> '' && check_bitrix_sessid())
  40. {
  41. if($foldername == '')
  42. {
  43. $strWarning = GetMessage("FILEMAN_NEWFOLDER_ENTER_NAME");
  44. }
  45. elseif (($mess = CFileMan::CheckFileName($foldername)) !== true)
  46. {
  47. $strWarning = $mess;
  48. }
  49. else
  50. {
  51. $pathto = $io->CombinePath("/", $path, $foldername);
  52. if($io->FileExists($DOC_ROOT.$pathto) || $io->DirectoryExists($DOC_ROOT.$pathto))
  53. {
  54. $strWarning = GetMessage("FILEMAN_NEWFOLDER_EXISTS");
  55. }
  56. else
  57. {
  58. $strWarning = CFileMan::CreateDir(Array($site, $pathto));
  59. if($strWarning == '')
  60. {
  61. if($USER->CanDoFileOperation('fm_add_to_menu',$arPath) &&
  62. $USER->CanDoOperation('fileman_add_element_to_menu') &&
  63. $mkmenu=="Y" && $bMenuTypeExists)
  64. {
  65. $arParsedPathTmp = CFileMan::ParsePath(Array($site, $pathto), true, false, "", $logical == "Y");
  66. $menu_path = $arParsedPathTmp["PREV"]."/.".$menutype.".menu.php";
  67. if($USER->CanDoFileOperation('fm_view_file',Array($site, $menu_path)))
  68. {
  69. $res = CFileMan::GetMenuArray($DOC_ROOT.$menu_path);
  70. $aMenuLinksTmp = $res["aMenuLinks"];
  71. $sMenuTemplateTmp = $res["sMenuTemplate"];
  72. $aMenuLinksTmp[] = Array($menuname, $arParsedPathTmp["PREV"]."/".$arParsedPathTmp["LAST"]."/", Array(), Array(), "");
  73. CFileMan::SaveMenu(Array($site, $menu_path), $aMenuLinksTmp, $sMenuTemplateTmp);
  74. if(COption::GetOptionString($module_id, "log_menu", "Y")=="Y")
  75. {
  76. $mt = COption::GetOptionString("fileman", "menutypes", $default_value, $site);
  77. $mt = unserialize(str_replace("\\", "", $mt), ['allowed_classes' => false]);
  78. $res_log['menu_name'] = $mt[$menutype];
  79. $res_log['path'] = mb_substr($path, 1);
  80. CEventLog::Log(
  81. "content",
  82. "MENU_EDIT",
  83. "fileman",
  84. "",
  85. serialize($res_log)
  86. );
  87. }
  88. }
  89. }
  90. if($sectionname <> '')
  91. {
  92. if(COption::GetOptionString($module_id, "log_page", "Y")=="Y")
  93. {
  94. $res_log['path'] = mb_substr($pathto, 1);
  95. CEventLog::Log(
  96. "content",
  97. "SECTION_ADD",
  98. "fileman",
  99. "",
  100. serialize($res_log)
  101. );
  102. }
  103. $APPLICATION->SaveFileContent($DOC_ROOT.$pathto."/.section.php", "<?\n\$sSectionName=\"".CFileMan::EscapePHPString($sectionname)."\";\n?>");
  104. }
  105. if ($e = $APPLICATION->GetException())
  106. $strNotice = $e->msg;
  107. else
  108. {
  109. if($USER->CanDoFileOperation('fm_create_new_file',$arPath) &&
  110. $USER->CanDoOperation('fileman_admin_files') &&
  111. $mkindex=="Y")
  112. {
  113. if($toedit=="Y")
  114. 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)));
  115. else
  116. $APPLICATION->SaveFileContent($DOC_ROOT.$pathto."/index.php", CFileman::GetTemplateContent($template));
  117. }
  118. }
  119. if ($e = $APPLICATION->GetException())
  120. $strNotice = $e->msg;
  121. elseif ($apply == '' && $strNotice == '')
  122. {
  123. if($back_url <> '')
  124. LocalRedirect("/".ltrim($back_url, "/"));
  125. else
  126. {
  127. $arPathtoParsed = CFileMan::ParsePath(Array($site, $pathto), false, false, "", $logical == "Y");
  128. LocalRedirect("/bitrix/admin/fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($arPathtoParsed["PREV"]));
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. else
  136. {
  137. $mkindex="Y";
  138. $toedit="Y";
  139. }
  140. }
  141. foreach ($arParsedPath["AR_PATH"] as $chainLevel)
  142. {
  143. $adminChain->AddItem(
  144. array(
  145. "TEXT" => htmlspecialcharsex($chainLevel["TITLE"]),
  146. "LINK" => (($chainLevel["LINK"] <> '') ? $chainLevel["LINK"] : ""),
  147. )
  148. );
  149. }
  150. $APPLICATION->SetTitle(GetMessage("FILEMAN_NEW_FOLDER_TITLE"));
  151. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  152. if($strWarning == '')
  153. $filename = $arParsedPath["LAST"];
  154. $aMenu = array(
  155. array(
  156. "TEXT" => GetMessage("FILEMAN_BACK"),
  157. "LINK" => "fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($path),
  158. "ICON" => "btn_list"
  159. )
  160. );
  161. $context = new CAdminContextMenu($aMenu);
  162. $context->Show();
  163. ?>
  164. <?CAdminMessage::ShowMessage($strNotice);?>
  165. <?CAdminMessage::ShowMessage($strWarning);?>
  166. <?
  167. if ($USER->CanDoFileOperation('fm_create_new_folder',$arPath))
  168. {
  169. ?>
  170. <form method="POST" action="<?echo $APPLICATION->GetCurPage()?>?" name="fnew_folder">
  171. <input type="hidden" name="logical" value="<?=htmlspecialcharsex($logical)?>">
  172. <?echo GetFilterHiddens("filter_");?>
  173. <input type="hidden" name="site" value="<?= htmlspecialcharsex($site) ?>">
  174. <input type="hidden" name="path" value="<?= htmlspecialcharsex($path) ?>">
  175. <input type="hidden" name="save" value="Y">
  176. <input type="hidden" name="back_url" value="<?= htmlspecialcharsex($back_url)?>">
  177. <input type="hidden" name="lang" value="<?=LANG ?>">
  178. <input type="hidden" name="ID" value="<?= htmlspecialcharsex($ID)?>">
  179. <input type="hidden" id="bxfm_linked" name="bxfm_linked" value="Y" />
  180. <?if($gotonewpage=="Y"):?><input type="hidden" name="gotonewpage" value="Y"><?endif?>
  181. <?if($backnewurl=="Y"):?><input type="hidden" name="backnewurl" value="Y"><?endif?>
  182. <?=bitrix_sessid_post()?>
  183. <?
  184. $aTabs = array(
  185. array("DIV" => "edit1", "TAB" => GetMessage("FILEMAN_TAB1"), "ICON" => "fileman", "TITLE" => GetMessage("FILEMAN_TAB1_ALT")),
  186. );
  187. $tabControl = new CAdminTabControl("tabControl", $aTabs);
  188. $tabControl->Begin();
  189. $tabControl->BeginNextTab();
  190. $site_template = false;
  191. $rsSiteTemplates = CSite::GetTemplateList($site);
  192. while($arSiteTemplate = $rsSiteTemplates->Fetch())
  193. {
  194. if($arSiteTemplate["CONDITION"] == '')
  195. {
  196. $site_template = $arSiteTemplate["TEMPLATE"];
  197. break;
  198. }
  199. }
  200. $arTemplates = CFileman::GetFileTemplates(LANGUAGE_ID, array($site_template));
  201. ?>
  202. <tr>
  203. <td><label for="bxfm_sectionname" style="font-weight: bold;"><?=GetMessage("FILEMAN_NEWFOLDER_SEACTION_NAME")?></label></td>
  204. <td><input type="text" id="bxfm_sectionname" name="sectionname" value="<?=htmlspecialcharsex($sectionname)?>" size="30" maxlength="255"></td>
  205. </tr>
  206. <tr>
  207. <td width="40%"><label for="bxfm_foldername" style="font-weight: bold;"><?=GetMessage("FILEMAN_NEWFOLDER_NAME")?></label></td>
  208. <td width="60%"><input id="bxfm_foldername" type="text" name="foldername" value="<?=htmlspecialcharsex($foldername)?>" size="30" maxlength="255"></td>
  209. </tr>
  210. <?if($USER->CanDoFileOperation('fm_add_to_menu',$arPath) && $USER->CanDoOperation('fileman_add_element_to_menu') ):?>
  211. <tr>
  212. <td><?=GetMessage("FILEMAN_NEWFOLDER_ADDMENU")?></td>
  213. <td><input type="checkbox" name="mkmenu" value="Y"<?if($mkmenu=="Y")echo " checked"?> onclick="document.fnew_folder.menuname.disabled=!this.checked;document.fnew_folder.menutype.disabled=!this.checked;if(this.checked && document.fnew_folder.sectionname.value.length!='' && document.fnew_folder.menuname.value=='') document.fnew_folder.menuname.value=document.fnew_folder.sectionname.value;fx1.disabled=!this.checked;fx2.disabled=!this.checked;"></td>
  214. </tr>
  215. <tr id="fx1"<?if($mkmenu!="Y")echo " disabled"?>>
  216. <td><?=GetMessage("FILEMAN_NEWFOLDER_MENU")?></td>
  217. <td>
  218. <select name="menutype" <?if($mkmenu!="Y")echo " disabled"?>>
  219. <?for($i = 0, $l = count($arMenuTypes); $i < $l; $i++):?>
  220. <option value="<?echo htmlspecialcharsex($arMenuTypes[$i][0])?>" <?if($menutype==$arMenuTypes[$i][0])echo " selected"?>><?echo htmlspecialcharsex("[".$arMenuTypes[$i][0]."] ".$arMenuTypes[$i][1])?></option>
  221. <?endfor;?>
  222. </select>
  223. </td>
  224. </tr>
  225. <tr id="fx2"<?if($mkmenu!="Y")echo " disabled"?>>
  226. <td><?=GetMessage("FILEMAN_NEWFOLDER_MENUITEM")?></td>
  227. <td><input type="text" name="menuname" value="<?echo htmlspecialcharsex($menuname)?>"<?if($mkmenu!="Y")echo " disabled"?>></td>
  228. </tr>
  229. <?endif;?>
  230. <?if($USER->CanDoFileOperation('fm_create_new_file',$arPath) && $USER->CanDoOperation('fileman_admin_files')):?>
  231. <tr>
  232. <td><?=GetMessage("FILEMAN_NEWFOLDER_MAKE_INDEX")?></td>
  233. <td><input type="checkbox" name="mkindex" value="Y"<?if($mkindex=="Y")echo " checked"?> onclick="document.fnew_folder.toedit.disabled=!this.checked;document.fnew_folder.template.disabled=!this.checked;ff1.disabled=!this.checked;ff2.disabled=!this.checked;"></td>
  234. </tr>
  235. <tr id="ff1">
  236. <td><?=GetMessage("FILEMAN_NEWFOLDER_INDEX_TEMPLATE")?></td>
  237. <td>
  238. <select name="template" <?if($mkindex!="Y")echo " disabled"?>>
  239. <?for($i = 0, $l = count($arTemplates); $i < $l; $i++):?>
  240. <option value="<?echo htmlspecialcharsex($arTemplates[$i]["file"])?>"<?if($template==$arTemplates[$i]["file"])echo " selected"?>><?echo htmlspecialcharsex($arTemplates[$i]["name"])?></option>
  241. <?endfor;?>
  242. </select>
  243. </td>
  244. </tr>
  245. <tr id="ff2">
  246. <td><?=GetMessage("FILEMAN_NEWFOLDER_INDEX_EDIT")?></td>
  247. <td><input type="checkbox" name="toedit" value="Y"<?if($toedit=="Y")echo " checked"?><?if($mkindex!="Y")echo " disabled"?>></td>
  248. </tr>
  249. <?endif;?>
  250. <?
  251. $tabControl->EndTab();
  252. $tabControl->Buttons(
  253. array(
  254. "disabled" => false,
  255. "back_url" => ($back_url <> '' ? $back_url : "fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($path))
  256. )
  257. );
  258. $tabControl->End();
  259. if (COption::GetOptionString("fileman", "use_translit", true))
  260. {
  261. include_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/classes/general/fileman_utils.php");
  262. CFilemanTransliterate::Init(array(
  263. 'fromInputId' => 'bxfm_sectionname',
  264. 'toInputId' => 'bxfm_foldername',
  265. 'linkedId' => 'bxfm_linked',
  266. 'linked' => $_REQUEST['bxfm_linked'] != "N",
  267. 'linkedTitle' => GetMessage('FILEMAN_TRANS_LINKED'),
  268. 'unlinkedTitle' => GetMessage('FILEMAN_TRANS_UNLINKED')
  269. ));
  270. }
  271. ?>
  272. </form>
  273. <?
  274. }
  275. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");
  276. ?>