PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/bitrix/wizards/bitrix/demo/scripts/install_steps.php

https://gitlab.com/Rad1calDreamer/honey
PHP | 279 lines | 215 code | 53 blank | 11 comment | 31 complexity | 6b891e4977bae3b294bbd88c143eb438 MD5 | raw file
  1. <?
  2. if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
  3. require_once("utils.php");
  4. class InstallTemplateData extends CWizardStep
  5. {
  6. function InitStep()
  7. {
  8. $this->SetTitle(GetMessage("DEMO_SITE_INSTALL_THEME_TITLE"));
  9. $this->SetNextStep("install_services");
  10. $this->SetAutoSubmit();
  11. }
  12. function OnPostForm()
  13. {
  14. $wizard =& $this->GetWizard();
  15. $templateID = $wizard->GetSiteTemplateID();
  16. $templatePath = BX_PERSONAL_ROOT."/templates/".$templateID;
  17. $arReplace = Array(
  18. "COMPANY_NAME" => $wizard->GetVar("company_name"),
  19. "COMPANY_SLOGAN" => $wizard->GetVar("company_slogan"),
  20. );
  21. CWizardUtil::ReplaceMacros($_SERVER["DOCUMENT_ROOT"].$templatePath."/include_areas/company_name.php", $arReplace);
  22. $server_name = ($_SERVER["HTTP_HOST"] <> ''? $_SERVER["HTTP_HOST"]:$_SERVER["SERVER_NAME"]);
  23. if($_SERVER["SERVER_PORT"] <> 80 && $_SERVER["SERVER_PORT"] <> 443 && $_SERVER["SERVER_PORT"] > 0 && strpos($_SERVER["HTTP_HOST"], ":") === false)
  24. $server_name .= ":".$_SERVER["SERVER_PORT"];
  25. COption::SetOptionString("main", "server_name", $server_name);
  26. COption::SetOptionString("main", "site_name", htmlspecialcharsEx($wizard->GetVar("company_name")));
  27. COption::SetOptionString("main", "wizard_company_slogan", $wizard->GetVar("company_slogan"));
  28. $themeVarName = $templateID."_themeID";
  29. $themeID = $wizard->GetVar($themeVarName);
  30. $themeID = Rel2Abs("/", $themeID);
  31. $themePath = $_SERVER["DOCUMENT_ROOT"].DemoSiteUtil::GetTemplatesPath($wizard->GetPath())."/".$templateID."/themes/".$themeID;
  32. CopyDirFiles(
  33. $themePath,
  34. $_SERVER["DOCUMENT_ROOT"].$templatePath,
  35. $rewrite = true,
  36. $recursive = true,
  37. $delete_after_copy = false,
  38. $exclude = "description.php"
  39. );
  40. $companyLogo = $wizard->GetVar("company_logo");
  41. CWizardUtil::CopyFile($companyLogo, $templatePath."/images/logo.gif", false);
  42. COption::SetOptionString("main", "wizard_site_logo", $companyLogo);
  43. }
  44. function ShowStep()
  45. {
  46. $this->content .= '
  47. <table border="0" cellspacing="4" cellpadding="6" width="550">
  48. <tr>
  49. <td>'.GetMessage("DEMO_SITE_INSTALL_THEME_CONTENT").'</td>
  50. </tr>
  51. <tr>
  52. <td><br />
  53. <table width=200 cellspacing="0" cellpadding="0" border="0" style="border:1px solid #EFCB69" bgcolor="#FFF7D7" align="center">
  54. <tr>
  55. <td height="50" width="50" valign="middle" align=center><img src="/bitrix/wizards/bitrix/demo/images/wait.gif"></td>
  56. <td height="50" width="150">'.GetMessage("MAIN_WIZARD_WAIT_WINDOW_TEXT").'</td>
  57. </tr>
  58. </table>
  59. </td>
  60. </tr>
  61. </table>';
  62. }
  63. }
  64. class InstallServices extends CWizardStep
  65. {
  66. function InitStep()
  67. {
  68. $this->SetTitle(GetMessage("INSTALL_SERVICE_TITLE"));
  69. }
  70. function OnPostForm()
  71. {
  72. $wizard =& $this->GetWizard();
  73. $serviceID = $wizard->GetVar("nextStep");
  74. $serviceStage = $wizard->GetVar("nextStepStage");
  75. if ($serviceID == "__finish")
  76. {
  77. $wizard->SetCurrentStep("__finish");
  78. //$wizard->SetCurrentStep("__install_structure");
  79. return;
  80. }
  81. $servicePath = $_SERVER["DOCUMENT_ROOT"].$wizard->GetPath()."/modules/";
  82. $arServiceSelected = $wizard->GetVar("services");
  83. if (!$arServiceSelected)
  84. $arServiceSelected = Array();
  85. $arServices = DemoSiteUtil::GetServices($servicePath, $arFilter = Array("SERVICES" => $arServiceSelected));
  86. /*$package =& $wizard->GetPackage();
  87. $arStructureServices = DemoSiteUtil::GetSelectedServices($package->GetSiteStructureID());
  88. $arServicePath = (array_key_exists($serviceID, $arStructureServices) ? $arStructureServices[$serviceID] : Array());*/
  89. if ($serviceStage == "skip")
  90. $success = true;
  91. else
  92. $success = $this->InstallDemoService($serviceID, $serviceStage);
  93. list($nextService, $nextServiceStage, $stepsComplete, $status) = $this->GetNextStep($arServices, $serviceID, $serviceStage);
  94. if ($nextService == "__finish")
  95. {
  96. $formName = $wizard->GetFormName();
  97. $nextButtonID = $wizard->GetNextButtonID();
  98. $response = "window.ajaxForm.StopAjax(); window.ajaxForm.SetStatus('100'); window.ajaxForm.Post('".$nextService."', '".$nextServiceStage."','".$status."');";
  99. }
  100. else
  101. {
  102. $arServiceID = array_keys($arServices);
  103. $lastService = array_pop($arServiceID);
  104. $stepsCount = $arServices[$lastService]["POSITION"];
  105. if (array_key_exists("STAGES", $arServices[$lastService]) && is_array($arServices[$lastService]))
  106. $stepsCount += count($arServices[$lastService]["STAGES"])-1;
  107. $percent = round($stepsComplete/$stepsCount * 100);
  108. $response = "window.ajaxForm.SetStatus('".$percent."'); window.ajaxForm.Post('".$nextService."', '".$nextServiceStage."','".$status."');";
  109. }
  110. die("[response]".$response."[/response]");
  111. }
  112. function InstallDemoService($serviceID, $serviceStage)
  113. {
  114. @set_time_limit(3600);
  115. $wizard =& $this->GetWizard();
  116. $templateID = $wizard->GetSiteTemplateID();
  117. $servicePath = $_SERVER["DOCUMENT_ROOT"].$wizard->GetPath()."/modules/".$serviceID."/".$serviceStage;
  118. $serviceRelativePath = $wizard->GetPath()."/modules/".$serviceID;
  119. $wizardPath = $_SERVER["DOCUMENT_ROOT"].$wizard->GetPath();
  120. if (!file_exists($servicePath))
  121. return false;
  122. global $DB, $DBType, $APPLICATION, $USER;
  123. include($servicePath);
  124. }
  125. function GetNextStep(&$arServices, &$currentService, &$currentStage)
  126. {
  127. $nextService = "__finish";
  128. $nextServiceStage = "__finish";
  129. $status = GetMessage("INSTALL_SERVICE_FINISH_STATUS");
  130. if (!array_key_exists($currentService, $arServices))
  131. return Array($nextService, $nextServiceStage, 0, $status); //Finish
  132. if ($currentStage != "skip" && array_key_exists("STAGES", $arServices[$currentService]) && is_array($arServices[$currentService]["STAGES"]))
  133. {
  134. $stageIndex = array_search($currentStage, $arServices[$currentService]["STAGES"]);
  135. if ($stageIndex !== false && isset($arServices[$currentService]["STAGES"][$stageIndex+1]))
  136. return Array(
  137. $currentService,
  138. $arServices[$currentService]["STAGES"][$stageIndex+1],
  139. $arServices[$currentService]["POSITION"]+ $stageIndex,
  140. $arServices[$currentService]["NAME"]
  141. ); //Current step, next stage
  142. }
  143. $arServiceID = array_keys($arServices);
  144. $serviceIndex = array_search($currentService, $arServiceID);
  145. if (!isset($arServiceID[$serviceIndex+1]))
  146. return Array($nextService, $nextServiceStage, 0, $status); //Finish
  147. $nextServiceID = $arServiceID[$serviceIndex+1];
  148. $nextServiceStage = "index.php";
  149. if (array_key_exists("STAGES", $arServices[$nextServiceID]) && is_array($arServices[$nextServiceID]["STAGES"]) && isset($arServices[$nextServiceID]["STAGES"][0]))
  150. $nextServiceStage = $arServices[$nextServiceID]["STAGES"][0];
  151. return Array($nextServiceID, $nextServiceStage, $arServices[$nextServiceID]["POSITION"]-1, $arServices[$nextServiceID]["NAME"]); //Next service
  152. }
  153. function GetFirstStep(&$arServices)
  154. {
  155. foreach ($arServices as $serviceID => $arService)
  156. {
  157. $stage = "index.php";
  158. if (array_key_exists("STAGES", $arService) && is_array($arService["STAGES"]) && isset($arService["STAGES"][0]))
  159. $stage = $arService["STAGES"][0];
  160. return Array($serviceID, $stage, $arService["NAME"]);
  161. }
  162. return Array("service_not_found", "__finish", GetMessage("INSTALL_SERVICE_FINISH_STATUS"));
  163. }
  164. function ShowStep()
  165. {
  166. $this->SetAutoSubmit(false);
  167. $wizard =& $this->GetWizard();
  168. $servicePath = $_SERVER["DOCUMENT_ROOT"].$wizard->GetPath()."/modules/";
  169. $arServiceSelected = $wizard->GetVar("services");
  170. if (!$arServiceSelected)
  171. $arServiceSelected = Array();
  172. $arServices = DemoSiteUtil::GetServices($servicePath, $arFilter = Array("SERVICES" => $arServiceSelected));
  173. /*$package =& $wizard->GetPackage();
  174. $arServiceSelected = array_keys(DemoSiteUtil::GetSelectedServices($package->GetSiteStructureID()));
  175. */
  176. //$this->content .= "<pre>".print_r($wizard->GetVar("services"), true)."</pre>";
  177. list($firstService, $stage, $status) = $this->GetFirstStep($arServices);
  178. $this->content .= '
  179. <table border="0" cellspacing="0" cellpadding="2" width="550">
  180. <tr>
  181. <td colspan="2"><div id="status"></div></td>
  182. </tr>
  183. <tr>
  184. <td width="90%" height="10">
  185. <div style="border:1px solid #B9CBDF; width:100%;"><div id="indicator" style="height:10px; width:0%; background-color:#B9CBDF"></div></div>
  186. </td>
  187. <td width="10%">&nbsp;<span id="percent">0%</span></td>
  188. </tr>
  189. </table>
  190. <div id="wait" align=center>
  191. <br />
  192. <table width=200 cellspacing=0 cellpadding=0 border=0 style="border:1px solid #EFCB69" bgcolor="#FFF7D7">
  193. <tr>
  194. <td height=50 width="50" valign="middle" align=center><img src="/bitrix/wizards/bitrix/demo/images/wait.gif"></td>
  195. <td height=50 width=150>'.GetMessage("MAIN_WIZARD_WAIT_WINDOW_TEXT").'</td>
  196. </tr>
  197. </table>
  198. </div><br />
  199. <br />
  200. <div id="error_container" style="display:none">
  201. <div id="error_notice"><span style="color:red;">'.GetMessage("INST_ERROR_OCCURED").'<br />'.GetMessage("INST_TEXT_ERROR").':</span></div>
  202. <div id="error_text"></div>
  203. <div><span style="color:red;">'.GetMessage("INST_ERROR_NOTICE").'</span></div>
  204. <div id="error_buttons" align="center">
  205. <br /><input type="button" value="'.GetMessage("INST_RETRY_BUTTON").'" id="error_retry_button" onclick="" />&nbsp;<input type="button" id="error_skip_button" value="'.GetMessage("INST_SKIP_BUTTON").'" onclick="" />&nbsp;</div>
  206. </div>
  207. '.$this->ShowHiddenField("nextStep", $firstService).'
  208. '.$this->ShowHiddenField("nextStepStage", $stage).'
  209. <iframe style="display:none;" id="iframe-post-form" name="iframe-post-form" src="javascript:\'\'"></iframe>';
  210. $wizard =& $this->GetWizard();
  211. $formName = $wizard->GetFormName();
  212. $nextButtonID = $wizard->GetNextButtonID();
  213. $NextStepVarName = $wizard->GetRealName("nextStep");
  214. $this->content .= '
  215. <script type="text/javascript">
  216. var ajaxForm = new CAjaxForm("'.$formName.'", "iframe-post-form", "'.$NextStepVarName.'");
  217. ajaxForm.Post("'.$firstService.'", "'.$stage.'", "'.$status.'");
  218. </script>';
  219. $package =& $wizard->GetPackage();
  220. //$this->content = print_r($package->GetSiteStructureID(), true);
  221. //$this->content .= "<pre>".print_r($arServices, true)."</pre>";
  222. //setTimeout(function () {document.forms["'.$formName.'"].elements["'.$nextButtonID.'"].style.display = "none"}, 1000);
  223. }
  224. }
  225. ?>