PageRenderTime 50ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/subscribe/admin/template_test.php

https://gitlab.com/alexprowars/bitrix
PHP | 339 lines | 311 code | 20 blank | 8 comment | 26 complexity | 2d833867118bcf75edd8afd82a48a332 MD5 | raw file
  1. <?
  2. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  3. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/subscribe/include.php");
  4. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/subscribe/prolog.php");
  5. IncludeModuleLangFile(__FILE__);
  6. $POST_RIGHT = $APPLICATION->GetGroupRight("subscribe");
  7. if($POST_RIGHT=="D")
  8. $APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
  9. $aTabs = array(
  10. array("DIV" => "edit1", "TAB" => GetMessage("rub_test_tab"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("rub_test_tab_title")),
  11. );
  12. $tabControl = new CAdminTabControl("tabControl", $aTabs);
  13. $ID = intval($ID); // Id of the rubric to test
  14. $arError = array();
  15. $message = null;
  16. $bVarsFromForm = false;
  17. $rubric = false;
  18. $arRubric = false;
  19. $arFieldDescriptions = array(
  20. "ACTIVE" => GetMessage("rub_ACTIVE"),
  21. "AUTO" => GetMessage("rub_AUTO"),
  22. "BODY_TYPE" => GetMessage("rub_BODY_TYPE"),
  23. "CHARSET" => GetMessage("rub_CHARSET"),
  24. "DAYS_OF_MONTH" => GetMessage("rub_DAYS_OF_MONTH"),
  25. "DAYS_OF_WEEK" => GetMessage("rub_DAYS_OF_WEEK"),
  26. "DESCRIPTION" => GetMessage("rub_DESCRIPTION"),
  27. "DIRECT_SEND" => GetMessage("rub_DIRECT_SEND"),
  28. "END_TIME" => GetMessage("rub_END_TIME"),
  29. "FROM_FIELD" => GetMessage("rub_FROM_FIELD"),
  30. "ID" => GetMessage("rub_ID"),
  31. "LAST_EXECUTED" => GetMessage("rub_LAST_EXECUTED"),
  32. "LID" => GetMessage("rub_LID"),
  33. "NAME" => GetMessage("rub_NAME"),
  34. "SITE_ID" => GetMessage("rub_SITE_ID"),
  35. "SORT" => GetMessage("rub_SORT"),
  36. "START_TIME" => GetMessage("rub_START_TIME"),
  37. "SUBJECT" => GetMessage("rub_SUBJECT"),
  38. "TEMPLATE" => GetMessage("rub_TEMPLATE"),
  39. "TIMES_OF_DAY" => GetMessage("rub_TIMES_OF_DAY"),
  40. "VISIBLE" => GetMessage("rub_VISIBLE"),
  41. );
  42. if($ID>0)
  43. {
  44. global $DB;
  45. $rubric = CRubric::GetByID($ID);
  46. if($rubric)
  47. $arRubric = $rubric->Fetch();
  48. if(!$arRubric)
  49. $arError[] = array("id"=>"", "text"=>GetMessage("rub_id_not_found"));
  50. else
  51. {
  52. if($START_TIME=="")
  53. $START_TIME=$arRubric["LAST_EXECUTED"];
  54. if($END_TIME=="")
  55. $END_TIME=ConvertTimeStamp(time()+CTimeZone::GetOffset(), "FULL");
  56. }
  57. }
  58. if($Test <> '' && $POST_RIGHT=="W" && check_bitrix_sessid())
  59. {
  60. if($DB->IsDate($START_TIME, false, false, "FULL")!==true)
  61. $arError[] = array("id"=>"START_TIME", "text"=>GetMessage("rub_wrong_stime"));
  62. if($DB->IsDate($END_TIME, false, false, "FULL")!==true)
  63. $arError[] = array("id"=>"END_TIME", "text"=>GetMessage("rub_wrong_etime"));
  64. $bTest = count($arError) == 0;
  65. }
  66. else
  67. $bTest = false;
  68. $APPLICATION->SetTitle(GetMessage("rub_title").$ID);
  69. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
  70. $aMenu = array(
  71. array(
  72. "TEXT"=>GetMessage("POST_LIST"),
  73. "TITLE"=>GetMessage("rub_list"),
  74. "LINK"=>"rubric_admin.php?lang=".LANG,
  75. "ICON"=>"btn_list",
  76. )
  77. );
  78. if($ID>0)
  79. {
  80. $aMenu[] = array("SEPARATOR"=>"Y");
  81. $aMenu[] = array(
  82. "TEXT"=>GetMessage("MAIN_ADD"),
  83. "TITLE"=>GetMessage("rubric_mnu_add"),
  84. "LINK"=>"rubric_edit.php?lang=".LANG,
  85. "ICON"=>"btn_new",
  86. );
  87. $aMenu[] = array(
  88. "TEXT"=>GetMessage("POST_EDIT"),
  89. "TITLE"=>GetMessage("rubric_mnu_edit"),
  90. "LINK"=>"rubric_edit.php?ID=".$ID."&lang=".LANG
  91. );
  92. $aMenu[] = array(
  93. "TEXT"=>GetMessage("POST_DELETE"),
  94. "TITLE"=>GetMessage("rubric_mnu_del"),
  95. "LINK"=>"javascript:if(confirm('".GetMessage("rubric_mnu_del_conf")."'))window.location='rubric_admin.php?ID=".$ID."&cf=delid&lang=".LANG."&".bitrix_sessid_get()."';",
  96. "ICON"=>"btn_delete",
  97. );
  98. }
  99. $context = new CAdminContextMenu($aMenu);
  100. $context->Show();
  101. ?>
  102. <?
  103. if(count($arError)>0)
  104. {
  105. $e = new CAdminException($arError);
  106. $message = new CAdminMessage(GetMessage("rub_test_error"), $e);
  107. echo $message->Show();
  108. }
  109. ?>
  110. <?if($arRubric):?>
  111. <form method="POST" Action="<?echo $APPLICATION->GetCurPage()?>" ENCTYPE="multipart/form-data" name="post_form">
  112. <?
  113. $tabControl->Begin();
  114. ?>
  115. <?
  116. //********************
  117. //Template test tab
  118. //********************
  119. $tabControl->BeginNextTab();
  120. ?>
  121. <tr>
  122. <td><?echo GetMessage("rub_name")?></td>
  123. <td><input type="hidden" name="ID" value="<?echo $ID;?>"><?=htmlspecialcharsbx($arRubric["NAME"])?></td>
  124. </tr>
  125. <?
  126. $arTemplate = CPostingTemplate::GetByID($arRubric["TEMPLATE"]);
  127. if($arTemplate):
  128. ?>
  129. <tr>
  130. <td><?echo GetMessage("rub_tmpl_name")?></td>
  131. <td><?=htmlspecialcharsbx($arTemplate["NAME"])?></td>
  132. </tr>
  133. <tr>
  134. <td><?echo GetMessage("rub_tmpl_desc")?></td>
  135. <td><?=htmlspecialcharsbx($arTemplate["DESCRIPTION"])?></td>
  136. </tr>
  137. <?endif;?>
  138. <tr class="heading">
  139. <td colspan="2"><?echo GetMessage("rub_times")?></td>
  140. </tr>
  141. <tr class="adm-detail-required-field">
  142. <td><?echo GetMessage("rub_stime").":"?></td>
  143. <td><?echo CalendarDate("START_TIME", htmlspecialcharsbx($START_TIME), "post_form", "20")?></td>
  144. </tr>
  145. <tr class="adm-detail-required-field">
  146. <td><?echo GetMessage("rub_etime").":"?></td>
  147. <td><?echo CalendarDate("END_TIME", htmlspecialcharsbx($END_TIME), "post_form", "20")?></td>
  148. </tr>
  149. <?
  150. $tabControl->Buttons();
  151. ?>
  152. <?echo bitrix_sessid_post();?>
  153. <input type="hidden" name="lang" value="<?echo LANG?>">
  154. <input <?if ($POST_RIGHT<"W") echo "disabled" ?> type="submit" name="Test" value="<?echo GetMessage("rub_action")?>" title="<?echo GetMessage("rub_action_title")?>" class="adm-btn-save">
  155. <?
  156. $tabControl->End();
  157. ?>
  158. </form>
  159. <?
  160. $tabControl->ShowWarnings("post_form", $message);
  161. ?>
  162. <?endif;?>
  163. <?
  164. if($bTest):
  165. $rubrics = CRubric::GetList(array(), array("ID"=>$ID));
  166. if($arRubric=$rubrics->Fetch()):
  167. $arRubric["START_TIME"] = $START_TIME;
  168. $arRubric["END_TIME"] = $END_TIME;
  169. $arRubric["SITE_ID"] = $arRubric["LID"];
  170. //Include language file for template.php
  171. $rsSite = CSite::GetByID($arRubric["SITE_ID"]);
  172. $arSite = $rsSite->Fetch();
  173. $strFileName= $_SERVER["DOCUMENT_ROOT"]."/".$arRubric["TEMPLATE"]."/lang/".$arSite["LANGUAGE_ID"]."/template.php";
  174. if(file_exists($strFileName))
  175. include($strFileName);
  176. //Execute template
  177. $strFileName= $_SERVER["DOCUMENT_ROOT"]."/".$arRubric["TEMPLATE"]."/template.php";
  178. if(file_exists($strFileName))
  179. {
  180. ob_start();
  181. $arFields = include($strFileName);
  182. $strBody = ob_get_contents();
  183. ob_end_clean();
  184. }
  185. if(!is_array($arFields))
  186. $arFields=array();
  187. ?>
  188. <script language="JavaScript">
  189. <!--
  190. function hide(id)
  191. {
  192. document.getElementById("div_show_"+id).style.display = "inline";
  193. document.getElementById("div_hide_"+id).style.display = "none";
  194. }
  195. function show(id)
  196. {
  197. document.getElementById("div_show_"+id).style.display = "none";
  198. document.getElementById("div_hide_"+id).style.display = "inline";
  199. }
  200. //-->
  201. </script>
  202. <p>
  203. <div id="div_show_INPUT" style="display:inline;">
  204. <table width="100%" border="0" cellpadding="0" cellspacing="0" class="list-table">
  205. <tr class="head" align="center" valign="top">
  206. <td class="left right">
  207. <a href="javascript:show('INPUT');" ><?=GetMessage("rub_input_show")?></a>
  208. </td>
  209. </tr>
  210. </table>
  211. </div>
  212. <div id="div_hide_INPUT" style="display:none;">
  213. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="list-table">
  214. <tr class="head" align="center" valign="top">
  215. <td colspan="3" class="left right">
  216. <a href="javascript:hide('INPUT');"><?=GetMessage("rub_input_hide")?></a>
  217. </td>
  218. </tr>
  219. <?foreach($arRubric as $key=>$value):?>
  220. <tr>
  221. <td align="left" width="20%" class="left"><?echo $arFieldDescriptions[$key]?></td>
  222. <td align="right" width="10%"><?echo htmlspecialcharsbx($key)?></td>
  223. <td align="left" width="70%" class="right"><?echo $value <> ''? htmlspecialcharsbx($value) : "&nbsp"?></td>
  224. </tr>
  225. <?endforeach?>
  226. </table>
  227. </div>
  228. </p>
  229. <script language="JavaScript">
  230. <!--
  231. hide("INPUT");
  232. //-->
  233. </script>
  234. <p align="center"><b><?=GetMessage("rub_body")?></b></p>
  235. <?if($arFields["BODY_TYPE"]=="html"):?>
  236. <?=$strBody?>
  237. <?else:?>
  238. <pre><?=$strBody?></pre>
  239. <?endif?>
  240. <p>
  241. <div id="div_show_OUTPUT" style="display:inline;">
  242. <table width="100%" border="0" cellpadding="0" cellspacing="0" class="list-table">
  243. <tr class="head" align="center" valign="top">
  244. <td class="left right">
  245. <a href="javascript:show('OUTPUT');" ><?=GetMessage("rub_output_show")?></a>
  246. </td>
  247. </tr>
  248. </table>
  249. </div>
  250. <div id="div_hide_OUTPUT" style="display:none;">
  251. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="list-table">
  252. <tr class="head" align="center" valign="top">
  253. <td colspan="3" class="left right">
  254. <a href="javascript:hide('OUTPUT');"><?=GetMessage("rub_output_hide")?></a>
  255. </td>
  256. </tr>
  257. <?foreach($arFields as $key=>$value):
  258. if($key == "FILES" && is_array($value))
  259. $value = "<pre>".htmlspecialcharsbx(print_r($value, true))."</pre>";
  260. else
  261. $value = htmlspecialcharsbx(print_r($value, true));
  262. ?>
  263. <tr>
  264. <td align="left" width="20%" class="left"><?echo $arFieldDescriptions[$key]?></td>
  265. <td align="right" width="10%"><?echo htmlspecialcharsbx($key)?></td>
  266. <td align="left" width="70%" class="right"><?echo $value <> ''? $value : "&nbsp"?></td>
  267. </tr>
  268. <?endforeach?>
  269. </table>
  270. </div>
  271. </p>
  272. <script language="JavaScript">
  273. <!--
  274. hide("OUTPUT");
  275. //-->
  276. </script>
  277. <form method="post" action="posting_edit.php" ENCTYPE="multipart/form-data" name="add_form">
  278. <?echo bitrix_sessid_post();?>
  279. <input type="hidden" name="lang" value="<?echo LANG?>">
  280. <input type="hidden" name="RUB_ID[]" value="<?=htmlspecialcharsbx($arRubric["ID"])?>">
  281. <?if(array_key_exists("GROUP_ID", $arFields)):
  282. if(is_array($arFields["GROUP_ID"]))
  283. {
  284. foreach($arFields["GROUP_ID"] as $GROUP_ID)
  285. {
  286. ?><input type="hidden" name="GROUP_ID[]" value="<?=htmlspecialcharsbx($GROUP_ID)?>"><?
  287. }
  288. }
  289. else
  290. {
  291. ?><input type="hidden" name="GROUP_ID[]" value="<?=htmlspecialcharsbx($arFields["GROUP_ID"])?>"><?
  292. }
  293. endif;?>
  294. <?if(array_key_exists("FILES", $arFields) && is_array($arFields["FILES"])):
  295. foreach($arFields["FILES"] as $i => $arFile)
  296. {
  297. $i = htmlspecialcharsbx($i);
  298. if(is_array($arFile))
  299. {
  300. foreach($arFile as $key => $value)
  301. {
  302. $key = htmlspecialcharsbx($key);
  303. $value = htmlspecialcharsbx($value);
  304. ?><input type="hidden" name="FILES[<?echo $i?>][<?echo $key?>]" value="<?echo $value?>"><?
  305. }
  306. }
  307. }
  308. endif;?>
  309. <input type="hidden" name="FROM_FIELD" value="<?=htmlspecialcharsbx($arFields["FROM_FIELD"])?>">
  310. <input type="hidden" name="SUBJECT" value="<?=htmlspecialcharsbx($arFields["SUBJECT"])?>">
  311. <input type="hidden" name="BODY_TYPE" value="<?=htmlspecialcharsbx($arFields["BODY_TYPE"])?>">
  312. <input type="hidden" name="CHARSET" value="<?=htmlspecialcharsbx($arFields["CHARSET"])?>">
  313. <input type="hidden" name="DIRECT_SEND" value="<?=htmlspecialcharsbx($arFields["DIRECT_SEND"])?>">
  314. <input type="hidden" name="BODY" value="<?=htmlspecialcharsbx($strBody)?>">
  315. <input <?if ($POST_RIGHT<"W") echo "disabled" ?> type="submit" name="apply" value="<?=GetMessage("rub_add_issue")?>" title="<?=GetMessage("rub_add_issue_act")?>">
  316. </form>
  317. <?endif?>
  318. <?endif?>
  319. <?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin.php");?>