wizardsteps.class.inc.php 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  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. $sDBName = $this->oWizard->GetParameter('db_name');
  1026. if ($sMode == 'upgrade')
  1027. {
  1028. if ($this->oWizard->GetParameter('db_backup', false))
  1029. {
  1030. $sSourceDir = $this->oWizard->GetParameter('source_dir', '');
  1031. if (!empty($sSourceDir))
  1032. {
  1033. $aPreviousInstance = SetupUtils::GetPreviousInstance($sSourceDir);
  1034. if ($aPreviousInstance['found'])
  1035. {
  1036. $sConfigurationFile = $aPreviousInstance['configuration_file'];
  1037. }
  1038. }
  1039. }
  1040. }
  1041. else
  1042. {
  1043. $sDBNewName = $this->oWizard->GetParameter('db_new_name', '');
  1044. if ($sDBNewName != '')
  1045. {
  1046. $sDBName = $sDBNewName; // Database will be created
  1047. }
  1048. }
  1049. $aInstallParams = array (
  1050. 'mode' => $sMode,
  1051. 'preinstall' => array (
  1052. 'copies' => array (
  1053. // 0 => array (
  1054. // 'source' => '',
  1055. // 'destination' => '',
  1056. // ),
  1057. ),
  1058. ),
  1059. 'source_dir' => 'datamodel',
  1060. 'target_env' => 'production',
  1061. 'workspace_dir' => '',
  1062. 'database' => array (
  1063. 'server' => $this->oWizard->GetParameter('db_server'),
  1064. 'user' => $this->oWizard->GetParameter('db_user'),
  1065. 'pwd' => $this->oWizard->GetParameter('db_pwd'),
  1066. 'name' => $sDBName,
  1067. 'prefix' => $this->oWizard->GetParameter('db_prefix'),
  1068. ),
  1069. 'url' => $this->oWizard->GetParameter('application_url'),
  1070. 'admin_account' => array (
  1071. 'user' => $this->oWizard->GetParameter('admin_user'),
  1072. 'pwd' => $this->oWizard->GetParameter('admin_pwd'),
  1073. 'language' => $this->oWizard->GetParameter('admin_language'),
  1074. ),
  1075. 'language' => $this->oWizard->GetParameter('default_language'),
  1076. 'selected_modules' => $aSelectedModules,
  1077. 'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false ,
  1078. 'options' => json_decode($this->oWizard->GetParameter('misc_options')),
  1079. );
  1080. if ($sBackupDestination != '')
  1081. {
  1082. $aInstallParams['backup'] = array (
  1083. 'destination' => $sBackupDestination,
  1084. 'configuration_file' => $sConfigurationFile,
  1085. );
  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. }