wizardsteps.class.inc.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  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. $aBackupChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath);
  213. $bCanBackup = true;
  214. $sMySQLDumpMessage = '';
  215. foreach($aBackupChecks as $oCheck)
  216. {
  217. if ($oCheck->iSeverity == CheckResult::ERROR)
  218. {
  219. $bCanBackup = false;
  220. $sMySQLDumpMessage .= '<img src="../images/error.png"/>&nbsp;<b> Warning:</b> '.$oCheck->sLabel;
  221. }
  222. else
  223. {
  224. $sMySQLDumpMessage .= '<img src="../images/validation_ok.png"/> '.$oCheck->sLabel.' ';
  225. }
  226. }
  227. $sChecked = ($bCanBackup && ($bDBBackup == 'install')) ? ' checked ' : '';
  228. $sDisabled = $bCanBackup ? '' : ' disabled ';
  229. $oPage->add('<tr><td colspan="2"><input id="db_backup" type="checkbox" name="db_backup"'.$sChecked.$sDisabled.' value="1"/>&nbsp;Backup the '.ITOP_APPLICATION.' database before upgrading</td></tr>');
  230. $oPage->add('<tr><td colspan="2">Save the backup to: <input id="db_backup_path" type="text" name="db_backup_path" '.$sDisabled.'value="'.htmlentities($sDBBackupPath, ENT_QUOTES, 'UTF-8').'" size="25"/></td></tr>');
  231. $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
  232. $sMessage = '';
  233. if ($fFreeSpace !== false)
  234. {
  235. $sMessage .= SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath);
  236. }
  237. $oPage->add('<tr><td colspan="2">');
  238. $oPage->add($sMySQLDumpMessage.'<br/><span id="backup_info" style="font-size:small;color:#696969;">'.$sMessage.'</span></td></tr>');
  239. $oPage->add('</table>');
  240. //$oPage->add('</fieldset>');
  241. $oPage->add_ready_script(
  242. <<<EOF
  243. $("#radio_update").bind('change', function() { if (this.checked ) { $('#upgrade_info').show(); WizardUpdateButtons(); } else { $('#upgrade_info').hide(); } });
  244. $("#radio_install").bind('change', function() { if (this.checked ) { $('#upgrade_info').hide(); WizardUpdateButtons(); } else { $('#upgrade_info').show(); } });
  245. $("#source_dir").bind('change keyup', function() { WizardAsyncAction('check_path', { source_dir: $('#source_dir').val() }); });
  246. $("#db_backup_path").bind('change keyup', function() { WizardAsyncAction('check_backup', { db_backup_path: $('#db_backup_path').val() }); });
  247. EOF
  248. );
  249. }
  250. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  251. {
  252. switch($sCode)
  253. {
  254. case 'check_path':
  255. $sSourceDir = $aParameters['source_dir'];
  256. $aPreviousInstance = SetupUtils::GetPreviousInstance($sSourceDir);
  257. if ($aPreviousInstance['found'])
  258. {
  259. $sDBServer = htmlentities($aPreviousInstance['db_server'], ENT_QUOTES, 'UTF-8');
  260. $sDBUser = htmlentities($aPreviousInstance['db_user'], ENT_QUOTES, 'UTF-8');
  261. $sDBPwd = htmlentities($aPreviousInstance['db_pwd'], ENT_QUOTES, 'UTF-8');
  262. $sDBName = htmlentities($aPreviousInstance['db_name'], ENT_QUOTES, 'UTF-8');
  263. $sDBPrefix = htmlentities($aPreviousInstance['db_prefix'], ENT_QUOTES, 'UTF-8');
  264. $oPage->add_ready_script(
  265. <<<EOF
  266. $("#db_server").val('$sDBServer');
  267. $("#db_user").val('$sDBUser');
  268. $("#db_pwd").val('$sDBPwd');
  269. $("#db_name").val('$sDBName');
  270. $("#db_prefix").val('$sDBPrefix');
  271. EOF
  272. );
  273. }
  274. break;
  275. case 'check_db':
  276. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  277. break;
  278. case 'check_backup':
  279. $sDBBackupPath = $aParameters['db_backup_path'];
  280. $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
  281. if ($fFreeSpace !== false)
  282. {
  283. $sMessage = htmlentities(SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath), ENT_QUOTES, 'UTF-8');
  284. $oPage->add_ready_script(
  285. <<<EOF
  286. $("#backup_info").html('$sMessage');
  287. EOF
  288. );
  289. }
  290. else
  291. {
  292. $oPage->add_ready_script(
  293. <<<EOF
  294. $("#backup_info").html('');
  295. EOF
  296. );
  297. }
  298. break;
  299. }
  300. }
  301. /**
  302. * Tells whether the "Next" button should be enabled interactively
  303. * @return string A piece of javascript code returning either true or false
  304. */
  305. public function JSCanMoveForward()
  306. {
  307. return
  308. <<<EOF
  309. if ($("#radio_install").attr("checked") == "checked")
  310. {
  311. ValidateField("db_name", false);
  312. ValidateField("db_new_name", false);
  313. ValidateField("db_prefix", false);
  314. return true;
  315. }
  316. else
  317. {
  318. var bRet = ($("#wiz_form").data("db_connection") !== "error");
  319. bRet = ValidateField("db_name", true) && bRet;
  320. bRet = ValidateField("db_new_name", true) && bRet;
  321. bRet = ValidateField("db_prefix", true) && bRet;
  322. return bRet;
  323. }
  324. EOF
  325. ;
  326. }
  327. }
  328. /**
  329. * Upgrade information
  330. */
  331. class WizStepDetectedInfo extends WizardStep
  332. {
  333. public function GetTitle()
  334. {
  335. return 'Detected Info';
  336. }
  337. public function GetPossibleSteps()
  338. {
  339. return array('WizStepUpgradeKeep', 'WizStepUpgradeAuto', 'WizStepLicense2');
  340. }
  341. public function ProcessParams($bMoveForward = true)
  342. {
  343. return array('class' => 'WizStepLicense2', 'state' => '');
  344. }
  345. public function Display(WebPage $oPage)
  346. {
  347. $oPage->p('Info about the detected version');
  348. }
  349. }
  350. /**
  351. * Keep or Upgrade choice
  352. */
  353. class WizStepUpgradeKeep extends WizardStep
  354. {
  355. public function GetTitle()
  356. {
  357. return 'Keep or Upgrade';
  358. }
  359. public function GetPossibleSteps()
  360. {
  361. return array('WizStepModulesChoice');
  362. }
  363. public function ProcessParams($bMoveForward = true)
  364. {
  365. return array('class' => 'WizStepModulesChoice', 'state' => 'start_upgrade');
  366. }
  367. public function Display(WebPage $oPage)
  368. {
  369. $oPage->p('Keep or Upgrade the data model');
  370. }
  371. }
  372. /**
  373. * Automatic Upgrade info
  374. */
  375. class WizStepUpgradeAuto extends WizardStep
  376. {
  377. public function GetTitle()
  378. {
  379. return 'Upgrade Information';
  380. }
  381. public function GetPossibleSteps()
  382. {
  383. return array('WizStepModulesChoice');
  384. }
  385. public function ProcessParams($bMoveForward = true)
  386. {
  387. return array('class' => 'WizStepModulesChoice', 'state' => 'start_upgrade');
  388. }
  389. public function Display(WebPage $oPage)
  390. {
  391. $oPage->p('Automatic Upgrade information');
  392. }
  393. }
  394. /**
  395. * License acceptation screen
  396. */
  397. class WizStepLicense extends WizardStep
  398. {
  399. public function GetTitle()
  400. {
  401. return 'License Agreement';
  402. }
  403. public function GetPossibleSteps()
  404. {
  405. return array('WizStepDBParams');
  406. }
  407. public function ProcessParams($bMoveForward = true)
  408. {
  409. $this->oWizard->SaveParameter('accept_license', 'no');
  410. return array('class' => 'WizStepDBParams', 'state' => '');
  411. }
  412. public function Display(WebPage $oPage)
  413. {
  414. $aLicenses = array();
  415. foreach (glob(APPROOT.'setup/licenses/*.xml') as $sFile)
  416. {
  417. $oXml = simplexml_load_file($sFile);
  418. foreach($oXml->license as $oLicense)
  419. {
  420. $aLicenses[] = $oLicense;
  421. }
  422. }
  423. $oPage->add('<h2>Licenses agreements for the components of '.ITOP_APPLICATION.'</h2>');
  424. $oPage->add_style('div a.no-arrow { background:transparent; padding-left:0;}');
  425. $oPage->add_style('.toggle { cursor:pointer; text-decoration:underline; color:#1C94C4; }');
  426. $oPage->add('<fieldset>');
  427. $oPage->add('<legend>Components of '.ITOP_APPLICATION.'</legend>');
  428. $oPage->add('<ul>');
  429. foreach($aLicenses as $index => $oLicense)
  430. {
  431. $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>)');
  432. $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>');
  433. $oPage->add_ready_script('$(".license_text a").attr("target", "_blank").addClass("no-arrow");');
  434. $oPage->add_ready_script('$("#toggle_'.$index.'").click( function() { $("#license_'.$index.'").toggle(); } );');
  435. }
  436. $oPage->add('</ul>');
  437. $oPage->add('</fieldset>');
  438. $sChecked = ($this->oWizard->GetParameter('accept_license', 'no') == 'yes') ? ' checked ' : '';
  439. $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>');
  440. $oPage->add_ready_script('$("#accept").bind("click change", function() { WizardUpdateButtons(); });');
  441. }
  442. /**
  443. * Tells whether the "Next" button should be enabled interactively
  444. * @return string A piece of javascript code returning either true or false
  445. */
  446. public function JSCanMoveForward()
  447. {
  448. return 'return ($("#accept").attr("checked") === "checked");';
  449. }
  450. }
  451. /**
  452. * License acceptation screen (when upgrading)
  453. */
  454. class WizStepLicense2 extends WizStepLicense
  455. {
  456. public function GetPossibleSteps()
  457. {
  458. return array('WizStepUpgradeKeep', 'WizStepUpgradeAuto');
  459. }
  460. public function ProcessParams($bMoveForward = true)
  461. {
  462. return array('class' => 'WizStepUpgradeAuto', 'state' => '');
  463. }
  464. }
  465. /**
  466. * Database Connection parameters screen
  467. */
  468. class WizStepDBParams extends WizardStep
  469. {
  470. public function GetTitle()
  471. {
  472. return 'Database Configuration';
  473. }
  474. public function GetPossibleSteps()
  475. {
  476. return array('WizStepAdminAccount');
  477. }
  478. public function ProcessParams($bMoveForward = true)
  479. {
  480. $this->oWizard->SaveParameter('db_server', '');
  481. $this->oWizard->SaveParameter('db_user', '');
  482. $this->oWizard->SaveParameter('db_pwd', '');
  483. $this->oWizard->SaveParameter('db_name', '');
  484. $this->oWizard->SaveParameter('db_prefix', '');
  485. $this->oWizard->SaveParameter('new_db_name', '');
  486. $this->oWizard->SaveParameter('create_db', '');
  487. $this->oWizard->SaveParameter('db_new_name', '');
  488. return array('class' => 'WizStepAdminAccount', 'state' => '');
  489. }
  490. public function Display(WebPage $oPage)
  491. {
  492. $oPage->add('<h2>Configuration of the database connection:</h2>');
  493. $sDBServer = $this->oWizard->GetParameter('db_server', '');
  494. $sDBUser = $this->oWizard->GetParameter('db_user', '');
  495. $sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
  496. $sDBName = $this->oWizard->GetParameter('db_name', '');
  497. $sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
  498. $sNewDBName = $this->oWizard->GetParameter('db_new_name', false);
  499. $oPage->add('<table>');
  500. SetupUtils::DisplayDBParameters($oPage, true, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName);
  501. $oPage->add('</table>');
  502. $sCreateDB = $this->oWizard->GetParameter('create_db', 'no');
  503. if ($sCreateDB == 'no')
  504. {
  505. $oPage->add_ready_script('$("#existing_db").attr("checked", "checked");');
  506. }
  507. else
  508. {
  509. $oPage->add_ready_script('$("#create_db").attr("checked", "checked");');
  510. }
  511. }
  512. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  513. {
  514. switch($sCode)
  515. {
  516. case 'check_db':
  517. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  518. break;
  519. }
  520. }
  521. /**
  522. * Tells whether the "Next" button should be enabled interactively
  523. * @return string A piece of javascript code returning either true or false
  524. */
  525. public function JSCanMoveForward()
  526. {
  527. return
  528. <<<EOF
  529. if ($("#wiz_form").data("db_connection") === "error") return false;
  530. var bRet = true;
  531. bRet = ValidateField("db_name", true) && bRet;
  532. bRet = ValidateField("db_new_name", true) && bRet;
  533. bRet = ValidateField("db_prefix", true) && bRet;
  534. return bRet;
  535. EOF
  536. ;
  537. }
  538. }
  539. /**
  540. * Administrator Account definition screen
  541. */
  542. class WizStepAdminAccount extends WizardStep
  543. {
  544. public function GetTitle()
  545. {
  546. return 'Administrator Account';
  547. }
  548. public function GetPossibleSteps()
  549. {
  550. return array('WizStepMiscParams');
  551. }
  552. public function ProcessParams($bMoveForward = true)
  553. {
  554. $this->oWizard->SaveParameter('admin_user', '');
  555. $this->oWizard->SaveParameter('admin_pwd', '');
  556. $this->oWizard->SaveParameter('confirm_pwd', '');
  557. $this->oWizard->SaveParameter('admin_language', 'EN US');
  558. return array('class' => 'WizStepMiscParams', 'state' => '');
  559. }
  560. public function Display(WebPage $oPage)
  561. {
  562. $sAdminUser = $this->oWizard->GetParameter('admin_user', 'admin');
  563. $sAdminPwd = $this->oWizard->GetParameter('admin_pwd', '');
  564. $sConfirmPwd = $this->oWizard->GetParameter('confirm_pwd', '');
  565. $sAdminLanguage = $this->oWizard->GetParameter('admin_language', 'EN US');
  566. $oPage->add('<h2>Definition of the Administrator Account</h2>');
  567. $oPage->add('<fieldset>');
  568. $oPage->add('<legend>Administrator Account</legend>');
  569. $oPage->add('<table>');
  570. $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').'"><span id="v_admin_user"/></td><tr>');
  571. $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').'"><span id="v_admin_pwd"/></td><tr>');
  572. $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>');
  573. $sSourceDir = APPROOT.'dictionaries/';
  574. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  575. $oPage->add('<tr><td>Language: </td><td>');
  576. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'admin_language', $sAdminLanguage));
  577. $oPage->add('</td></tr>');
  578. $oPage->add('</table>');
  579. $oPage->add('</fieldset>');
  580. $oPage->add_ready_script(
  581. <<<EOF
  582. $('#admin_user').bind('change keyup', function() { WizardUpdateButtons(); } );
  583. $('#admin_pwd').bind('change keyup', function() { WizardUpdateButtons(); } );
  584. $('#confirm_pwd').bind('change keyup', function() { WizardUpdateButtons(); } );
  585. EOF
  586. );
  587. }
  588. /**
  589. * Tells whether the "Next" button should be enabled interactively
  590. * @return string A piece of javascript code returning either true or false
  591. */
  592. public function JSCanMoveForward()
  593. {
  594. return
  595. <<<EOF
  596. bRet = ($('#admin_user').val() != '');
  597. if (!bRet)
  598. {
  599. $("#v_admin_user").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  600. }
  601. else
  602. {
  603. $("#v_admin_user").html('');
  604. }
  605. bPasswordsMatch = ($('#admin_pwd').val() == $('#confirm_pwd').val());
  606. if (!bPasswordsMatch)
  607. {
  608. $('#v_admin_pwd').html('<img src="../images/validation_error.png" title="Retyped password do not match"/>');
  609. }
  610. else
  611. {
  612. $('#v_admin_pwd').html('');
  613. }
  614. bRet = bPasswordsMatch && bRet;
  615. return bRet;
  616. EOF
  617. ;
  618. }}
  619. /**
  620. * Miscellaneous Parameters (URL, Sample Data)
  621. */
  622. class WizStepMiscParams extends WizardStep
  623. {
  624. public function GetTitle()
  625. {
  626. return 'Miscellaneous Parameters';
  627. }
  628. public function GetPossibleSteps()
  629. {
  630. return array('WizStepModulesChoice');
  631. }
  632. public function ProcessParams($bMoveForward = true)
  633. {
  634. $this->oWizard->SaveParameter('default_language', '');
  635. $this->oWizard->SaveParameter('application_url', '');
  636. $this->oWizard->SaveParameter('sample_data', 'yes');
  637. return array('class' => 'WizStepModulesChoice', 'state' => 'start_install');
  638. }
  639. public function Display(WebPage $oPage)
  640. {
  641. $sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
  642. $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot());
  643. $sSampleData = $this->oWizard->GetParameter('sample_data', 'yes');
  644. $oPage->add('<h2>Additional parameters</h2>');
  645. $oPage->add('<fieldset>');
  646. $oPage->add('<legend>Default Language</legend>');
  647. $oPage->add('<table>');
  648. $sSourceDir = APPROOT.'dictionaries/';
  649. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  650. $oPage->add('<tr><td>Default Language: </td><td>');
  651. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'default_language', $sDefaultLanguage));
  652. $oPage->add('</td></tr>');
  653. $oPage->add('</table>');
  654. $oPage->add('</fieldset>');
  655. $oPage->add('<fieldset>');
  656. $oPage->add('<legend>Application URL</legend>');
  657. $oPage->add('<table>');
  658. $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').'"><span id="v_application_url"/></td><tr>');
  659. $oPage->add('<tr><td colspan="2">Change the value above if the end-users will be accessing the application by another path due to a specific configuration of the web server.</td><tr>');
  660. $oPage->add('</table>');
  661. $oPage->add('</fieldset>');
  662. $oPage->add('<fieldset>');
  663. $oPage->add('<legend>Sample Data</legend>');
  664. $oPage->add('<table>');
  665. $sChecked = ($sSampleData == 'yes') ? ' checked ' : '';
  666. $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.');
  667. $sChecked = ($sSampleData == 'no') ? ' checked ' : '';
  668. $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.');
  669. $oPage->add('</table>');
  670. $oPage->add('</fieldset>');
  671. $oPage->add_ready_script(
  672. <<<EOF
  673. $('#application_url').bind('change keyup', function() { WizardUpdateButtons(); } );
  674. EOF
  675. );
  676. }
  677. /**
  678. * Tells whether the "Next" button should be enabled interactively
  679. * @return string A piece of javascript code returning either true or false
  680. */
  681. public function JSCanMoveForward()
  682. {
  683. return
  684. <<<EOF
  685. bRet = ($('#application_url').val() != '');
  686. if (!bRet)
  687. {
  688. $("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  689. }
  690. else
  691. {
  692. $("#v_application_url").html('');
  693. }
  694. return bRet;
  695. EOF
  696. ;
  697. }
  698. }
  699. /**
  700. * Choice of the modules to be installed
  701. */
  702. class WizStepModulesChoice extends WizardStep
  703. {
  704. public function GetTitle()
  705. {
  706. $aStepInfo = $this->GetStepInfo();
  707. $sTitle = isset($aStepInfo['title']) ? $aStepInfo['title'] : 'Modules selection';
  708. return $sTitle;
  709. }
  710. public function GetPossibleSteps()
  711. {
  712. return array('WizStepModulesChoice', 'WizStepSummary');
  713. }
  714. public function ProcessParams($bMoveForward = true)
  715. {
  716. // Accumulates the selected modules:
  717. $index = $this->GetStepIndex();
  718. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  719. $aSelectedChoices = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  720. $aSelected = utils::ReadParam('choice', array());
  721. $aSelectedChoices[$index] = $aSelected;
  722. $this->oWizard->SetParameter('selected_components', json_encode($aSelectedChoices));
  723. if ($this->GetStepInfo($index) == null)
  724. {
  725. throw new Exception('Internal error: invalid step "'.$index.'" for the choice of modules.');
  726. }
  727. else if ($bMoveForward)
  728. {
  729. if ($this->GetStepInfo(1 + $index) != null)
  730. {
  731. return array('class' => 'WizStepModulesChoice', 'state' => (1+$index));
  732. }
  733. else
  734. {
  735. // Exiting this step of the wizard, let's convert the selection into a list of modules
  736. $aModules = array();
  737. $sDisplayChoices = '<ul>';
  738. for($i = 0; $i <= $index; $i++)
  739. {
  740. $aStepInfo = $this->GetStepInfo($i);
  741. $sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules);
  742. }
  743. $sDisplayChoices .= '</ul>';
  744. $this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules)));
  745. $this->oWizard->SetParameter('display_choices', $sDisplayChoices);
  746. return array('class' => 'WizStepSummary', 'state' => '');
  747. }
  748. }
  749. }
  750. public function Display(WebPage $oPage)
  751. {
  752. $this->DisplayStep($oPage);
  753. }
  754. protected function DisplayStep($oPage)
  755. {
  756. $aStepInfo = $this->GetStepInfo();
  757. $oPage->add_style("div.choice { margin: 0.5em;}");
  758. $oPage->add_style("div.description { margin-left: 2em; }");
  759. $oPage->add_style(".choice-disabled { color: #999; }");
  760. $oPage->add('<table><tr>');
  761. $sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
  762. if (!empty($sBannerPath))
  763. {
  764. if (substr($sBannerPath, 0, 1) == '/')
  765. {
  766. // absolute path, means relative to APPROOT
  767. $sBannerUrl = utils::GetDefaultUrlAppRoot().$sBannerPath;
  768. }
  769. else
  770. {
  771. // relative path: i.e. relative to the directory containing the XML file
  772. $sFullPath = dirname($this->GetSourceFilePath()).'/'.$sBannerPath;
  773. $sRealPath = realpath($sFullPath);
  774. $sBannerUrl = utils::GetDefaultUrlAppRoot().str_replace(realpath(APPROOT), '', $sRealPath);
  775. }
  776. $oPage->add('<td><img src="'.$sBannerUrl.'"/><td>');
  777. }
  778. $sDescription = isset($aStepInfo['description']) ? $aStepInfo['description'] : '';
  779. $oPage->add('<td>'.$sDescription.'<td>');
  780. $oPage->add('</tr></table>');
  781. // Build the default choices
  782. $aDefaults = array();
  783. $this->GetDefaults($aStepInfo, $aDefaults);
  784. $index = $this->GetStepIndex();
  785. // retrieve the saved selection
  786. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  787. $aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  788. if (!isset($aParameters[$index]))
  789. {
  790. $aParameters[$index] = $aDefaults;
  791. }
  792. $aSelectedComponents = $aParameters[$index];
  793. $oPage->add('<div style="max-height:250px;overflow:auto;border:#ccc 1px solid;">');
  794. $this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents);
  795. $oPage->add('</div>');
  796. $oPage->add_script(
  797. <<<EOF
  798. function CheckChoice(sChoiceId)
  799. {
  800. console.log('Ici !!');
  801. var oElement = $('#'+sChoiceId);
  802. var bChecked = (oElement.attr('checked') == 'checked');
  803. var sId = sChoiceId.replace('choice', '');
  804. if ((oElement.attr('type') == 'radio') && bChecked)
  805. {
  806. // Only the radio that is clicked is notified, let's warn the other radio buttons
  807. sName = oElement.attr('name');
  808. $('input[name="'+sName+'"]').each(function() {
  809. var sRadioId = $(this).attr('id');
  810. if (sRadioId != sChoiceId)
  811. {
  812. CheckChoice(sRadioId);
  813. }
  814. });
  815. }
  816. $('#sub_choices'+sId).each(function() {
  817. if (!bChecked)
  818. {
  819. $(this).addClass('choice-disabled');
  820. }
  821. else
  822. {
  823. $(this).removeClass('choice-disabled');
  824. }
  825. $('input', this).each(function() {
  826. if (bChecked)
  827. {
  828. if ($(this).attr('data-disabled') != 'disabled')
  829. {
  830. // Only non-mandatory fields can be enabled
  831. $(this).removeAttr('disabled');
  832. }
  833. }
  834. else
  835. {
  836. $(this).attr('disabled', 'disabled');
  837. }
  838. });
  839. });
  840. }
  841. EOF
  842. );
  843. $oPage->add_ready_script(
  844. <<<EOF
  845. $('.wiz-choice').bind('change', function() { CheckChoice($(this).attr('id')); } );
  846. $('.wiz-choice').trigger('change');
  847. EOF
  848. );
  849. }
  850. protected function GetDefaults($aInfo, &$aDefaults, $sParentId = '')
  851. {
  852. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  853. foreach($aOptions as $index => $aChoice)
  854. {
  855. $sChoiceId = $sParentId.'_'.$index;
  856. if (isset($aChoice['default']) && $aChoice['default'])
  857. {
  858. $aDefaults[$sChoiceId] = $sChoiceId;
  859. }
  860. if (isset($aChoice['sub_options']))
  861. {
  862. $this->GetDefaults($aChoice['sub_options'], $aDefaults, $sChoiceId);
  863. }
  864. $index++;
  865. }
  866. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  867. $sChoiceName = null;
  868. foreach($aAlternatives as $index => $aChoice)
  869. {
  870. $sChoiceId = $sParentId.'_'.$index;
  871. if ($sChoiceName == null)
  872. {
  873. $sChoiceName = $sChoiceId;
  874. }
  875. if (isset($aChoice['default']) && $aChoice['default'])
  876. {
  877. $aDefaults[$sChoiceName] = $sChoiceId;
  878. }
  879. if (isset($aChoice['sub_options']))
  880. {
  881. $this->GetDefaults($aChoice['sub_options'], $aDefaults, $sChoiceId);
  882. }
  883. $index++;
  884. }
  885. }
  886. /**
  887. * Converts the list of selected "choices" into a list of "modules": take into account the selected and the mandatory modules
  888. * @param hash $aInfo Info about the "choice" array('options' => array(...), 'alternatives' => array(...))
  889. * @param hash $aSelectedChoices List of selected choices array('name' => 'selected_value_id')
  890. * @param hash $aModules Return parameter: List of selected modules array('module_id' => true)
  891. * @param string $sParentId Used for recursion
  892. * @return void
  893. */
  894. protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '')
  895. {
  896. if ($sParentId == '')
  897. {
  898. // Check once (before recursing) that the hidden modules are selected
  899. foreach(SetupUtils::AnalyzeInstallation($this->oWizard) as $sModuleId => $aModule)
  900. {
  901. if ($sModuleId != ROOT_MODULE)
  902. {
  903. if (($aModule['category'] == 'authentication') || (!$aModule['visible']))
  904. {
  905. $aModules[$sModuleId] = true;
  906. }
  907. }
  908. }
  909. }
  910. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  911. foreach($aOptions as $index => $aChoice)
  912. {
  913. $sChoiceId = $sParentId.'_'.$index;
  914. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  915. (isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId)) )
  916. {
  917. $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
  918. if (isset($aChoice['modules']))
  919. {
  920. foreach($aChoice['modules'] as $sModuleId)
  921. {
  922. $aModules[$sModuleId] = true; // store the Id of the selected module
  923. }
  924. }
  925. // Recurse only for selected choices
  926. if (isset($aChoice['sub_options']))
  927. {
  928. $sDisplayChoices .= '<ul>';
  929. $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices);
  930. $sDisplayChoices .= '</ul>';
  931. }
  932. $sDisplayChoices .= '</li>';
  933. }
  934. $index++;
  935. }
  936. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  937. $sChoiceName = null;
  938. foreach($aAlternatives as $index => $aChoice)
  939. {
  940. $sChoiceId = $sParentId.'_'.$index;
  941. if ($sChoiceName == null)
  942. {
  943. $sChoiceName = $sChoiceId;
  944. }
  945. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  946. (isset($aSelectedChoices[$sChoiceName]) && ($aSelectedChoices[$sChoiceName] == $sChoiceId)) )
  947. {
  948. $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
  949. if (isset($aChoice['modules']))
  950. {
  951. foreach($aChoice['modules'] as $sModuleId)
  952. {
  953. $aModules[$sModuleId] = true; // store the Id of the selected module
  954. }
  955. }
  956. // Recurse only for selected choices
  957. if (isset($aChoice['sub_options']))
  958. {
  959. $sDisplayChoices .= '<ul>';
  960. $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices);
  961. $sDisplayChoices .= '</ul>';
  962. }
  963. $sDisplayChoices .= '</li>';
  964. }
  965. $index++;
  966. }
  967. return $sDisplayChoices;
  968. }
  969. protected function GetStepIndex()
  970. {
  971. switch($this->sCurrentState)
  972. {
  973. case 'start_install':
  974. case 'start_upgrade':
  975. $index = 0;
  976. break;
  977. default:
  978. $index = (integer)$this->sCurrentState;
  979. }
  980. return $index;
  981. }
  982. protected function GetStepInfo($idx = null)
  983. {
  984. $aStepInfo = null;
  985. if ($idx === null)
  986. {
  987. $index = $this->GetStepIndex();
  988. }
  989. else
  990. {
  991. $index = $idx;
  992. }
  993. if (@file_exists($this->GetSourceFilePath()))
  994. {
  995. $aParams = new XMLParameters($this->GetSourceFilePath());
  996. $aSteps = $aParams->Get('steps', array());
  997. if (array_key_exists($index, $aSteps))
  998. {
  999. $aStepInfo = $aSteps[$index];
  1000. }
  1001. }
  1002. else if ($idx == 0)
  1003. {
  1004. // No wizard configuration provided, build a standard one:
  1005. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1006. $aStepInfo = array(
  1007. 'title' => 'Modules Selection',
  1008. '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>',
  1009. 'banner' => '/images/modules.png',
  1010. 'options' => array(),
  1011. );
  1012. try
  1013. {
  1014. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  1015. }
  1016. catch(Exception $e)
  1017. {
  1018. $sDefaultAppPath = '..';
  1019. }
  1020. foreach($aAvailableModules as $sModuleId => $aModule)
  1021. {
  1022. if ($sModuleId == ROOT_MODULE) continue; // Convention: the version number of the application is stored as a module named ROOT_MODULE
  1023. $sModuleLabel = $aModule['label'];
  1024. $sModuleHelp = $aModule['doc.more_information'];
  1025. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"$sDefaultAppPath{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  1026. if (($aModule['category'] != 'authentication') && ($aModule['visible']))
  1027. {
  1028. $aStepInfo['options'][$index] = array(
  1029. 'title' => $sModuleLabel,
  1030. 'description' => '',
  1031. 'more_info' => $sMoreInfo,
  1032. 'default' => true, // by default offer to install all modules
  1033. 'modules' => array($sModuleId),
  1034. );
  1035. switch($aModule['install']['flag'])
  1036. {
  1037. case MODULE_ACTION_MANDATORY:
  1038. $aStepInfo['options'][$index]['mandatory'] = true;
  1039. break;
  1040. }
  1041. $index++;
  1042. }
  1043. }
  1044. }
  1045. return $aStepInfo;
  1046. }
  1047. protected function DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $sParentId = '')
  1048. {
  1049. $aOptions = isset($aStepInfo['options']) ? $aStepInfo['options'] : array();
  1050. $aAlternatives = isset($aStepInfo['alternatives']) ? $aStepInfo['alternatives'] : array();
  1051. $index = 0;
  1052. foreach($aOptions as $index => $aChoice)
  1053. {
  1054. $sAttributes = '';
  1055. $sChoiceId = $sParentId.'_'.$index;
  1056. if (isset($aChoice['mandatory']) && $aChoice['mandatory'])
  1057. {
  1058. $oPage->add('<div class="choice"><input id="choice'.$sChoiceId.'" checked disabled data-disabled="disabled" type="checkbox"'.$sAttributes.'/><input type="hidden" name="choice['.$sChoiceId.']" value="'.$sChoiceId.'">&nbsp;');
  1059. }
  1060. else if (isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId))
  1061. {
  1062. $oPage->add('<div class="choice"><input class="wiz-choice" id="choice'.$sChoiceId.'" name="choice['.$sChoiceId.']" type="checkbox" checked value="'.$sChoiceId.'"/>&nbsp;');
  1063. }
  1064. else
  1065. {
  1066. $oPage->add('<div class="choice"><input class="wiz-choice" id="choice'.$sChoiceId.'" name="choice['.$sChoiceId.']" type="checkbox" value="'.$sChoiceId.'"/>&nbsp;');
  1067. }
  1068. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $sChoiceId);
  1069. $oPage->add('</div>');
  1070. $index++;
  1071. }
  1072. $sChoiceName = null;
  1073. foreach($aAlternatives as $index => $aChoice)
  1074. {
  1075. $sAttributes = '';
  1076. $sChoiceId = $sParentId.'_'.$index;
  1077. if ($sChoiceName == null)
  1078. {
  1079. $sChoiceName = $sChoiceId; // All radios share the same name
  1080. }
  1081. if (isset($aSelectedComponents[$sChoiceName]) && ($aSelectedComponents[$sChoiceName] == $sChoiceId))
  1082. {
  1083. $sAttributes = ' checked ';
  1084. }
  1085. $oPage->add('<div class="choice"><input class="wiz-choice" id="choice'.$sChoiceId.'" name="choice['.$sChoiceName.']" type="radio"'.$sAttributes.' value="'.$sChoiceId.'"/>&nbsp;');
  1086. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $sChoiceId);
  1087. $oPage->add('</div>');
  1088. $index++;
  1089. }
  1090. }
  1091. protected function DisplayChoice($oPage, $aChoice, $aSelectedComponents, $sChoiceId)
  1092. {
  1093. $oPage->add('<label for="choice'.$sChoiceId.'"><b>'.htmlentities($aChoice['title'], ENT_QUOTES, 'UTF-8').'</b></label>');
  1094. $sDescription = isset($aChoice['description']) ? htmlentities($aChoice['description'], ENT_QUOTES, 'UTF-8') : '';
  1095. $oPage->add('<div class="description">'.$sDescription.'<span id="sub_choices'.$sChoiceId.'">');
  1096. if (isset($aChoice['sub_options']))
  1097. {
  1098. $this->DisplayOptions($oPage, $aChoice['sub_options'], $aSelectedComponents, $sChoiceId);
  1099. }
  1100. $oPage->add('</span></div>');
  1101. }
  1102. protected function GetSourceFilePath()
  1103. {
  1104. return APPROOT.'datamodel/installation.xml';
  1105. }
  1106. }
  1107. /**
  1108. * Summary of the installation tasks
  1109. */
  1110. class WizStepSummary extends WizardStep
  1111. {
  1112. public function GetTitle()
  1113. {
  1114. $sMode = $this->oWizard->GetParameter('mode', 'install');
  1115. if ($sMode == 'install')
  1116. {
  1117. return 'Ready to install';
  1118. }
  1119. else
  1120. {
  1121. return 'Ready to upgrade';
  1122. }
  1123. }
  1124. public function GetPossibleSteps()
  1125. {
  1126. return array('WizStepDone');
  1127. }
  1128. /**
  1129. * Returns the label for the " Next >> " button
  1130. * @return string The label for the button
  1131. */
  1132. public function GetNextButtonLabel()
  1133. {
  1134. return ' Install ! ';
  1135. }
  1136. public function ProcessParams($bMoveForward = true)
  1137. {
  1138. return array('class' => 'WizStepDone', 'state' => '');
  1139. }
  1140. public function Display(WebPage $oPage)
  1141. {
  1142. $oPage->add_style(
  1143. <<<EOF
  1144. #params_summary {
  1145. height: 200px;
  1146. overflow: auto;
  1147. }
  1148. #params_summary div {
  1149. width:100;
  1150. margin-top:0;
  1151. padding-top: 0.5em;
  1152. padding-left: 0;
  1153. }
  1154. #params_summary div ul {
  1155. margin-left:0;
  1156. padding-left: 20px;
  1157. }
  1158. #params_summary div.closed ul {
  1159. display:none;
  1160. }
  1161. #params_summary div li {
  1162. list-style: none;
  1163. width: 100;
  1164. margin-left:0;
  1165. padding-left: 0em;
  1166. }
  1167. .title {
  1168. padding-left: 20px;
  1169. font-weight: bold;
  1170. cursor: pointer;
  1171. background: url(../images/minus.gif) 2px 2px no-repeat;
  1172. }
  1173. #params_summary div.closed .title {
  1174. background: url(../images/plus.gif) 2px 2px no-repeat;
  1175. }
  1176. #progress_content {
  1177. height: 200px;
  1178. overflow: auto;
  1179. text-align: center;
  1180. }
  1181. #installation_progress {
  1182. display: none;
  1183. }
  1184. EOF
  1185. );
  1186. $sMode = $this->oWizard->GetParameter('mode', 'install');
  1187. $sPreinstallationPhase = '';
  1188. $sDestination = ITOP_APPLICATION.(($sMode == 'install') ? ' version '.ITOP_VERSION.' is about to be installed ' : ' is about to be upgraded ');
  1189. $sDBDescription = ' <b>existing</b> database <b>'.$this->oWizard->GetParameter('db_name').'</b>';
  1190. if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes'))
  1191. {
  1192. $sDBDescription = ' <b>new</b> database <b>'.$this->oWizard->GetParameter('db_new_name').'</b>';
  1193. }
  1194. $sDestination .= 'into the '.$sDBDescription.' on the server <b>'.$this->oWizard->GetParameter('db_server').'</b>.';
  1195. $oPage->add('<h2>'.$sDestination.'</h2>');
  1196. $oPage->add('<fieldset id="summary"><legend>Installation Parameters</legend>');
  1197. $oPage->add('<div id="params_summary">');
  1198. $oPage->add('<div class="closed"><span class="title">Database Parameters</span><ul>');
  1199. $oPage->add('<li>Server Name: '.$this->oWizard->GetParameter('db_server').'</li>');
  1200. $oPage->add('<li>DB User Name: '.$this->oWizard->GetParameter('db_user').'</li>');
  1201. $oPage->add('<li>DB user password: '.$this->oWizard->GetParameter('db_pwd').'</li>');
  1202. if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes'))
  1203. {
  1204. $oPage->add('<li>Database Name: '.$this->oWizard->GetParameter('db_new_name').' (will be created)</li>');
  1205. }
  1206. else
  1207. {
  1208. $oPage->add('<li>Database Name: '.$this->oWizard->GetParameter('db_name').'</li>');
  1209. }
  1210. if ($this->oWizard->GetParameter('db_prefix') != '')
  1211. {
  1212. $oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: '.$this->oWizard->GetParameter('db_prefix').'</li>');
  1213. }
  1214. else
  1215. {
  1216. $oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: none</li>');
  1217. }
  1218. $oPage->add('</ul></div>');
  1219. $oPage->add('<div><span class="title">Data Model Configuration</span>');
  1220. $oPage->add($this->oWizard->GetParameter('display_choices'));
  1221. $oPage->add('</div>');
  1222. $oPage->add('<div class="closed"><span class="title">Other Parameters</span><ul>');
  1223. $oPage->add('<li>Default language: '.$this->oWizard->GetParameter('default_language').'</li>');
  1224. $oPage->add('<li>URL to access the application: '.$this->oWizard->GetParameter('application_url').'</li>');
  1225. if ($this->oWizard->GetParameter('sample_data') == 'yes')
  1226. {
  1227. $oPage->add('<li>Sample data will be loaded into the database.</li>');
  1228. }
  1229. $oPage->add('</ul></div>');
  1230. $oPage->add('<div class="closed"><span class="title">Admininistrator Account</span><ul>');
  1231. $oPage->add('<li>Login: '.$this->oWizard->GetParameter('admin_user').'</li>');
  1232. $oPage->add('<li>Password: '.$this->oWizard->GetParameter('admin_pwd').'</li>');
  1233. $oPage->add('<li>Language: '.$this->oWizard->GetParameter('admin_language').'</li>');
  1234. $oPage->add('</ul></div>');
  1235. $aMiscOptions = json_decode($this->oWizard->GetParameter('misc_options', '[]'), true /* bAssoc */);
  1236. if (count($aMiscOptions) > 0)
  1237. {
  1238. $oPage->add('<div class="closed"><span class="title">Miscellaneous Options</span><ul>');
  1239. foreach($aMiscOptions as $sKey => $sValue)
  1240. {
  1241. $oPage->add('<li>'.$sKey.': '.$sValue.'</li>');
  1242. }
  1243. $oPage->add('</ul></div>');
  1244. }
  1245. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  1246. /*
  1247. $oPage->add('<ul>Selected modules:');
  1248. sort($aSelectedModules);
  1249. foreach($aSelectedModules as $sModuleId)
  1250. {
  1251. $oPage->add('<li>'.$sModuleId.'</li>');
  1252. }
  1253. $oPage->add('</ul>');
  1254. */
  1255. $oPage->add_ready_script(
  1256. <<<EOF
  1257. $("#params_summary div").addClass('closed');
  1258. $("#params_summary .title").click(function() { $(this).parent().toggleClass('closed'); } );
  1259. $("#btn_next").bind("click.install", function(event) {
  1260. $('#summary').hide();
  1261. $('#installation_progress').show();
  1262. $(this).attr("disabled", "disabled"); event.preventDefault(); ExecuteStep("");
  1263. });
  1264. $("#wiz_form").data("installation_status", "not started")
  1265. EOF
  1266. );
  1267. // Prepare the parameters to execute the installation asynchronously
  1268. $sBackupDestination = '';
  1269. $sConfigurationFile = '';
  1270. $sDBName = $this->oWizard->GetParameter('db_name');
  1271. if ($sMode == 'upgrade')
  1272. {
  1273. if ($this->oWizard->GetParameter('db_backup', false))
  1274. {
  1275. $sSourceDir = $this->oWizard->GetParameter('source_dir', '');
  1276. if (!empty($sSourceDir))
  1277. {
  1278. $aPreviousInstance = SetupUtils::GetPreviousInstance($sSourceDir);
  1279. if ($aPreviousInstance['found'])
  1280. {
  1281. $sConfigurationFile = $aPreviousInstance['configuration_file'];
  1282. }
  1283. }
  1284. }
  1285. }
  1286. else
  1287. {
  1288. $sDBNewName = $this->oWizard->GetParameter('db_new_name', '');
  1289. if ($sDBNewName != '')
  1290. {
  1291. $sDBName = $sDBNewName; // Database will be created
  1292. }
  1293. }
  1294. $aInstallParams = array (
  1295. 'mode' => $sMode,
  1296. 'preinstall' => array (
  1297. 'copies' => array (
  1298. // 0 => array (
  1299. // 'source' => '',
  1300. // 'destination' => '',
  1301. // ),
  1302. ),
  1303. ),
  1304. 'source_dir' => 'datamodel',
  1305. 'target_env' => 'production',
  1306. 'workspace_dir' => '',
  1307. 'database' => array (
  1308. 'server' => $this->oWizard->GetParameter('db_server'),
  1309. 'user' => $this->oWizard->GetParameter('db_user'),
  1310. 'pwd' => $this->oWizard->GetParameter('db_pwd'),
  1311. 'name' => $sDBName,
  1312. 'prefix' => $this->oWizard->GetParameter('db_prefix'),
  1313. ),
  1314. 'url' => $this->oWizard->GetParameter('application_url'),
  1315. 'admin_account' => array (
  1316. 'user' => $this->oWizard->GetParameter('admin_user'),
  1317. 'pwd' => $this->oWizard->GetParameter('admin_pwd'),
  1318. 'language' => $this->oWizard->GetParameter('admin_language'),
  1319. ),
  1320. 'language' => $this->oWizard->GetParameter('default_language'),
  1321. 'selected_modules' => $aSelectedModules,
  1322. 'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false ,
  1323. 'options' => json_decode($this->oWizard->GetParameter('misc_options', '[]'), true),
  1324. );
  1325. if ($sBackupDestination != '')
  1326. {
  1327. $aInstallParams['backup'] = array (
  1328. 'destination' => $sBackupDestination,
  1329. 'configuration_file' => $sConfigurationFile,
  1330. );
  1331. }
  1332. $sJSONData = json_encode($aInstallParams);
  1333. if (isset($aMiscOptions['generate_config']))
  1334. {
  1335. $oDoc = new DOMDocument('1.0', 'UTF-8');
  1336. $oDoc->preserveWhiteSpace = false;
  1337. $oDoc->formatOutput = true;
  1338. $oParams = new PHPParameters();
  1339. $oParams->LoadFromHash($aInstallParams);
  1340. $oParams->ToXML($oDoc, null, 'installation');
  1341. $sXML = $oDoc->saveXML();
  1342. $oPage->add('<div class="closed"><span class="title">XML Config file</span><ul><pre>');
  1343. $oPage->add(htmlentities($sXML, ENT_QUOTES, 'UTF-8'));
  1344. $oPage->add('</pre></ul></div>');
  1345. }
  1346. $oPage->add('</div>'); // params_summary
  1347. $oPage->add('</fieldset>');
  1348. $oPage->add('<fieldset id="installation_progress"><legend>Progress of the installation</legend>');
  1349. $oPage->add('<div id="progress_content">');
  1350. $oPage->add_linked_script('../setup/jquery.progression.js');
  1351. $oPage->add('<p class="center"><span id="setup_msg">Ready to start...</span></p><div style="display:block;margin-left: auto; margin-right:auto;" id="progress">0%</div>');
  1352. $oPage->add('</div>'); // progress_content
  1353. $oPage->add('</fieldset>');
  1354. $oPage->add('<input type="hidden" id="installer_parameters" value="'.htmlentities($sJSONData, ENT_QUOTES, 'UTF-8').'"/>');
  1355. }
  1356. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  1357. {
  1358. $oParameters = new PHPParameters();
  1359. $sStep = $aParameters['installer_step'];
  1360. $sJSONParameters = $aParameters['installer_config'];
  1361. $oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
  1362. $oInstaller = new ApplicationInstaller($oParameters);
  1363. $aRes = $oInstaller->ExecuteStep($sStep);
  1364. if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != ''))
  1365. {
  1366. // Tell the web page to move the progress bar and to launch the next step
  1367. $sMessage = addslashes(htmlentities($aRes['next-step-label'], ENT_QUOTES, 'UTF-8'));
  1368. $oPage->add_ready_script(
  1369. <<<EOF
  1370. $("#wiz_form").data("installation_status", "running");
  1371. WizardUpdateButtons();
  1372. $('#setup_msg').html('$sMessage');
  1373. $('#progress').progression( {Current:{$aRes['percentage-completed']}, Maximum: 100, aBackgroundImg: GetAbsoluteUrlAppRoot()+'setup/orange-progress.gif', aTextColor: '#000000'} );
  1374. //$("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
  1375. ExecuteStep('{$aRes['next-step']}');
  1376. EOF
  1377. );
  1378. }
  1379. else if ($aRes['next-step'] == '')
  1380. {
  1381. // Installation complete, move to the next step of the wizard
  1382. $oPage->add_ready_script(
  1383. <<<EOF
  1384. $("#wiz_form").data("installation_status", "completed");
  1385. $('#progress').progression( {Current:100, Maximum: 100, aBackgroundImg: GetAbsoluteUrlAppRoot()+'setup/orange-progress.gif', aTextColor: '#000000'} );
  1386. WizardUpdateButtons();
  1387. $("#btn_next").unbind("click.install");
  1388. $("#btn_next").click();
  1389. EOF
  1390. );
  1391. }
  1392. else
  1393. {
  1394. $sMessage = addslashes(htmlentities($aRes['message'], ENT_QUOTES, 'UTF-8'));
  1395. $oPage->add_ready_script(
  1396. <<<EOF
  1397. $("#wiz_form").data("installation_status", "error");
  1398. WizardUpdateButtons();
  1399. $('#setup_msg').html('$sMessage');
  1400. EOF
  1401. );
  1402. }
  1403. }
  1404. /**
  1405. * Tells whether the "Next" button should be enabled interactively
  1406. * @return string A piece of javascript code returning either true or false
  1407. */
  1408. public function JSCanMoveForward()
  1409. {
  1410. return 'return (($("#wiz_form").data("installation_status") === "not started") || ($("#wiz_form").data("installation_status") === "completed"));';
  1411. }
  1412. /**
  1413. * Tells whether the "Next" button should be enabled interactively
  1414. * @return string A piece of javascript code returning either true or false
  1415. */
  1416. public function JSCanMoveBackward()
  1417. {
  1418. return 'var sStatus = $("#wiz_form").data("installation_status"); return ((sStatus === "not started") || (sStatus === "error"));';
  1419. }
  1420. }
  1421. /**
  1422. * Summary of the installation tasks
  1423. */
  1424. class WizStepDone extends WizardStep
  1425. {
  1426. public function GetTitle()
  1427. {
  1428. return 'Done';
  1429. }
  1430. public function GetPossibleSteps()
  1431. {
  1432. return array();
  1433. }
  1434. public function ProcessParams($bMoveForward = true)
  1435. {
  1436. return array('class' => '', 'state' => '');
  1437. }
  1438. public function Display(WebPage $oPage)
  1439. {
  1440. // Check if there are some manual steps required:
  1441. $aManualSteps = array();
  1442. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1443. $sRootUrl = utils::GetAbsoluteUrlAppRoot();
  1444. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  1445. foreach($aSelectedModules as $sModuleId)
  1446. {
  1447. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  1448. {
  1449. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $sRootUrl.$aAvailableModules[$sModuleId]['doc.manual_setup'];
  1450. }
  1451. }
  1452. if (count($aManualSteps) > 0)
  1453. {
  1454. $oPage->add("<h2>Manual operations required</h2>");
  1455. $oPage->p("In order to complete the installation, the following manual operations are required:");
  1456. foreach($aManualSteps as $sModuleLabel => $sUrl)
  1457. {
  1458. $oPage->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  1459. }
  1460. $oPage->add("<h2>Congratulations for installing iTop</h2>");
  1461. }
  1462. else
  1463. {
  1464. $oPage->add("<h2>Congratulations for installing iTop</h2>");
  1465. $oPage->ok("The installation completed successfully.");
  1466. }
  1467. // Form goes here.. No back button since the job is done !
  1468. $oPage->add('<table style="width:600px;border:0;padding:0;"><tr>');
  1469. $oPage->add("<td><a style=\"background:transparent;padding:0;\" title=\"Free: Register your iTop version.\" href=\"http://www.combodo.com/register?product=iTop&version=".urlencode(ITOP_VERSION." revision ".ITOP_REVISION)."\" target=\"_blank\"><img style=\"border:0\" src=\"../images/setup-register.gif\"/></td></a>");
  1470. $oPage->add("<td><a style=\"background:transparent;padding:0;\" title=\"Get Professional Support from Combodo\" href=\"http://www.combodo.com/itopsupport\" target=\"_blank\"><img style=\"border:0\" src=\"../images/setup-support.gif\"/></td></a>");
  1471. $oPage->add("<td><a style=\"background:transparent;padding:0;\" title=\"Get Professional Training from Combodo\" href=\"http://www.combodo.com/itoptraining\" target=\"_blank\"><img style=\"border:0\" src=\"../images/setup-training.gif\"/></td></a>");
  1472. $oPage->add('</tr></table>');
  1473. $sForm = '<form method="post" action="'.$this->oWizard->GetParameter('application_url').'/pages/UI.php">';
  1474. $sForm .= '<input type="hidden" name="auth_user" value="'.htmlentities($this->oWizard->GetParameter('admin_user'), ENT_QUOTES, 'UTF-8').'">';
  1475. $sForm .= '<input type="hidden" name="auth_pwd" value="'.htmlentities($this->oWizard->GetParameter('admin_pwd'), ENT_QUOTES, 'UTF-8').'">';
  1476. $sForm .= "<p style=\"text-align:center;width:100%\"><button id=\"enter_itop\" type=\"submit\">Enter iTop</button></p>";
  1477. $sForm .= '</form>';
  1478. $oPage->add('<img style="border:0" src="http://www.combodo.com/stats/?p='.urlencode(ITOP_APPLICATION).'&v='.urlencode(ITOP_VERSION).'"/>');
  1479. $sForm = addslashes($sForm);
  1480. $oPage->add_ready_script("$('#wiz_form').after('$sForm');");
  1481. }
  1482. public function CanMoveForward()
  1483. {
  1484. return false;
  1485. }
  1486. public function CanMoveBackward()
  1487. {
  1488. return false;
  1489. }
  1490. }