wizardsteps.class.inc.php 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298
  1. <?php
  2. // Copyright (C) 2012 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * All the steps of the iTop installation wizard
  18. * @author Erwan Taloc <erwan.taloc@combodo.com>
  19. * @author Romain Quetiez <romain.quetiez@combodo.com>
  20. * @author Denis Flaven <denis.flaven@combodo.com>
  21. * @license http://www.opensource.org/licenses/gpl-3.0.html GPL
  22. */
  23. require_once(APPROOT.'setup/setuputils.class.inc.php');
  24. require_once(APPROOT.'setup/parameters.class.inc.php');
  25. require_once(APPROOT.'setup/applicationinstaller.class.inc.php');
  26. require_once(APPROOT.'setup/parameters.class.inc.php');
  27. /**
  28. * First step of the iTop Installation Wizard: Welcome screen
  29. */
  30. class WizStepWelcome extends WizardStep
  31. {
  32. protected $bCanMoveForward;
  33. public function GetTitle()
  34. {
  35. return 'Welcome to '.ITOP_APPLICATION.' version '.ITOP_VERSION;
  36. }
  37. /**
  38. * Returns the label for the " Next >> " button
  39. * @return string The label for the button
  40. */
  41. public function GetNextButtonLabel()
  42. {
  43. return ' Continue >> ';
  44. }
  45. public function GetPossibleSteps()
  46. {
  47. return array('WizStepInstallOrUpgrade');
  48. }
  49. public function ProcessParams($bMoveForward = true)
  50. {
  51. return array('class' => 'WizStepInstallOrUpgrade', 'state' => '');
  52. }
  53. public function Display(WebPage $oPage)
  54. {
  55. // Store the misc_options for the future...
  56. $aMiscOptions = utils::ReadParam('option', array(), false, 'raw_data');
  57. $sMiscOptions = $this->oWizard->GetParameter('misc_options', json_encode($aMiscOptions));
  58. $this->oWizard->SetParameter('misc_options', $sMiscOptions);
  59. $oPage->add('<h1>iTop Installation Wizard</h1>');
  60. $aResults = SetupUtils::CheckPHPVersion($oPage);
  61. $this->bCanMoveForward = true;
  62. $aInfo = array();
  63. $aWarnings = array();
  64. $aErrors = array();
  65. foreach($aResults as $oCheckResult)
  66. {
  67. switch($oCheckResult->iSeverity)
  68. {
  69. case CheckResult::ERROR:
  70. $aErrors[] = $oCheckResult->sLabel;
  71. $this->bCanMoveForward = false;
  72. break;
  73. case CheckResult::WARNING:
  74. $aWarnings[] = $oCheckResult->sLabel;
  75. break;
  76. case CheckResult::INFO:
  77. $aInfo[] = $oCheckResult->sLabel;
  78. break;
  79. }
  80. }
  81. $sStyle = 'style="display:none;max-height:196px;overflow:auto;"';
  82. $sToggleButtons = '<button type="button" id="show_details" onclick="$(\'#details\').toggle(); $(this).toggle(); $(\'#hide_details\').toggle();">Show details</button><button type="button" id="hide_details" style="display:none;" onclick="$(\'#details\').toggle(); $(this).toggle(); $(\'#show_details\').toggle();">Hide details</button>';
  83. if (count($aErrors)> 0)
  84. {
  85. $sStyle = 'style="max-height:196px;overflow:auto;"';
  86. $sImage = "stop-mid.png";
  87. $sTitle = count($aErrors).' Error(s), '.count($aWarnings).' Warning(s).';
  88. }
  89. else if (count($aWarnings)> 0)
  90. {
  91. $sTitle = count($aWarnings).' Warning(s) '.$sToggleButtons;
  92. $sImage = "messagebox_warning-mid.png";
  93. }
  94. else
  95. {
  96. $sTitle = 'Ok. '.$sToggleButtons;
  97. $sImage = "clean-mid.png";
  98. }
  99. $oPage->add('<h2>Prerequisites validation: ');
  100. $oPage->add("<img style=\"vertical-align:middle;\" src=\"../images/$sImage\"> ");
  101. $oPage->add($sTitle);
  102. $oPage->add('</h2>');
  103. $oPage->add('<div id="details" '.$sStyle.'>');
  104. foreach($aErrors as $sText)
  105. {
  106. $oPage->error($sText);
  107. }
  108. foreach($aWarnings as $sText)
  109. {
  110. $oPage->warning($sText);
  111. }
  112. foreach($aInfo as $sText)
  113. {
  114. $oPage->ok($sText);
  115. }
  116. $oPage->add('</div>');
  117. if (!$this->bCanMoveForward)
  118. {
  119. $oPage->p('Sorry, the installation cannot continue. Please fix the errors and reload this page to launch the installation again.');
  120. }
  121. }
  122. public function CanMoveForward()
  123. {
  124. return $this->bCanMoveForward;
  125. }
  126. }
  127. /**
  128. * Second step of the iTop Installation Wizard: Install or Upgrade
  129. */
  130. class WizStepInstallOrUpgrade extends WizardStep
  131. {
  132. public function GetTitle()
  133. {
  134. return 'Install or Upgrade choice';
  135. }
  136. public function GetPossibleSteps()
  137. {
  138. return array('WizStepDetectedInfo', 'WizStepLicense');
  139. }
  140. public function ProcessParams($bMoveForward = true)
  141. {
  142. $sNextStep = '';
  143. $sInstallMode = utils::ReadParam('install_mode');
  144. $this->oWizard->SaveParameter('source_dir', '');
  145. $this->oWizard->SaveParameter('db_server', '');
  146. $this->oWizard->SaveParameter('db_user', '');
  147. $this->oWizard->SaveParameter('db_pwd', '');
  148. $this->oWizard->SaveParameter('db_name', '');
  149. $this->oWizard->SaveParameter('db_prefix', '');
  150. $this->oWizard->SaveParameter('db_backup', false);
  151. $this->oWizard->SaveParameter('db_backup_path', '');
  152. if ($sInstallMode == 'install')
  153. {
  154. $this->oWizard->SetParameter('install_mode', 'install');
  155. $sNextStep = 'WizStepLicense';
  156. }
  157. else
  158. {
  159. $this->oWizard->SetParameter('install_mode', 'upgrade');
  160. $sNextStep = 'WizStepDetectedInfo';
  161. }
  162. return array('class' => $sNextStep, 'state' => '');
  163. }
  164. public function Display(WebPage $oPage)
  165. {
  166. $sInstallMode = $this->oWizard->GetParameter('install_mode', '');
  167. $sSourceDir = $this->oWizard->GetParameter('source_dir', '');
  168. $sDBServer = $this->oWizard->GetParameter('db_server', '');
  169. $sDBUser = $this->oWizard->GetParameter('db_user', '');
  170. $sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
  171. $sDBName = $this->oWizard->GetParameter('db_name', '');
  172. $sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
  173. $bDBBackup = $this->oWizard->GetParameter('db_backup', false);
  174. $sDBBackupPath = $this->oWizard->GetParameter('db_backup_path', '');
  175. if ($sInstallMode == '')
  176. {
  177. $sDBBackupPath = APPROOT.'data/'.ITOP_APPLICATION.strftime('-backup-%Y-%m-%d.zip');
  178. $bDBBackup = true;
  179. $aPreviousInstance = SetupUtils::GetPreviousInstance(APPROOT);
  180. if ($aPreviousInstance['found'])
  181. {
  182. $sInstallMode = 'upgrade';
  183. $sSourceDir = APPROOT;
  184. $sDBServer = $aPreviousInstance['db_server'];
  185. $sDBUser = $aPreviousInstance['db_user'];
  186. $sDBPwd = $aPreviousInstance['db_pwd'];
  187. $sDBName = $aPreviousInstance['db_name'];
  188. $sDBPrefix = $aPreviousInstance['db_prefix'];
  189. //TODO: check if we can run the backup
  190. $sStyle = '';
  191. }
  192. else
  193. {
  194. $sInstallMode = 'install';
  195. }
  196. }
  197. $sUpgradeInfoStyle = '';
  198. if ($sInstallMode == 'install')
  199. {
  200. $sUpgradeInfoStyle = ' style="display: none;" ';
  201. }
  202. $oPage->add('<h2>What do you want to do?</h2>');
  203. $sChecked = ($sInstallMode == 'install') ? ' checked ' : '';
  204. $oPage->p('<input id="radio_install" type="radio" name="install_mode" value="install"'.$sChecked.'/><label for="radio_install">&nbsp;Install a new '.ITOP_APPLICATION.'</label>');
  205. $sChecked = ($sInstallMode == 'upgrade') ? ' checked ' : '';
  206. $oPage->p('<input id="radio_update" type="radio" name="install_mode" value="upgrade"'.$sChecked.'/><label for="radio_update">&nbsp;Upgrade an existing '.ITOP_APPLICATION.' instance</label>');
  207. //$oPage->add('<fieldset id="upgrade_info"'.$sUpgradeInfoStyle.'>');
  208. //$oPage->add('<legend>Information about the previous instance:</legend>');
  209. $oPage->add('<table id="upgrade_info"'.$sUpgradeInfoStyle.'>');
  210. $oPage->add('<tr><td>Location on the disk:</td><td><input id="source_dir" type="text" name="source_dir" value="'.htmlentities($sSourceDir, ENT_QUOTES, 'UTF-8').'" size="25"/></td></tr>');
  211. SetupUtils::DisplayDBParameters($oPage, false, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix);
  212. $sChecked = ($bDBBackup == 'install') ? ' checked ' : '';
  213. $oPage->add('<tr><td style="text-align:right"><input id="db_backup" type="checkbox" name="db_backup"'.$sChecked.' value="1"/></td><td>Backup the '.ITOP_APPLICATION.' database before upgrading</td></tr>');
  214. $oPage->add('<tr><td>Save the backup to:</td><td><input id="db_backup_path" type="text" name="db_backup_path" value="'.htmlentities($sDBBackupPath, ENT_QUOTES, 'UTF-8').'" size="25"/></td></tr>');
  215. $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
  216. $sMessage = '';
  217. if ($fFreeSpace !== false)
  218. {
  219. $sMessage = SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath);
  220. }
  221. $oPage->add('<tr><td>&nbsp;</td>');
  222. $oPage->add('<td><span id="backup_info" style="font-size:small;color:#696969;">'.$sMessage.'</span></td></tr>');
  223. $oPage->add('</table>');
  224. //$oPage->add('</fieldset>');
  225. $oPage->add_ready_script(
  226. <<<EOF
  227. $("#radio_update").bind('change', function() { if (this.checked ) { $('#upgrade_info').show(); WizardUpdateButtons(); } else { $('#upgrade_info').hide(); } });
  228. $("#radio_install").bind('change', function() { if (this.checked ) { $('#upgrade_info').hide(); WizardUpdateButtons(); } else { $('#upgrade_info').show(); } });
  229. $("#source_dir").bind('change keyup', function() { WizardAsyncAction('check_path', { source_dir: $('#source_dir').val() }); });
  230. $("#db_backup_path").bind('change keyup', function() { WizardAsyncAction('check_backup', { db_backup_path: $('#db_backup_path').val() }); });
  231. EOF
  232. );
  233. }
  234. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  235. {
  236. switch($sCode)
  237. {
  238. case 'check_path':
  239. $sSourceDir = $aParameters['source_dir'];
  240. $aPreviousInstance = SetupUtils::GetPreviousInstance($sSourceDir);
  241. if ($aPreviousInstance['found'])
  242. {
  243. $sDBServer = htmlentities($aPreviousInstance['db_server'], ENT_QUOTES, 'UTF-8');
  244. $sDBUser = htmlentities($aPreviousInstance['db_user'], ENT_QUOTES, 'UTF-8');
  245. $sDBPwd = htmlentities($aPreviousInstance['db_pwd'], ENT_QUOTES, 'UTF-8');
  246. $sDBName = htmlentities($aPreviousInstance['db_name'], ENT_QUOTES, 'UTF-8');
  247. $sDBPrefix = htmlentities($aPreviousInstance['db_prefix'], ENT_QUOTES, 'UTF-8');
  248. $oPage->add_ready_script(
  249. <<<EOF
  250. $("#db_server").val('$sDBServer');
  251. $("#db_user").val('$sDBUser');
  252. $("#db_pwd").val('$sDBPwd');
  253. $("#db_name").val('$sDBName');
  254. $("#db_prefix").val('$sDBPrefix');
  255. EOF
  256. );
  257. }
  258. break;
  259. case 'check_db':
  260. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  261. break;
  262. case 'check_backup':
  263. $sDBBackupPath = $aParameters['db_backup_path'];
  264. $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
  265. if ($fFreeSpace !== false)
  266. {
  267. $sMessage = htmlentities(SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath), ENT_QUOTES, 'UTF-8');
  268. $oPage->add_ready_script(
  269. <<<EOF
  270. $("#backup_info").html('$sMessage');
  271. EOF
  272. );
  273. }
  274. else
  275. {
  276. $oPage->add_ready_script(
  277. <<<EOF
  278. $("#backup_info").html('');
  279. EOF
  280. );
  281. }
  282. break;
  283. }
  284. }
  285. /**
  286. * Tells whether the "Next" button should be enabled interactively
  287. * @return string A piece of javascript code returning either true or false
  288. */
  289. public function JSCanMoveForward()
  290. {
  291. return
  292. <<<EOF
  293. if ($("#radio_install").attr("checked") == "checked")
  294. {
  295. ValidateField("db_name", false);
  296. ValidateField("db_new_name", false);
  297. ValidateField("db_prefix", false);
  298. return true;
  299. }
  300. else
  301. {
  302. var bRet = ($("#wiz_form").data("db_connection") !== "error");
  303. bRet = ValidateField("db_name", true) && bRet;
  304. bRet = ValidateField("db_new_name", true) && bRet;
  305. bRet = ValidateField("db_prefix", true) && bRet;
  306. return bRet;
  307. }
  308. EOF
  309. ;
  310. }
  311. }
  312. /**
  313. * Upgrade information
  314. */
  315. class WizStepDetectedInfo extends WizardStep
  316. {
  317. public function GetTitle()
  318. {
  319. return 'Detected Info';
  320. }
  321. public function GetPossibleSteps()
  322. {
  323. return array('WizStepUpgradeKeep', 'WizStepUpgradeAuto', 'WizStepLicense2');
  324. }
  325. public function ProcessParams($bMoveForward = true)
  326. {
  327. return array('class' => 'WizStepLicense2', 'state' => '');
  328. }
  329. public function Display(WebPage $oPage)
  330. {
  331. $oPage->p('Info about the detected version');
  332. }
  333. }
  334. /**
  335. * Keep or Upgrade choice
  336. */
  337. class WizStepUpgradeKeep extends WizardStep
  338. {
  339. public function GetTitle()
  340. {
  341. return 'Keep or Upgrade';
  342. }
  343. public function GetPossibleSteps()
  344. {
  345. return array('WizStepModulesChoice');
  346. }
  347. public function ProcessParams($bMoveForward = true)
  348. {
  349. return array('class' => 'WizStepModulesChoice', 'state' => 'start_upgrade');
  350. }
  351. public function Display(WebPage $oPage)
  352. {
  353. $oPage->p('Keep or Upgrade the data model');
  354. }
  355. }
  356. /**
  357. * Automatic Upgrade info
  358. */
  359. class WizStepUpgradeAuto extends WizardStep
  360. {
  361. public function GetTitle()
  362. {
  363. return 'Upgrade Information';
  364. }
  365. public function GetPossibleSteps()
  366. {
  367. return array('WizStepModulesChoice');
  368. }
  369. public function ProcessParams($bMoveForward = true)
  370. {
  371. return array('class' => 'WizStepModulesChoice', 'state' => 'start_upgrade');
  372. }
  373. public function Display(WebPage $oPage)
  374. {
  375. $oPage->p('Automatic Upgrade information');
  376. }
  377. }
  378. /**
  379. * License acceptation screen
  380. */
  381. class WizStepLicense extends WizardStep
  382. {
  383. public function GetTitle()
  384. {
  385. return 'License Agreement';
  386. }
  387. public function GetPossibleSteps()
  388. {
  389. return array('WizStepDBParams');
  390. }
  391. public function ProcessParams($bMoveForward = true)
  392. {
  393. $this->oWizard->SaveParameter('accept_license', 'no');
  394. return array('class' => 'WizStepDBParams', 'state' => '');
  395. }
  396. public function Display(WebPage $oPage)
  397. {
  398. $aLicenses = array();
  399. foreach (glob(APPROOT.'setup/licenses/*.xml') as $sFile)
  400. {
  401. $oXml = simplexml_load_file($sFile);
  402. foreach($oXml->license as $oLicense)
  403. {
  404. $aLicenses[] = $oLicense;
  405. }
  406. }
  407. $oPage->add('<h2>Licenses agreements for the components of '.ITOP_APPLICATION.'</h2>');
  408. $oPage->add_style('div a.no-arrow { background:transparent; padding-left:0;}');
  409. $oPage->add_style('.toggle { cursor:pointer; text-decoration:underline; color:#1C94C4; }');
  410. $oPage->add('<fieldset>');
  411. $oPage->add('<legend>Components of '.ITOP_APPLICATION.'</legend>');
  412. $oPage->add('<ul>');
  413. foreach($aLicenses as $index => $oLicense)
  414. {
  415. $oPage->add('<li><b>'.$oLicense->product.'</b>, licensed by '.$oLicense->author.' under the <b>'.$oLicense->license_type.' license</b>. (<span class="toggle" id="toggle_'.$index.'">Details</span>)');
  416. $oPage->add('<div id="license_'.$index.'" class="license_text" style="display:none;overflow:auto;max-height:10em;font-size:small;border:1px #696969 solid;margin-bottom:1em; margin-top:0.5em;padding:0.5em;">'.$oLicense->text.'<div>');
  417. $oPage->add_ready_script('$(".license_text a").attr("target", "_blank").addClass("no-arrow");');
  418. $oPage->add_ready_script('$("#toggle_'.$index.'").click( function() { $("#license_'.$index.'").toggle(); } );');
  419. }
  420. $oPage->add('</ul>');
  421. $oPage->add('</fieldset>');
  422. $sChecked = ($this->oWizard->GetParameter('accept_license', 'no') == 'yes') ? ' checked ' : '';
  423. $oPage->p('<input type="checkbox" name="accept_license" id="accept" value="yes"'.$sChecked.'><label for="accept">&nbsp;I accept the terms of the licenses of the '.count($aLicenses).' components mentioned above.</label>');
  424. $oPage->add_ready_script('$("#accept").bind("click change", function() { WizardUpdateButtons(); });');
  425. }
  426. /**
  427. * Tells whether the "Next" button should be enabled interactively
  428. * @return string A piece of javascript code returning either true or false
  429. */
  430. public function JSCanMoveForward()
  431. {
  432. return 'return ($("#accept").attr("checked") === "checked");';
  433. }
  434. }
  435. /**
  436. * License acceptation screen (when upgrading)
  437. */
  438. class WizStepLicense2 extends WizStepLicense
  439. {
  440. public function GetPossibleSteps()
  441. {
  442. return array('WizStepUpgradeKeep', 'WizStepUpgradeAuto');
  443. }
  444. public function ProcessParams($bMoveForward = true)
  445. {
  446. return array('class' => 'WizStepUpgradeAuto', 'state' => '');
  447. }
  448. }
  449. /**
  450. * Database Connection parameters screen
  451. */
  452. class WizStepDBParams extends WizardStep
  453. {
  454. public function GetTitle()
  455. {
  456. return 'Database Configuration';
  457. }
  458. public function GetPossibleSteps()
  459. {
  460. return array('WizStepAdminAccount');
  461. }
  462. public function ProcessParams($bMoveForward = true)
  463. {
  464. $this->oWizard->SaveParameter('db_server', '');
  465. $this->oWizard->SaveParameter('db_user', '');
  466. $this->oWizard->SaveParameter('db_pwd', '');
  467. $this->oWizard->SaveParameter('db_name', '');
  468. $this->oWizard->SaveParameter('db_prefix', '');
  469. $this->oWizard->SaveParameter('new_db_name', '');
  470. $this->oWizard->SaveParameter('create_db', '');
  471. $this->oWizard->SaveParameter('db_new_name', '');
  472. return array('class' => 'WizStepAdminAccount', 'state' => '');
  473. }
  474. public function Display(WebPage $oPage)
  475. {
  476. $oPage->add('<h2>Configuration of the database connection:</h2>');
  477. $sDBServer = $this->oWizard->GetParameter('db_server', '');
  478. $sDBUser = $this->oWizard->GetParameter('db_user', '');
  479. $sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
  480. $sDBName = $this->oWizard->GetParameter('db_name', '');
  481. $sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
  482. $sNewDBName = $this->oWizard->GetParameter('db_new_name', false);
  483. $oPage->add('<table>');
  484. SetupUtils::DisplayDBParameters($oPage, true, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName);
  485. $oPage->add('</table>');
  486. $sCreateDB = $this->oWizard->GetParameter('create_db', 'no');
  487. if ($sCreateDB == 'no')
  488. {
  489. $oPage->add_ready_script('$("#existing_db").attr("checked", "checked");');
  490. }
  491. else
  492. {
  493. $oPage->add_ready_script('$("#create_db").attr("checked", "checked");');
  494. }
  495. }
  496. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  497. {
  498. switch($sCode)
  499. {
  500. case 'check_db':
  501. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  502. break;
  503. }
  504. }
  505. /**
  506. * Tells whether the "Next" button should be enabled interactively
  507. * @return string A piece of javascript code returning either true or false
  508. */
  509. public function JSCanMoveForward()
  510. {
  511. return
  512. <<<EOF
  513. if ($("#wiz_form").data("db_connection") === "error") return false;
  514. var bRet = true;
  515. bRet = ValidateField("db_name", true) && bRet;
  516. bRet = ValidateField("db_new_name", true) && bRet;
  517. bRet = ValidateField("db_prefix", true) && bRet;
  518. return bRet;
  519. EOF
  520. ;
  521. }
  522. }
  523. /**
  524. * Administrator Account definition screen
  525. */
  526. class WizStepAdminAccount extends WizardStep
  527. {
  528. public function GetTitle()
  529. {
  530. return 'Administrator Account';
  531. }
  532. public function GetPossibleSteps()
  533. {
  534. return array('WizStepMiscParams');
  535. }
  536. public function ProcessParams($bMoveForward = true)
  537. {
  538. $this->oWizard->SaveParameter('admin_user', '');
  539. $this->oWizard->SaveParameter('admin_pwd', '');
  540. $this->oWizard->SaveParameter('confirm_pwd', '');
  541. $this->oWizard->SaveParameter('admin_language', 'EN US');
  542. return array('class' => 'WizStepMiscParams', 'state' => '');
  543. }
  544. public function Display(WebPage $oPage)
  545. {
  546. $sAdminUser = $this->oWizard->GetParameter('admin_user', '');
  547. $sAdminPwd = $this->oWizard->GetParameter('admin_pwd', '');
  548. $sConfirmPwd = $this->oWizard->GetParameter('confirm_pwd', '');
  549. $sAdminLanguage = $this->oWizard->GetParameter('admin_language', 'EN US');
  550. $oPage->add('<h2>Definition of the Administrator Account</h2>');
  551. $oPage->add('<fieldset>');
  552. $oPage->add('<legend>Administrator Account</legend>');
  553. $oPage->add('<table>');
  554. $oPage->add('<tr><td>Login: </td><td><input id="admin_user" name="admin_user" type="text" size="25" maxlength="64" value="'.htmlentities($sAdminUser, ENT_QUOTES, 'UTF-8').'"></td><tr>');
  555. $oPage->add('<tr><td>Password: </td><td><input id="admin_pwd" name="admin_pwd" type="password" size="25" maxlength="64" value="'.htmlentities($sAdminPwd, ENT_QUOTES, 'UTF-8').'"></td><tr>');
  556. $oPage->add('<tr><td>Confirm password: </td><td><input id="confirm_pwd" name="confirm_pwd" type="password" size="25" maxlength="64" value="'.htmlentities($sConfirmPwd, ENT_QUOTES, 'UTF-8').'"></td><tr>');
  557. $sSourceDir = APPROOT.'dictionaries/';
  558. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  559. $oPage->add('<tr><td>Language: </td><td>');
  560. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'admin_language', $sAdminLanguage));
  561. $oPage->add('</td></tr>');
  562. $oPage->add('</table>');
  563. $oPage->add('</fieldset>');
  564. }
  565. }
  566. /**
  567. * Miscellaneous Parameters (URL, Sample Data)
  568. */
  569. class WizStepMiscParams extends WizardStep
  570. {
  571. public function GetTitle()
  572. {
  573. return 'Miscellaneous Parameters';
  574. }
  575. public function GetPossibleSteps()
  576. {
  577. return array('WizStepModulesChoice');
  578. }
  579. public function ProcessParams($bMoveForward = true)
  580. {
  581. $this->oWizard->SaveParameter('default_language', '');
  582. $this->oWizard->SaveParameter('application_url', '');
  583. $this->oWizard->SaveParameter('sample_data', 'yes');
  584. return array('class' => 'WizStepModulesChoice', 'state' => 'start_install');
  585. }
  586. public function Display(WebPage $oPage)
  587. {
  588. $sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
  589. $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot());
  590. $sSampleData = $this->oWizard->GetParameter('sample_data', 'yes');
  591. $oPage->add('<h2>Additional parameters</h2>');
  592. $oPage->add('<fieldset>');
  593. $oPage->add('<legend>Default Language</legend>');
  594. $oPage->add('<table>');
  595. $sSourceDir = APPROOT.'dictionaries/';
  596. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  597. $oPage->add('<tr><td>Default Language: </td><td>');
  598. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'default_language', $sDefaultLanguage));
  599. $oPage->add('</td></tr>');
  600. $oPage->add('</table>');
  601. $oPage->add('</fieldset>');
  602. $oPage->add('<fieldset>');
  603. $oPage->add('<legend>Application URL</legend>');
  604. $oPage->add('<table>');
  605. $oPage->add('<tr><td>URL: </td><td><input id="application_url" name="application_url" type="text" size="35" maxlength="1024" value="'.htmlentities($sApplicationURL, ENT_QUOTES, 'UTF-8').'"></td><tr>');
  606. $oPage->add('</table>');
  607. $oPage->add('</fieldset>');
  608. $oPage->add('<fieldset>');
  609. $oPage->add('<legend>Sample Data</legend>');
  610. $oPage->add('<table>');
  611. $sChecked = ($sSampleData == 'yes') ? ' checked ' : '';
  612. $oPage->p('<input id="sample_data_yes" name="sample_data" type="radio" value="yes"'.$sChecked.'><label for="sample_data_yes">&nbsp;I am installing a <b>demo or test</b> instance, populate the database with some demo data.');
  613. $sChecked = ($sSampleData == 'no') ? ' checked ' : '';
  614. $oPage->p('<input id="sample_data_no" name="sample_data" type="radio" value="no"'.$sChecked.'><label for="sample_data_no">&nbsp;I am installing a <b>production</b> instance, create an empty database to start from.');
  615. $oPage->add('</table>');
  616. $oPage->add('</fieldset>');
  617. }
  618. }
  619. /**
  620. * Choice of the modules to be installed
  621. */
  622. class WizStepModulesChoice extends WizardStep
  623. {
  624. public function GetTitle()
  625. {
  626. $aStepInfo = $this->GetStepInfo();
  627. $sTitle = isset($aStepInfo['title']) ? $aStepInfo['title'] : 'Modules selection';
  628. return $sTitle;
  629. }
  630. public function GetPossibleSteps()
  631. {
  632. return array('WizStepModulesChoice', 'WizStepSummary');
  633. }
  634. public function ProcessParams($bMoveForward = true)
  635. {
  636. // Accumualtes the selected modules:
  637. $index = $this->GetStepIndex();
  638. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  639. $aSelectedChoices = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  640. $aSelected = utils::ReadParam('choice', array());
  641. $aSelectedChoices[$index] = $aSelected;
  642. $this->oWizard->SetParameter('selected_components', json_encode($aSelectedChoices, JSON_FORCE_OBJECT));
  643. if ($this->GetStepInfo($index) == null)
  644. {
  645. throw new Exception('Internal error: invalid step "'.$index.'" for the choice of modules.');
  646. }
  647. else if ($bMoveForward)
  648. {
  649. if ($this->GetStepInfo(1 + $index) != null)
  650. {
  651. return array('class' => 'WizStepModulesChoice', 'state' => (1+$index));
  652. }
  653. else
  654. {
  655. // Exiting this step of the wizard, let's convert the selection into a list of modules
  656. $aModules = array();
  657. for($i = 0; $i <= $index; $i++)
  658. {
  659. $aStepInfo = $this->GetStepInfo($i);
  660. $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules);
  661. }
  662. $this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules)));
  663. return array('class' => 'WizStepSummary', 'state' => '');
  664. }
  665. }
  666. }
  667. public function Display(WebPage $oPage)
  668. {
  669. $this->DisplayStep($oPage);
  670. }
  671. protected function DisplayStep($oPage)
  672. {
  673. $aStepInfo = $this->GetStepInfo();
  674. $oPage->add_style("div.choice { margin: 0.5em;}");
  675. $oPage->add_style("div.description { margin-left: 2em; }");
  676. $oPage->add('<table><tr>');
  677. $sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
  678. if (!empty($sBannerPath))
  679. {
  680. if (substr($sBannerPath, 0, 1) == '/')
  681. {
  682. // absolute path, means relative to APPROOT
  683. $sBannerUrl = utils::GetDefaultUrlAppRoot().$sBannerPath;
  684. }
  685. else
  686. {
  687. // relative path: i.e. relative to the directory containing the XML file
  688. $sFullPath = dirname($this->GetSourceFilePath()).'/'.$sBannerPath;
  689. $sRealPath = realpath($sFullPath);
  690. $sBannerUrl = utils::GetDefaultUrlAppRoot().str_replace(APPROOT, '', $sRealPath);
  691. }
  692. $oPage->add('<td><img src="'.$sBannerUrl.'"/><td>');
  693. }
  694. $sDescription = isset($aStepInfo['description']) ? $aStepInfo['description'] : '';
  695. $oPage->add('<td>'.$sDescription.'<td>');
  696. $oPage->add('</tr></table>');
  697. // Build the default choices
  698. $aDefaults = array();
  699. $this->GetDefaults($aStepInfo, $aDefaults);
  700. $index = $this->GetStepIndex();
  701. // retrieve the saved selection
  702. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  703. $aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  704. if (!isset($aParameters[$index]))
  705. {
  706. $aParameters[$index] = $aDefaults;
  707. }
  708. $aSelectedComponents = $aParameters[$index];
  709. $oPage->add('<div style="max-height:250px;overflow:auto;border:#ccc 1px solid;">');
  710. $this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents);
  711. $oPage->add('</div>');
  712. }
  713. protected function GetDefaults($aInfo, &$aDefaults, $sParentId = '')
  714. {
  715. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  716. foreach($aOptions as $index => $aChoice)
  717. {
  718. $sChoiceId = $sParentId.'_'.$index;
  719. if (isset($aChoice['default']) && $aChoice['default'])
  720. {
  721. $aDefaults[$sChoiceId] = $sChoiceId;
  722. }
  723. if (isset($aChoice['sub_options']))
  724. {
  725. $this->GetDefaults($aChoice['sub_options'], $aDefaults, $sChoiceId);
  726. }
  727. $index++;
  728. }
  729. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  730. $sChoiceName = null;
  731. foreach($aAlternatives as $index => $aChoice)
  732. {
  733. $sChoiceId = $sParentId.'_'.$index;
  734. if ($sChoiceName == null)
  735. {
  736. $sChoiceName = $sChoiceId;
  737. }
  738. if (isset($aChoice['default']) && $aChoice['default'])
  739. {
  740. $aDefaults[$sChoiceName] = $sChoiceId;
  741. }
  742. if (isset($aChoice['sub_options']))
  743. {
  744. $this->GetDefaults($aChoice['sub_options'], $aDefaults, $sChoiceId);
  745. }
  746. $index++;
  747. }
  748. }
  749. /**
  750. * Converts the list of selected "choices" into a list of "modules": take into account the selected and the mandatory modules
  751. * @param hash $aInfo Info about the "choice" array('options' => array(...), 'alternatives' => array(...))
  752. * @param hash $aSelectedChoices List of selected choices array('name' => 'selected_value_id')
  753. * @param hash $aModules Return parameter: List of selected modules array('module_id' => true)
  754. * @param string $sParentId Used for recursion
  755. * @return void
  756. */
  757. protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '')
  758. {
  759. if ($sParentId == '')
  760. {
  761. // Check once (before recursing) that the hidden modules are selected
  762. foreach($this->AnalyzeInstallation() as $sModuleId => $aModule)
  763. {
  764. if ($sModuleId != ROOT_MODULE)
  765. {
  766. if (($aModule['category'] == 'authentication') || (!$aModule['visible']))
  767. {
  768. $aModules[$sModuleId] = true;
  769. }
  770. }
  771. }
  772. }
  773. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  774. foreach($aOptions as $index => $aChoice)
  775. {
  776. $sChoiceId = $sParentId.'_'.$index;
  777. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  778. (isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId)) )
  779. {
  780. if (isset($aChoice['modules']))
  781. {
  782. foreach($aChoice['modules'] as $sModuleId)
  783. {
  784. $aModules[$sModuleId] = true; // store the Id of the selected module
  785. }
  786. }
  787. // Recurse only for selected choices
  788. if (isset($aChoice['sub_options']))
  789. {
  790. $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId);
  791. }
  792. }
  793. $index++;
  794. }
  795. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  796. $sChoiceName = null;
  797. foreach($aAlternatives as $index => $aChoice)
  798. {
  799. $sChoiceId = $sParentId.'_'.$index;
  800. if ($sChoiceName == null)
  801. {
  802. $sChoiceName = $sChoiceId;
  803. }
  804. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  805. (isset($aSelectedChoices[$sChoiceName]) && ($aSelectedChoices[$sChoiceName] == $sChoiceId)) )
  806. {
  807. if (isset($aChoice['modules']))
  808. {
  809. foreach($aChoice['modules'] as $sModuleId)
  810. {
  811. $aModules[$sModuleId] = true; // store the Id of the selected module
  812. }
  813. }
  814. // Recurse only for selected choices
  815. if (isset($aChoice['sub_options']))
  816. {
  817. $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId);
  818. }
  819. }
  820. $index++;
  821. }
  822. }
  823. protected function GetStepIndex()
  824. {
  825. switch($this->sCurrentState)
  826. {
  827. case 'start_install':
  828. case 'start_upgrade':
  829. $index = 0;
  830. break;
  831. default:
  832. $index = (integer)$this->sCurrentState;
  833. }
  834. return $index;
  835. }
  836. protected function GetStepInfo($idx = null)
  837. {
  838. $aStepInfo = null;
  839. if ($idx === null)
  840. {
  841. $index = $this->GetStepIndex();
  842. }
  843. else
  844. {
  845. $index = $idx;
  846. }
  847. if (@file_exists($this->GetSourceFilePath()))
  848. {
  849. $aParams = new XMLParameters($this->GetSourceFilePath());
  850. $aSteps = $aParams->Get('steps', array());
  851. if (array_key_exists($index, $aSteps))
  852. {
  853. $aStepInfo = $aSteps[$index];
  854. }
  855. }
  856. else if ($idx == 0)
  857. {
  858. // No wizard configuration provided, build a standard one:
  859. $aAvailableModules = $this->AnalyzeInstallation();
  860. $aStepInfo = array(
  861. 'title' => 'Modules Selection',
  862. 'description' => '<h2>Select the modules to install. You can launch the installation again to install new modules, but you cannot remove already installed modules.</h2>',
  863. 'banner' => '/images/modules.png',
  864. 'options' => array(),
  865. );
  866. try
  867. {
  868. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  869. }
  870. catch(Exception $e)
  871. {
  872. $sDefaultAppPath = '..';
  873. }
  874. foreach($aAvailableModules as $sModuleId => $aModule)
  875. {
  876. if ($sModuleId == ROOT_MODULE) continue; // Convention: the version number of the application is stored as a module named ROOT_MODULE
  877. $sModuleLabel = $aModule['label'];
  878. $sModuleHelp = $aModule['doc.more_information'];
  879. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"$sDefaultAppPath{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  880. if (($aModule['category'] != 'authentication') && ($aModule['visible']))
  881. {
  882. $aStepInfo['options'][$index] = array(
  883. 'title' => $sModuleLabel,
  884. 'description' => '',
  885. 'more_info' => $sMoreInfo,
  886. 'default' => true, // by default offer to install all modules
  887. 'modules' => array($sModuleId),
  888. );
  889. switch($aModule['install']['flag'])
  890. {
  891. case MODULE_ACTION_MANDATORY:
  892. $aStepInfo['options'][$index]['mandatory'] = true;
  893. break;
  894. }
  895. $index++;
  896. }
  897. }
  898. }
  899. return $aStepInfo;
  900. }
  901. protected function AnalyzeInstallation()
  902. {
  903. require_once(APPROOT.'/setup/moduleinstaller.class.inc.php');
  904. $oConfig = new Config();
  905. $aParamValues = array(
  906. 'db_server' => $this->oWizard->GetParameter('db_server', ''),
  907. 'db_user' => $this->oWizard->GetParameter('db_user', ''),
  908. 'db_pwd' => $this->oWizard->GetParameter('db_server', ''),
  909. 'db_name' => $this->oWizard->GetParameter('db_name', ''),
  910. 'db_prefix' => $this->oWizard->GetParameter('db_prefix', ''),
  911. 'source_dir' => APPROOT.'datamodel',
  912. );
  913. $oConfig->UpdateFromParams($aParamValues, 'datamodel');
  914. $oProductionEnv = new RunTimeEnvironment();
  915. $oConfig = new Config();
  916. $aAvailableModules = $oProductionEnv->AnalyzeInstallation($oConfig, 'datamodel');
  917. return $aAvailableModules;
  918. }
  919. protected function DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $sParentId = '')
  920. {
  921. $aOptions = isset($aStepInfo['options']) ? $aStepInfo['options'] : array();
  922. $aAlternatives = isset($aStepInfo['alternatives']) ? $aStepInfo['alternatives'] : array();
  923. $index = 0;
  924. foreach($aOptions as $index => $aChoice)
  925. {
  926. $sAttributes = '';
  927. $sChoiceId = $sParentId.'_'.$index;
  928. if (isset($aChoice['mandatory']) && $aChoice['mandatory'])
  929. {
  930. $oPage->add('<div class="choice"><input id="choice'.$sChoiceId.'" checked disabled type="checkbox"'.$sAttributes.'/><input type="hidden" name="choice['.$sChoiceId.']" value="'.$sChoiceId.'">&nbsp;');
  931. }
  932. else if (isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId))
  933. {
  934. $oPage->add('<div class="choice"><input id="choice'.$sChoiceId.'" name="choice['.$sChoiceId.']" type="checkbox" checked value="'.$sChoiceId.'"/>&nbsp;');
  935. }
  936. else
  937. {
  938. $oPage->add('<div class="choice"><input id="choice'.$sChoiceId.'" name="choice['.$sChoiceId.']" type="checkbox" value="'.$sChoiceId.'"/>&nbsp;');
  939. }
  940. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $sChoiceId);
  941. $oPage->add('</div>');
  942. $index++;
  943. }
  944. $sChoiceName = null;
  945. foreach($aAlternatives as $index => $aChoice)
  946. {
  947. $sAttributes = '';
  948. $sChoiceId = $sParentId.'_'.$index;
  949. if ($sChoiceName == null)
  950. {
  951. $sChoiceName = $sChoiceId; // All radios share the same name
  952. }
  953. if (isset($aSelectedComponents[$sChoiceName]) && ($aSelectedComponents[$sChoiceName] == $sChoiceId))
  954. {
  955. $sAttributes = ' checked ';
  956. }
  957. $oPage->add('<div class="choice"><input id="choice'.$sChoiceId.'" name="choice['.$sChoiceName.']" type="radio"'.$sAttributes.' value="'.$sChoiceId.'"/>&nbsp;');
  958. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $sChoiceId);
  959. $oPage->add('</div>');
  960. $index++;
  961. }
  962. }
  963. protected function DisplayChoice($oPage, $aChoice, $aSelectedComponents, $sChoiceId)
  964. {
  965. $oPage->add('<label for="choice'.$sChoiceId.'"><b>'.htmlentities($aChoice['title'], ENT_QUOTES, 'UTF-8').'</b></label>');
  966. $sDescription = isset($aChoice['description']) ? htmlentities($aChoice['description'], ENT_QUOTES, 'UTF-8') : '';
  967. $oPage->add('<div class="description">'.$sDescription);
  968. if (isset($aChoice['sub_options']))
  969. {
  970. $this->DisplayOptions($oPage, $aChoice['sub_options'], $aSelectedComponents, $sChoiceId);
  971. }
  972. $oPage->add('</div>');
  973. }
  974. protected function GetSourceFilePath()
  975. {
  976. return APPROOT.'datamodel/installation.xml';
  977. }
  978. }
  979. /**
  980. * Summary of the installation tasks
  981. */
  982. class WizStepSummary extends WizardStep
  983. {
  984. public function GetTitle()
  985. {
  986. return 'Installation summary';
  987. }
  988. public function GetPossibleSteps()
  989. {
  990. return array('WizStepDone');
  991. }
  992. /**
  993. * Returns the label for the " Next >> " button
  994. * @return string The label for the button
  995. */
  996. public function GetNextButtonLabel()
  997. {
  998. return ' Install ! ';
  999. }
  1000. public function ProcessParams($bMoveForward = true)
  1001. {
  1002. return array('class' => 'WizStepDone', 'state' => '');
  1003. }
  1004. public function Display(WebPage $oPage)
  1005. {
  1006. $oPage->add('<ul>Selected modules:');
  1007. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'));
  1008. sort($aSelectedModules);
  1009. foreach($aSelectedModules as $sModuleId)
  1010. {
  1011. $oPage->add('<li>'.$sModuleId.'</li>');
  1012. }
  1013. $oPage->add('</ul>');
  1014. $oPage->add('<div id="percentage"> Ready to Start...<br/></div>');
  1015. $oPage->add_ready_script(
  1016. <<<EOF
  1017. $("#btn_next").bind("click.install", function(event){ $(this).attr("disabled", "disabled"); event.preventDefault(); ExecuteStep(""); });
  1018. $("#wiz_form").data("installation_status", "not started")
  1019. EOF
  1020. );
  1021. // Prepare the parameters to execute the installation asynchronously
  1022. $sMode = $this->oWizard->GetParameter('mode', 'install');
  1023. $sBackupDestination = '';
  1024. $sConfigurationFile = '';
  1025. $sSourceEnvironment = 'production';
  1026. $sDBName = $this->oWizard->GetParameter('db_name');
  1027. if ($sMode == 'upgrade')
  1028. {
  1029. if ($this->oWizard->GetParameter('db_backup', false))
  1030. {
  1031. $sSourceDir = $this->oWizard->GetParameter('source_dir', '');
  1032. if (!empty($sSourceDir))
  1033. {
  1034. $aPreviousInstance = SetupUtils::GetPreviousInstance($sSourceDir);
  1035. if ($aPreviousInstance['found'])
  1036. {
  1037. $sConfigurationFile = $aPreviousInstance['configuration_file'];
  1038. $sSourceEnvironment = $aPreviousInstance['source_environment'];
  1039. }
  1040. }
  1041. }
  1042. }
  1043. else
  1044. {
  1045. $sDBNewName = $this->oWizard->GetParameter('db_new_name', '');
  1046. if ($sDBNewName != '')
  1047. {
  1048. $sDBName = $sDBNewName; // Database will be created
  1049. }
  1050. }
  1051. $aInstallParams = array (
  1052. 'mode' => $sMode,
  1053. 'preinstall' => array (
  1054. 'copies' => array (
  1055. // 0 => array (
  1056. // 'source' => '',
  1057. // 'destination' => '',
  1058. // ),
  1059. ),
  1060. 'backup' => array (
  1061. 'destination' => $sBackupDestination,
  1062. 'configuration_file' => $sConfigurationFile,
  1063. ),
  1064. ),
  1065. 'source_dir' => 'datamodel',
  1066. 'source_env' => $sSourceEnvironment,
  1067. 'target_env' => 'production',
  1068. 'workspace_dir' => '',
  1069. 'database' => array (
  1070. 'server' => $this->oWizard->GetParameter('db_server'),
  1071. 'user' => $this->oWizard->GetParameter('db_user'),
  1072. 'pwd' => $this->oWizard->GetParameter('db_pwd'),
  1073. 'name' => $sDBName,
  1074. 'prefix' => $this->oWizard->GetParameter('db_prefix'),
  1075. ),
  1076. 'url' => $this->oWizard->GetParameter('application_url'),
  1077. 'admin_account' => array (
  1078. 'user' => $this->oWizard->GetParameter('admin_user'),
  1079. 'pwd' => $this->oWizard->GetParameter('admin_pwd'),
  1080. 'language' => $this->oWizard->GetParameter('admin_language'),
  1081. ),
  1082. 'language' => $this->oWizard->GetParameter('default_language'),
  1083. 'selected_modules' => $aSelectedModules,
  1084. 'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false ,
  1085. 'options' => json_decode($this->oWizard->GetParameter('misc_options')),
  1086. );
  1087. $sJSONData = json_encode($aInstallParams);
  1088. $oPage->add('<input type="hidden" id="installer_parameters" value="'.htmlentities($sJSONData, ENT_QUOTES, 'UTF-8').'"/>');
  1089. }
  1090. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  1091. {
  1092. $oParameters = new PHPParameters();
  1093. $sStep = $aParameters['installer_step'];
  1094. $sJSONParameters = $aParameters['installer_config'];
  1095. $oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
  1096. $oInstaller = new ApplicationInstaller($oParameters);
  1097. $aRes = $oInstaller->ExecuteStep($sStep);
  1098. if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != ''))
  1099. {
  1100. // Tell the web page to move the progress bar and to launch the next step
  1101. $oPage->add_ready_script(
  1102. <<<EOF
  1103. $("#wiz_form").data("installation_status", "running");
  1104. WizardUpdateButtons();
  1105. $("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
  1106. ExecuteStep('{$aRes['next-step']}');
  1107. EOF
  1108. );
  1109. }
  1110. else if ($aRes['next-step'] == '')
  1111. {
  1112. // Installation complete, move to the next step of the wizard
  1113. $oPage->add_ready_script(
  1114. <<<EOF
  1115. $("#wiz_form").data("installation_status", "completed");
  1116. WizardUpdateButtons();
  1117. EOF
  1118. );
  1119. }
  1120. else
  1121. {
  1122. $oPage->add_ready_script(
  1123. <<<EOF
  1124. $("#wiz_form").data("installation_status", "error");
  1125. WizardUpdateButtons();
  1126. $("#percentage").html('<b>Error</b><br/>{$aRes['message']}');
  1127. EOF
  1128. );
  1129. }
  1130. }
  1131. /**
  1132. * Tells whether the "Next" button should be enabled interactively
  1133. * @return string A piece of javascript code returning either true or false
  1134. */
  1135. public function JSCanMoveForward()
  1136. {
  1137. return 'return ($("#wiz_form").data("installation_status") === "not started");';
  1138. }
  1139. /**
  1140. * Tells whether the "Next" button should be enabled interactively
  1141. * @return string A piece of javascript code returning either true or false
  1142. */
  1143. public function JSCanMoveBackward()
  1144. {
  1145. return 'var sStatus = $("#wiz_form").data("installation_status"); return ((sStatus === "not started") || (sStatus === "error"));';
  1146. }
  1147. }
  1148. /**
  1149. * Summary of the installation tasks
  1150. */
  1151. class WizStepDone extends WizardStep
  1152. {
  1153. public function GetTitle()
  1154. {
  1155. return 'Done';
  1156. }
  1157. public function GetPossibleSteps()
  1158. {
  1159. return array();
  1160. }
  1161. public function ProcessParams($bMoveForward = true)
  1162. {
  1163. return array('class' => '', 'state' => '');
  1164. }
  1165. public function Display(WebPage $oPage)
  1166. {
  1167. $oPage->p('Installation Completed.');
  1168. }
  1169. public function CanMoveForward()
  1170. {
  1171. return false;
  1172. }
  1173. public function CanMoveBackward()
  1174. {
  1175. return false;
  1176. }
  1177. }