wizardsteps.class.inc.php 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * All the steps of the iTop installation wizard
  20. * @copyright Copyright (C) 2010-2012 Combodo SARL
  21. * @license http://opensource.org/licenses/AGPL-3.0
  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. require_once(APPROOT.'core/mutex.class.inc.php');
  28. /**
  29. * First step of the iTop Installation Wizard: Welcome screen
  30. */
  31. class WizStepWelcome extends WizardStep
  32. {
  33. protected $bCanMoveForward;
  34. public function GetTitle()
  35. {
  36. return 'Welcome to '.ITOP_APPLICATION.' version '.ITOP_VERSION;
  37. }
  38. /**
  39. * Returns the label for the " Next >> " button
  40. * @return string The label for the button
  41. */
  42. public function GetNextButtonLabel()
  43. {
  44. return ' Continue >> ';
  45. }
  46. public function GetPossibleSteps()
  47. {
  48. return array('WizStepInstallOrUpgrade');
  49. }
  50. public function ProcessParams($bMoveForward = true)
  51. {
  52. return array('class' => 'WizStepInstallOrUpgrade', 'state' => '');
  53. }
  54. public function Display(WebPage $oPage)
  55. {
  56. // Store the misc_options for the future...
  57. $aMiscOptions = utils::ReadParam('option', array(), false, 'raw_data');
  58. $sMiscOptions = $this->oWizard->GetParameter('misc_options', json_encode($aMiscOptions));
  59. $this->oWizard->SetParameter('misc_options', $sMiscOptions);
  60. $oPage->add("<!--[if lt IE 8]><div id=\"old_ie\"></div><![endif]-->");
  61. $oPage->add_ready_script(
  62. <<<EOF
  63. if ($('#old_ie').length > 0)
  64. {
  65. alert("Internet Explorer version 7 or older is NOT supported! (Check that IE is not running in compatibility mode)");
  66. }
  67. EOF
  68. );
  69. $oPage->add('<h1>'.ITOP_APPLICATION.' Installation Wizard</h1>');
  70. $aResults = SetupUtils::CheckPHPVersion($oPage);
  71. $this->bCanMoveForward = true;
  72. $aInfo = array();
  73. $aWarnings = array();
  74. $aErrors = array();
  75. foreach($aResults as $oCheckResult)
  76. {
  77. switch($oCheckResult->iSeverity)
  78. {
  79. case CheckResult::ERROR:
  80. $aErrors[] = $oCheckResult->sLabel;
  81. $this->bCanMoveForward = false;
  82. break;
  83. case CheckResult::WARNING:
  84. $aWarnings[] = $oCheckResult->sLabel;
  85. break;
  86. case CheckResult::INFO:
  87. $aInfo[] = $oCheckResult->sLabel;
  88. break;
  89. }
  90. }
  91. $sStyle = 'style="display:none;max-height:196px;overflow:auto;"';
  92. $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>';
  93. if (count($aErrors)> 0)
  94. {
  95. $sStyle = 'style="max-height:196px;overflow:auto;"';
  96. $sImage = "stop-mid.png";
  97. $sTitle = count($aErrors).' Error(s), '.count($aWarnings).' Warning(s).';
  98. }
  99. else if (count($aWarnings)> 0)
  100. {
  101. $sTitle = count($aWarnings).' Warning(s) '.$sToggleButtons;
  102. $sImage = "messagebox_warning-mid.png";
  103. }
  104. else
  105. {
  106. $sTitle = 'Ok. '.$sToggleButtons;
  107. $sImage = "clean-mid.png";
  108. }
  109. $oPage->add('<h2>Prerequisites validation: ');
  110. $oPage->add("<img style=\"vertical-align:middle;\" src=\"../images/$sImage\"> ");
  111. $oPage->add($sTitle);
  112. $oPage->add('</h2>');
  113. $oPage->add('<div id="details" '.$sStyle.'>');
  114. foreach($aErrors as $sText)
  115. {
  116. $oPage->error($sText);
  117. }
  118. foreach($aWarnings as $sText)
  119. {
  120. $oPage->warning($sText);
  121. }
  122. foreach($aInfo as $sText)
  123. {
  124. $oPage->ok($sText);
  125. }
  126. $oPage->add('</div>');
  127. if (!$this->bCanMoveForward)
  128. {
  129. $oPage->p('Sorry, the installation cannot continue. Please fix the errors and reload this page to launch the installation again.');
  130. $oPage->p('<button type="button" onclick="window.location.reload()">Reload</button>');
  131. }
  132. }
  133. public function CanMoveForward()
  134. {
  135. return $this->bCanMoveForward;
  136. }
  137. }
  138. /**
  139. * Second step of the iTop Installation Wizard: Install or Upgrade
  140. */
  141. class WizStepInstallOrUpgrade extends WizardStep
  142. {
  143. public function GetTitle()
  144. {
  145. return 'Install or Upgrade choice';
  146. }
  147. public function GetPossibleSteps()
  148. {
  149. return array('WizStepDetectedInfo', 'WizStepLicense');
  150. }
  151. public function ProcessParams($bMoveForward = true)
  152. {
  153. $sNextStep = '';
  154. $sInstallMode = utils::ReadParam('install_mode');
  155. $this->oWizard->SaveParameter('previous_version_dir', '');
  156. $this->oWizard->SaveParameter('db_server', '');
  157. $this->oWizard->SaveParameter('db_user', '');
  158. $this->oWizard->SaveParameter('db_pwd', '');
  159. $this->oWizard->SaveParameter('db_name', '');
  160. $this->oWizard->SaveParameter('db_prefix', '');
  161. $this->oWizard->SaveParameter('db_backup', false);
  162. $this->oWizard->SaveParameter('db_backup_path', '');
  163. if ($sInstallMode == 'install')
  164. {
  165. $this->oWizard->SetParameter('install_mode', 'install');
  166. $sFullSourceDir = SetupUtils::GetLatestDataModelDir();
  167. $this->oWizard->SetParameter('source_dir', $sFullSourceDir);
  168. $this->oWizard->SetParameter('datamodel_version', SetupUtils::GetDataModelVersion($sFullSourceDir));
  169. $sNextStep = 'WizStepLicense';
  170. }
  171. else
  172. {
  173. $this->oWizard->SetParameter('install_mode', 'upgrade');
  174. $sNextStep = 'WizStepDetectedInfo';
  175. }
  176. return array('class' => $sNextStep, 'state' => '');
  177. }
  178. public function Display(WebPage $oPage)
  179. {
  180. $sInstallMode = $this->oWizard->GetParameter('install_mode', '');
  181. $sDBServer = $this->oWizard->GetParameter('db_server', '');
  182. $sDBUser = $this->oWizard->GetParameter('db_user', '');
  183. $sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
  184. $sDBName = $this->oWizard->GetParameter('db_name', '');
  185. $sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
  186. $bDBBackup = $this->oWizard->GetParameter('db_backup', false);
  187. $sDBBackupPath = $this->oWizard->GetParameter('db_backup_path', '');
  188. $sPreviousVersionDir = '';
  189. if ($sInstallMode == '')
  190. {
  191. $sDBBackupPath = APPROOT.'data/'.ITOP_APPLICATION.strftime('-backup-%Y-%m-%d.zip');
  192. $bDBBackup = true;
  193. $aPreviousInstance = SetupUtils::GetPreviousInstance(APPROOT);
  194. if ($aPreviousInstance['found'])
  195. {
  196. $sInstallMode = 'upgrade';
  197. $sSourceDir = APPROOT;
  198. $sDBServer = $aPreviousInstance['db_server'];
  199. $sDBUser = $aPreviousInstance['db_user'];
  200. $sDBPwd = $aPreviousInstance['db_pwd'];
  201. $sDBName = $aPreviousInstance['db_name'];
  202. $sDBPrefix = $aPreviousInstance['db_prefix'];
  203. $sStyle = '';
  204. $sPreviousVersionDir = APPROOT;
  205. }
  206. else
  207. {
  208. $sInstallMode = 'install';
  209. }
  210. }
  211. $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', $sPreviousVersionDir);
  212. $sUpgradeInfoStyle = '';
  213. if ($sInstallMode == 'install')
  214. {
  215. $sUpgradeInfoStyle = ' style="display: none;" ';
  216. }
  217. $oPage->add('<h2>What do you want to do?</h2>');
  218. $sChecked = ($sInstallMode == 'install') ? ' checked ' : '';
  219. $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>');
  220. $sChecked = ($sInstallMode == 'upgrade') ? ' checked ' : '';
  221. $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>');
  222. //$oPage->add('<fieldset id="upgrade_info"'.$sUpgradeInfoStyle.'>');
  223. //$oPage->add('<legend>Information about the previous instance:</legend>');
  224. $oPage->add('<table id="upgrade_info"'.$sUpgradeInfoStyle.'>');
  225. $oPage->add('<tr><td>Location on the disk:</td><td><input id="previous_version_dir" type="text" name="previous_version_dir" value="'.htmlentities($sPreviousVersionDir, ENT_QUOTES, 'UTF-8').'" size="25"/></td></tr>');
  226. SetupUtils::DisplayDBParameters($oPage, false, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix);
  227. $aBackupChecks = SetupUtils::CheckBackupPrerequisites($sDBBackupPath);
  228. $bCanBackup = true;
  229. $sMySQLDumpMessage = '';
  230. foreach($aBackupChecks as $oCheck)
  231. {
  232. if ($oCheck->iSeverity == CheckResult::ERROR)
  233. {
  234. $bCanBackup = false;
  235. $sMySQLDumpMessage .= '<img src="../images/error.png"/>&nbsp;<b> Warning:</b> '.$oCheck->sLabel;
  236. }
  237. else
  238. {
  239. $sMySQLDumpMessage .= '<img src="../images/validation_ok.png"/> '.$oCheck->sLabel.' ';
  240. }
  241. }
  242. $sChecked = ($bCanBackup && $bDBBackup) ? ' checked ' : '';
  243. $sDisabled = $bCanBackup ? '' : ' disabled ';
  244. $oPage->add('<tr><td colspan="2"><input id="db_backup" type="checkbox" name="db_backup"'.$sChecked.$sDisabled.' value="1"/><label for="db_backup">&nbsp;Backup the '.ITOP_APPLICATION.' database before upgrading</label></td></tr>');
  245. $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>');
  246. $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
  247. $sMessage = '';
  248. if ($fFreeSpace !== false)
  249. {
  250. $sMessage .= SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath);
  251. }
  252. $oPage->add('<tr><td colspan="2">');
  253. $oPage->add($sMySQLDumpMessage.'<br/><span id="backup_info" style="font-size:small;color:#696969;">'.$sMessage.'</span></td></tr>');
  254. $oPage->add('</table>');
  255. //$oPage->add('</fieldset>');
  256. $oPage->add_ready_script(
  257. <<<EOF
  258. $("#radio_update").bind('change', function() { if (this.checked ) { $('#upgrade_info').show(); WizardUpdateButtons(); } else { $('#upgrade_info').hide(); } });
  259. $("#radio_install").bind('change', function() { if (this.checked ) { $('#upgrade_info').hide(); WizardUpdateButtons(); } else { $('#upgrade_info').show(); } });
  260. $("#previous_version_dir").bind('change keyup', function() { WizardAsyncAction('check_path', { previous_version_dir: $('#previous_version_dir').val() }); });
  261. $("#db_backup_path").bind('change keyup', function() { WizardAsyncAction('check_backup', { db_backup_path: $('#db_backup_path').val() }); });
  262. EOF
  263. );
  264. }
  265. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  266. {
  267. switch($sCode)
  268. {
  269. case 'check_path':
  270. $sPreviousVersionDir = $aParameters['previous_version_dir'];
  271. $aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir);
  272. if ($aPreviousInstance['found'])
  273. {
  274. $sDBServer = htmlentities($aPreviousInstance['db_server'], ENT_QUOTES, 'UTF-8');
  275. $sDBUser = htmlentities($aPreviousInstance['db_user'], ENT_QUOTES, 'UTF-8');
  276. $sDBPwd = htmlentities($aPreviousInstance['db_pwd'], ENT_QUOTES, 'UTF-8');
  277. $sDBName = htmlentities($aPreviousInstance['db_name'], ENT_QUOTES, 'UTF-8');
  278. $sDBPrefix = htmlentities($aPreviousInstance['db_prefix'], ENT_QUOTES, 'UTF-8');
  279. $oPage->add_ready_script(
  280. <<<EOF
  281. $("#db_server").val('$sDBServer');
  282. $("#db_user").val('$sDBUser');
  283. $("#db_pwd").val('$sDBPwd');
  284. $("#db_name").val('$sDBName');
  285. $("#db_prefix").val('$sDBPrefix');
  286. $("#db_pwd").trigger('change'); // Forces check of the DB connection
  287. EOF
  288. );
  289. }
  290. break;
  291. case 'check_db':
  292. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  293. break;
  294. case 'check_backup':
  295. $sDBBackupPath = $aParameters['db_backup_path'];
  296. $fFreeSpace = SetupUtils::CheckDiskSpace($sDBBackupPath);
  297. if ($fFreeSpace !== false)
  298. {
  299. $sMessage = htmlentities(SetupUtils::HumanReadableSize($fFreeSpace).' free in '.dirname($sDBBackupPath), ENT_QUOTES, 'UTF-8');
  300. $oPage->add_ready_script(
  301. <<<EOF
  302. $("#backup_info").html('$sMessage');
  303. EOF
  304. );
  305. }
  306. else
  307. {
  308. $oPage->add_ready_script(
  309. <<<EOF
  310. $("#backup_info").html('');
  311. EOF
  312. );
  313. }
  314. break;
  315. }
  316. }
  317. /**
  318. * Tells whether the "Next" button should be enabled interactively
  319. * @return string A piece of javascript code returning either true or false
  320. */
  321. public function JSCanMoveForward()
  322. {
  323. return
  324. <<<EOF
  325. if ($("#radio_install").attr("checked") == "checked")
  326. {
  327. ValidateField("db_name", false);
  328. ValidateField("db_new_name", false);
  329. ValidateField("db_prefix", false);
  330. return true;
  331. }
  332. else
  333. {
  334. var bRet = ($("#wiz_form").data("db_connection") !== "error");
  335. bRet = ValidateField("db_name", true) && bRet;
  336. bRet = ValidateField("db_new_name", true) && bRet;
  337. bRet = ValidateField("db_prefix", true) && bRet;
  338. return bRet;
  339. }
  340. EOF
  341. ;
  342. }
  343. }
  344. /**
  345. * Upgrade information
  346. */
  347. class WizStepDetectedInfo extends WizardStep
  348. {
  349. protected $bCanMoveForward;
  350. public function GetTitle()
  351. {
  352. return 'Upgrade Information';
  353. }
  354. public function GetPossibleSteps()
  355. {
  356. return array('WizStepUpgradeMiscParams', 'WizStepLicense2');
  357. }
  358. public function ProcessParams($bMoveForward = true)
  359. {
  360. $sUpgradeType = utils::ReadParam('upgrade_type');
  361. $this->oWizard->SetParameter('mode', 'upgrade');
  362. $this->oWizard->SetParameter('upgrade_type', $sUpgradeType);
  363. $this->oWizard->SaveParameter('copy_extensions_from', '');
  364. $bDisplayLicense = $this->oWizard->GetParameter('display_license');
  365. switch ($sUpgradeType)
  366. {
  367. case 'keep-previous':
  368. $sSourceDir = utils::ReadParam('relative_source_dir', '', false, 'raw_data');
  369. $this->oWizard->SetParameter('source_dir', $this->oWizard->GetParameter('previous_version_dir').'/'.$sSourceDir);
  370. $this->oWizard->SetParameter('datamodel_version', utils::ReadParam('datamodel_previous_version', '', false, 'raw_data'));
  371. break;
  372. case 'use-compatible':
  373. $sDataModelPath = utils::ReadParam('datamodel_path', '', false, 'raw_data');
  374. $this->oWizard->SetParameter('source_dir', $sDataModelPath);
  375. $this->oWizard->SaveParameter('datamodel_version', '');
  376. break;
  377. default:
  378. // Do nothing, maybe the user pressed the Back button
  379. }
  380. if ($bDisplayLicense)
  381. {
  382. $aRet = array('class' => 'WizStepLicense2', 'state' => '');
  383. }
  384. else
  385. {
  386. $aRet = array('class' => 'WizStepUpgradeMiscParams', 'state' => '');
  387. }
  388. return $aRet;
  389. }
  390. public function Display(WebPage $oPage)
  391. {
  392. $oPage->add_style(
  393. <<<EOF
  394. #changes_summary {
  395. max-height: 200px;
  396. overflow: auto;
  397. }
  398. #changes_summary div {
  399. width:100;
  400. margin-top:0;
  401. padding-top: 0.5em;
  402. padding-left: 0;
  403. }
  404. #changes_summary div ul {
  405. margin-left:0;
  406. padding-left: 20px;
  407. }
  408. #changes_summary div.closed ul {
  409. display:none;
  410. }
  411. #changes_summary div li {
  412. list-style: none;
  413. width: 100;
  414. margin-left:0;
  415. padding-left: 0em;
  416. }
  417. .title {
  418. padding-left: 20px;
  419. font-weight: bold;
  420. cursor: pointer;
  421. background: url(../images/minus.gif) 2px 2px no-repeat;
  422. }
  423. #changes_summary div.closed .title {
  424. background: url(../images/plus.gif) 2px 2px no-repeat;
  425. }
  426. EOF
  427. );
  428. $this->bCanMoveForward = true;
  429. $bDisplayLicense = true;
  430. $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', '');
  431. $aInstalledInfo = SetupUtils::GetApplicationVersion($this->oWizard);
  432. if ($aInstalledInfo === false)
  433. {
  434. throw(new Exception('No previous version of '.ITOP_APPLICATION.' found in the supplied database. The upgrade cannot continue.'));
  435. }
  436. else if (strcasecmp($aInstalledInfo['product_name'], ITOP_APPLICATION) != 0)
  437. {
  438. $oPage->p("<b>Warning: The installed products seem different. Are you sure the you want to upgrade {$aInstalledInfo['product_name']} with ".ITOP_APPLICATION."?</b>");
  439. }
  440. $sInstalledVersion = $aInstalledInfo['product_version'];
  441. $sInstalledDataModelVersion = $aInstalledInfo['datamodel_version'];
  442. $oPage->add("<h2>Information about the upgrade from version $sInstalledVersion to ".ITOP_VERSION.'.'.ITOP_REVISION."</h2>");
  443. if ($sInstalledVersion == (ITOP_VERSION.'.'.ITOP_REVISION))
  444. {
  445. // Reinstalling the same version let's skip the license agreement...
  446. $bDisplayLicense = false;
  447. }
  448. $this->oWizard->SetParameter('license', $bDisplayLicense); // Remember for later
  449. if ($sInstalledDataModelVersion == '$ITOP_VERSION$.$WCREV$')
  450. {
  451. // Special case for upgrading some development versions (temporary)
  452. $sCompatibleDMDir = SetupUtils::GetLatestDataModelDir();
  453. $sInstalledDataModelVersion = SetupUtils::GetDataModelVersion($sCompatibleDMDir);
  454. }
  455. else
  456. {
  457. $sCompatibleDMDir = SetupUtils::GetCompatibleDataModelDir($sInstalledDataModelVersion);
  458. }
  459. if ($sCompatibleDMDir === false)
  460. {
  461. // No compatible version exists... cannot upgrade. Either it is too old, or too new (downgrade !)
  462. $this->bCanMoveForward = false;
  463. $oPage->p("The current version of ".ITOP_APPLICATION." (".ITOP_VERSION.'.'.ITOP_REVISION.") does not seem to be compatible with the installed version ($sInstalledVersion).");
  464. $oPage->p("The upgrade cannot continue, sorry.");
  465. }
  466. else
  467. {
  468. $sUpgradeDMVersion = SetupUtils::GetDataModelVersion($sCompatibleDMDir);
  469. $sPreviousSourceDir = isset($aInstalledInfo['source_dir']) ? $aInstalledInfo['source_dir'] : 'modules';
  470. $aChanges = false;
  471. if (is_dir($sPreviousVersionDir))
  472. {
  473. // Check if the previous version is a "genuine" one or not...
  474. $aChanges = SetupUtils::CheckVersion($sInstalledDataModelVersion, $sPreviousVersionDir.'/'.$sPreviousSourceDir);
  475. }
  476. if (($aChanges !== false) && ( (count($aChanges['added']) > 0) || (count($aChanges['removed']) > 0) || (count($aChanges['modified']) > 0)) )
  477. {
  478. // Some changes were detected, prompt the user to keep or discard them
  479. $oPage->p("<img src=\"../images/error.png\"/>&nbsp;Some modifications were detected between the ".ITOP_APPLICATION." version in '$sPreviousVersionDir' and a genuine $sInstalledVersion version.");
  480. $oPage->p("What do you want to do?");
  481. $aWritableDirs = array('modules', 'portal');
  482. $aErrors = SetupUtils::CheckWritableDirs($aWritableDirs);
  483. $sChecked = ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous') ? ' checked ' : '';
  484. $sDisabled = (count($aErrors) > 0) ? ' disabled ' : '';
  485. $oPage->p('<input id="radio_upgrade_keep" type="radio" name="upgrade_type" value="keep-previous"'.$sChecked.$sDisabled.'/><label for="radio_upgrade_keep">&nbsp;Preserve the modifications of the installed version (the dasboards inside '.ITOP_APPLICATION.' may not be editable).</label>');
  486. $oPage->add('<input type="hidden" name="datamodel_previous_version" value="'.htmlentities($sInstalledDataModelVersion, ENT_QUOTES, 'UTF-8').'">');
  487. $oPage->add('<input type="hidden" name="relative_source_dir" value="'.htmlentities($sPreviousSourceDir, ENT_QUOTES, 'UTF-8').'">');
  488. if (count($aErrors) > 0)
  489. {
  490. $oPage->p("Cannot copy the installed version due to the following access rights issue(s):");
  491. foreach($aErrors as $sDir => $oCheckResult)
  492. {
  493. $oPage->p('<img src="../images/error.png"/>&nbsp;'.$oCheckResult->sLabel);
  494. }
  495. }
  496. $sChecked = ($this->oWizard->GetParameter('upgrade_type') == 'use-compatible') ? ' checked ' : '';
  497. $oPage->p('<input id="radio_upgrade_convert" type="radio" name="upgrade_type" value="use-compatible"'.$sChecked.'/><label for="radio_upgrade_convert">&nbsp;Discard the modifications, use a standard '.$sUpgradeDMVersion.' data model.</label>');
  498. $oPage->add('<input type="hidden" name="datamodel_path" value="'.htmlentities($sCompatibleDMDir, ENT_QUOTES, 'UTF-8').'">');
  499. $oPage->add('<input type="hidden" name="datamodel_version" value="'.htmlentities($sUpgradeDMVersion, ENT_QUOTES, 'UTF-8').'">');
  500. $oPage->add('<div id="changes_summary"><div class="closed"><span class="title">Details of the modifications</span><div>');
  501. if (count($aChanges['added']) > 0)
  502. {
  503. $oPage->add('<ul>New files added:');
  504. foreach($aChanges['added'] as $sFilePath => $void)
  505. {
  506. $oPage->add('<li>'.$sFilePath.'</li>');
  507. }
  508. $oPage->add('</ul>');
  509. }
  510. if (count($aChanges['removed']) > 0)
  511. {
  512. $oPage->add('<ul>Deleted files:');
  513. foreach($aChanges['removed'] as $sFilePath => $void)
  514. {
  515. $oPage->add('<li>'.$sFilePath.'</li>');
  516. }
  517. $oPage->add('</ul>');
  518. }
  519. if (count($aChanges['modified']) > 0)
  520. {
  521. $oPage->add('<ul>Modified files:');
  522. foreach($aChanges['modified'] as $sFilePath => $void)
  523. {
  524. $oPage->add('<li>'.$sFilePath.'</li>');
  525. }
  526. $oPage->add('</ul>');
  527. }
  528. $oPage->add('</div></div></div>');
  529. }
  530. else
  531. {
  532. // No changes detected... or no way to tell because of the lack of a manifest or previous source dir
  533. // Use the "compatible" datamodel as-is.
  534. $oPage->p("<img src=\"../images/validation_ok.png\"/>&nbsp;The datamodel will be upgraded from version $sInstalledDataModelVersion to version $sUpgradeDMVersion.");
  535. $oPage->add('<input type="hidden" name="upgrade_type" value="use-compatible">');
  536. $oPage->add('<input type="hidden" name="datamodel_path" value="'.htmlentities($sCompatibleDMDir, ENT_QUOTES, 'UTF-8').'">');
  537. $oPage->add('<input type="hidden" name="datamodel_version" value="'.htmlentities($sUpgradeDMVersion, ENT_QUOTES, 'UTF-8').'">');
  538. }
  539. // Check if there are "extensions" to preserve and if it's possible
  540. if (is_dir($sPreviousVersionDir.'/extensions'))
  541. {
  542. $aExtensions = glob($sPreviousVersionDir.'/extensions/*', GLOB_ONLYDIR);
  543. if (($aExtensions !== false) && (count($aExtensions)>0) && (realpath($sPreviousVersionDir.'/extensions') != realpath(APPROOT.'extensions')) )
  544. {
  545. $aWritableDirs = array('extensions');
  546. $aErrors = SetupUtils::CheckWritableDirs($aWritableDirs);
  547. if (count($aErrors) > 0)
  548. {
  549. $oPage->p("Cannot copy the extensions from '$sPreviousVersionDir/extensions' to '".APPROOT."extensions' due to the following access rights issue(s):");
  550. foreach($aErrors as $sDir => $oCheckResult)
  551. {
  552. $oPage->p('<img src="../images/error.png"/>&nbsp;'.$oCheckResult->sLabel);
  553. }
  554. }
  555. else
  556. {
  557. $oPage->p("<b>Note:</b> The extensions present in '$sPreviousVersionDir/extensions' will be copied to '".APPROOT."extensions'.");
  558. $oPage->add('<input type="hidden" name="copy_extensions_from" value="'.htmlentities($sPreviousVersionDir.'/extensions', ENT_QUOTES, 'UTF-8').'">');
  559. }
  560. }
  561. }
  562. $oPage->add_ready_script(
  563. <<<EOF
  564. $("#changes_summary .title").click(function() { $(this).parent().toggleClass('closed'); } );
  565. $('input[name=upgrade_type]').bind('click change', function() { WizardUpdateButtons(); });
  566. EOF
  567. );
  568. $oMutex = new iTopMutex(
  569. 'cron.'.$this->oWizard->GetParameter('db_name', '').'_'.$this->oWizard->GetParameter('db_prefix', ''),
  570. $this->oWizard->GetParameter('db_server', ''),
  571. $this->oWizard->GetParameter('db_user', ''),
  572. $this->oWizard->GetParameter('db_pwd', '')
  573. );
  574. if ($oMutex->TryLock())
  575. {
  576. $oMutex->Unlock();
  577. }
  578. else
  579. {
  580. $oPage->p("<img src=\"../images/error.png\"/>&nbsp;An iTop CRON process is being executed on the target database. It is highly recommended to stop any iTop CRON process prior to running the setup program.");
  581. }
  582. }
  583. }
  584. public function CanMoveForward()
  585. {
  586. return $this->bCanMoveForward;
  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. if ($("#radio_upgrade_keep").length == 0) return true;
  597. bRet = ($('input[name=upgrade_type]:checked').length > 0);
  598. return bRet;
  599. EOF
  600. ;
  601. }
  602. }
  603. /**
  604. * License acceptation screen
  605. */
  606. class WizStepLicense extends WizardStep
  607. {
  608. public function GetTitle()
  609. {
  610. return 'License Agreement';
  611. }
  612. public function GetPossibleSteps()
  613. {
  614. return array('WizStepDBParams');
  615. }
  616. public function ProcessParams($bMoveForward = true)
  617. {
  618. $this->oWizard->SaveParameter('accept_license', 'no');
  619. return array('class' => 'WizStepDBParams', 'state' => '');
  620. }
  621. public function Display(WebPage $oPage)
  622. {
  623. $aLicenses = SetupUtils::GetLicenses();
  624. $oPage->add('<h2>Licenses agreements for the components of '.ITOP_APPLICATION.'</h2>');
  625. $oPage->add_style('div a.no-arrow { background:transparent; padding-left:0;}');
  626. $oPage->add_style('.toggle { cursor:pointer; text-decoration:underline; color:#1C94C4; }');
  627. $oPage->add('<fieldset>');
  628. $oPage->add('<legend>Components of '.ITOP_APPLICATION.'</legend>');
  629. $oPage->add('<ul>');
  630. foreach($aLicenses as $index => $oLicense)
  631. {
  632. $oPage->add('<li><b>'.$oLicense->product.'</b>, &copy; '.$oLicense->author.' is licensed under the <b>'.$oLicense->license_type.' license</b>. (<span class="toggle" id="toggle_'.$index.'">Details</span>)');
  633. $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>');
  634. $oPage->add_ready_script('$(".license_text a").attr("target", "_blank").addClass("no-arrow");');
  635. $oPage->add_ready_script('$("#toggle_'.$index.'").click( function() { $("#license_'.$index.'").toggle(); } );');
  636. }
  637. $oPage->add('</ul>');
  638. $oPage->add('</fieldset>');
  639. $sChecked = ($this->oWizard->GetParameter('accept_license', 'no') == 'yes') ? ' checked ' : '';
  640. $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>');
  641. $oPage->add_ready_script('$("#accept").bind("click change", function() { WizardUpdateButtons(); });');
  642. }
  643. /**
  644. * Tells whether the "Next" button should be enabled interactively
  645. * @return string A piece of javascript code returning either true or false
  646. */
  647. public function JSCanMoveForward()
  648. {
  649. return 'return ($("#accept").attr("checked") === "checked");';
  650. }
  651. }
  652. /**
  653. * License acceptation screen (when upgrading)
  654. */
  655. class WizStepLicense2 extends WizStepLicense
  656. {
  657. public function GetPossibleSteps()
  658. {
  659. return array('WizStepUpgradeMiscParams');
  660. }
  661. public function ProcessParams($bMoveForward = true)
  662. {
  663. return array('class' => 'WizStepUpgradeMiscParams', 'state' => '');
  664. }
  665. }
  666. /**
  667. * Database Connection parameters screen
  668. */
  669. class WizStepDBParams extends WizardStep
  670. {
  671. public function GetTitle()
  672. {
  673. return 'Database Configuration';
  674. }
  675. public function GetPossibleSteps()
  676. {
  677. return array('WizStepAdminAccount');
  678. }
  679. public function ProcessParams($bMoveForward = true)
  680. {
  681. $this->oWizard->SaveParameter('db_server', '');
  682. $this->oWizard->SaveParameter('db_user', '');
  683. $this->oWizard->SaveParameter('db_pwd', '');
  684. $this->oWizard->SaveParameter('db_name', '');
  685. $this->oWizard->SaveParameter('db_prefix', '');
  686. $this->oWizard->SaveParameter('new_db_name', '');
  687. $this->oWizard->SaveParameter('create_db', '');
  688. $this->oWizard->SaveParameter('db_new_name', '');
  689. return array('class' => 'WizStepAdminAccount', 'state' => '');
  690. }
  691. public function Display(WebPage $oPage)
  692. {
  693. $oPage->add('<h2>Configuration of the database connection:</h2>');
  694. $sDBServer = $this->oWizard->GetParameter('db_server', '');
  695. $sDBUser = $this->oWizard->GetParameter('db_user', '');
  696. $sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
  697. $sDBName = $this->oWizard->GetParameter('db_name', '');
  698. $sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
  699. $sNewDBName = $this->oWizard->GetParameter('db_new_name', false);
  700. $oPage->add('<table>');
  701. SetupUtils::DisplayDBParameters($oPage, true, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName);
  702. $oPage->add('</table>');
  703. $sCreateDB = $this->oWizard->GetParameter('create_db', 'yes');
  704. if ($sCreateDB == 'no')
  705. {
  706. $oPage->add_ready_script('$("#existing_db").attr("checked", "checked");');
  707. }
  708. else
  709. {
  710. $oPage->add_ready_script('$("#create_db").attr("checked", "checked");');
  711. }
  712. }
  713. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  714. {
  715. switch($sCode)
  716. {
  717. case 'check_db':
  718. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  719. break;
  720. }
  721. }
  722. /**
  723. * Tells whether the "Next" button should be enabled interactively
  724. * @return string A piece of javascript code returning either true or false
  725. */
  726. public function JSCanMoveForward()
  727. {
  728. return
  729. <<<EOF
  730. if ($("#wiz_form").data("db_connection") === "error") return false;
  731. var bRet = true;
  732. bRet = ValidateField("db_name", true) && bRet;
  733. bRet = ValidateField("db_new_name", true) && bRet;
  734. bRet = ValidateField("db_prefix", true) && bRet;
  735. return bRet;
  736. EOF
  737. ;
  738. }
  739. }
  740. /**
  741. * Administrator Account definition screen
  742. */
  743. class WizStepAdminAccount extends WizardStep
  744. {
  745. public function GetTitle()
  746. {
  747. return 'Administrator Account';
  748. }
  749. public function GetPossibleSteps()
  750. {
  751. return array('WizStepMiscParams');
  752. }
  753. public function ProcessParams($bMoveForward = true)
  754. {
  755. $this->oWizard->SaveParameter('admin_user', '');
  756. $this->oWizard->SaveParameter('admin_pwd', '');
  757. $this->oWizard->SaveParameter('confirm_pwd', '');
  758. $this->oWizard->SaveParameter('admin_language', 'EN US');
  759. return array('class' => 'WizStepMiscParams', 'state' => '');
  760. }
  761. public function Display(WebPage $oPage)
  762. {
  763. $sAdminUser = $this->oWizard->GetParameter('admin_user', 'admin');
  764. $sAdminPwd = $this->oWizard->GetParameter('admin_pwd', '');
  765. $sConfirmPwd = $this->oWizard->GetParameter('confirm_pwd', '');
  766. $sAdminLanguage = $this->oWizard->GetParameter('admin_language', 'EN US');
  767. $oPage->add('<h2>Definition of the Administrator Account</h2>');
  768. $oPage->add('<fieldset>');
  769. $oPage->add('<legend>Administrator Account</legend>');
  770. $oPage->add('<table>');
  771. $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>');
  772. $oPage->add('<tr><td>Password: </td><td><input id="admin_pwd" autocomplete="off" name="admin_pwd" type="password" size="25" maxlength="64" value="'.htmlentities($sAdminPwd, ENT_QUOTES, 'UTF-8').'"><span id="v_admin_pwd"/></td><tr>');
  773. $oPage->add('<tr><td>Confirm password: </td><td><input id="confirm_pwd" autocomplete="off" name="confirm_pwd" type="password" size="25" maxlength="64" value="'.htmlentities($sConfirmPwd, ENT_QUOTES, 'UTF-8').'"></td><tr>');
  774. $sSourceDir = APPROOT.'dictionaries/';
  775. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  776. $oPage->add('<tr><td>Language: </td><td>');
  777. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'admin_language', $sAdminLanguage));
  778. $oPage->add('</td></tr>');
  779. $oPage->add('</table>');
  780. $oPage->add('</fieldset>');
  781. $oPage->add_ready_script(
  782. <<<EOF
  783. $('#admin_user').bind('change keyup', function() { WizardUpdateButtons(); } );
  784. $('#admin_pwd').bind('change keyup', function() { WizardUpdateButtons(); } );
  785. $('#confirm_pwd').bind('change keyup', function() { WizardUpdateButtons(); } );
  786. EOF
  787. );
  788. }
  789. /**
  790. * Tells whether the "Next" button should be enabled interactively
  791. * @return string A piece of javascript code returning either true or false
  792. */
  793. public function JSCanMoveForward()
  794. {
  795. return
  796. <<<EOF
  797. bRet = ($('#admin_user').val() != '');
  798. if (!bRet)
  799. {
  800. $("#v_admin_user").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  801. }
  802. else
  803. {
  804. $("#v_admin_user").html('');
  805. }
  806. bPasswordsMatch = ($('#admin_pwd').val() == $('#confirm_pwd').val());
  807. if (!bPasswordsMatch)
  808. {
  809. $('#v_admin_pwd').html('<img src="../images/validation_error.png" title="Retyped password do not match"/>');
  810. }
  811. else
  812. {
  813. $('#v_admin_pwd').html('');
  814. }
  815. bRet = bPasswordsMatch && bRet;
  816. return bRet;
  817. EOF
  818. ;
  819. }}
  820. /**
  821. * Miscellaneous Parameters (URL, Sample Data)
  822. */
  823. class WizStepMiscParams extends WizardStep
  824. {
  825. public function GetTitle()
  826. {
  827. return 'Miscellaneous Parameters';
  828. }
  829. public function GetPossibleSteps()
  830. {
  831. return array('WizStepModulesChoice');
  832. }
  833. public function ProcessParams($bMoveForward = true)
  834. {
  835. $this->oWizard->SaveParameter('default_language', '');
  836. $this->oWizard->SaveParameter('application_url', '');
  837. $this->oWizard->SaveParameter('sample_data', 'yes');
  838. return array('class' => 'WizStepModulesChoice', 'state' => 'start_install');
  839. }
  840. public function Display(WebPage $oPage)
  841. {
  842. $sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
  843. $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot());
  844. $sSampleData = $this->oWizard->GetParameter('sample_data', 'yes');
  845. $oPage->add('<h2>Additional parameters</h2>');
  846. $oPage->add('<fieldset>');
  847. $oPage->add('<legend>Default Language</legend>');
  848. $oPage->add('<table>');
  849. $sSourceDir = APPROOT.'dictionaries/';
  850. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  851. $oPage->add('<tr><td>Default Language: </td><td>');
  852. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'default_language', $sDefaultLanguage));
  853. $oPage->add('</td></tr>');
  854. $oPage->add('</table>');
  855. $oPage->add('</fieldset>');
  856. $oPage->add('<fieldset>');
  857. $oPage->add('<legend>Application URL</legend>');
  858. $oPage->add('<table>');
  859. $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>');
  860. $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>');
  861. $oPage->add('</table>');
  862. $oPage->add('</fieldset>');
  863. $oPage->add('<fieldset>');
  864. $oPage->add('<legend>Sample Data</legend>');
  865. $sChecked = ($sSampleData == 'yes') ? ' checked ' : '';
  866. $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.');
  867. $sChecked = ($sSampleData == 'no') ? ' checked ' : '';
  868. $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.');
  869. $oPage->add('</fieldset>');
  870. $oPage->add_ready_script(
  871. <<<EOF
  872. $('#application_url').bind('change keyup', function() { WizardUpdateButtons(); } );
  873. EOF
  874. );
  875. }
  876. /**
  877. * Tells whether the "Next" button should be enabled interactively
  878. * @return string A piece of javascript code returning either true or false
  879. */
  880. public function JSCanMoveForward()
  881. {
  882. return
  883. <<<EOF
  884. bRet = ($('#application_url').val() != '');
  885. if (!bRet)
  886. {
  887. $("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  888. }
  889. else
  890. {
  891. $("#v_application_url").html('');
  892. }
  893. return bRet;
  894. EOF
  895. ;
  896. }
  897. }
  898. /**
  899. * Miscellaneous Parameters (URL...) in case of upgrade
  900. */
  901. class WizStepUpgradeMiscParams extends WizardStep
  902. {
  903. public function GetTitle()
  904. {
  905. return 'Miscellaneous Parameters';
  906. }
  907. public function GetPossibleSteps()
  908. {
  909. return array('WizStepModulesChoice');
  910. }
  911. public function ProcessParams($bMoveForward = true)
  912. {
  913. $this->oWizard->SaveParameter('application_url', '');
  914. return array('class' => 'WizStepModulesChoice', 'state' => 'start_upgrade');
  915. }
  916. public function Display(WebPage $oPage)
  917. {
  918. $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot());
  919. $oPage->add('<h2>Additional parameters</h2>');
  920. $oPage->add('<fieldset>');
  921. $oPage->add('<legend>Application URL</legend>');
  922. $oPage->add('<table>');
  923. $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>');
  924. $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>');
  925. $oPage->add('</table>');
  926. $oPage->add('</fieldset>');
  927. $oPage->add_ready_script(
  928. <<<EOF
  929. $('#application_url').bind('change keyup', function() { WizardUpdateButtons(); } );
  930. EOF
  931. );
  932. }
  933. /**
  934. * Tells whether the "Next" button should be enabled interactively
  935. * @return string A piece of javascript code returning either true or false
  936. */
  937. public function JSCanMoveForward()
  938. {
  939. return
  940. <<<EOF
  941. bRet = ($('#application_url').val() != '');
  942. if (!bRet)
  943. {
  944. $("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  945. }
  946. else
  947. {
  948. $("#v_application_url").html('');
  949. }
  950. return bRet;
  951. EOF
  952. ;
  953. }
  954. }
  955. /**
  956. * Choice of the modules to be installed
  957. */
  958. class WizStepModulesChoice extends WizardStep
  959. {
  960. static protected $SEP = '_';
  961. protected $bUpgrade = false;
  962. public function GetTitle()
  963. {
  964. $aStepInfo = $this->GetStepInfo();
  965. $sTitle = isset($aStepInfo['title']) ? $aStepInfo['title'] : 'Modules selection';
  966. return $sTitle;
  967. }
  968. public function GetPossibleSteps()
  969. {
  970. return array('WizStepModulesChoice', 'WizStepSummary');
  971. }
  972. public function ProcessParams($bMoveForward = true)
  973. {
  974. // Accumulates the selected modules:
  975. $index = $this->GetStepIndex();
  976. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  977. $aSelectedChoices = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  978. $aSelected = utils::ReadParam('choice', array());
  979. $aSelectedChoices[$index] = $aSelected;
  980. $this->oWizard->SetParameter('selected_components', json_encode($aSelectedChoices));
  981. if ($this->GetStepInfo($index) == null)
  982. {
  983. throw new Exception('Internal error: invalid step "'.$index.'" for the choice of modules.');
  984. }
  985. else if ($bMoveForward)
  986. {
  987. if ($this->GetStepInfo(1 + $index) != null)
  988. {
  989. return array('class' => 'WizStepModulesChoice', 'state' => (1+$index));
  990. }
  991. else
  992. {
  993. // Exiting this step of the wizard, let's convert the selection into a list of modules
  994. $aModules = array();
  995. $sDisplayChoices = '<ul>';
  996. for($i = 0; $i <= $index; $i++)
  997. {
  998. $aStepInfo = $this->GetStepInfo($i);
  999. $sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules);
  1000. }
  1001. $sDisplayChoices .= '</ul>';
  1002. if (class_exists('CreateITILProfilesInstaller'))
  1003. {
  1004. $this->oWizard->SetParameter('old_addon', true);
  1005. }
  1006. $this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules)));
  1007. $this->oWizard->SetParameter('display_choices', $sDisplayChoices);
  1008. return array('class' => 'WizStepSummary', 'state' => '');
  1009. }
  1010. }
  1011. }
  1012. public function Display(WebPage $oPage)
  1013. {
  1014. $this->DisplayStep($oPage);
  1015. }
  1016. protected function DisplayStep($oPage)
  1017. {
  1018. // Sanity check (not stopper, to let developpers go further...)
  1019. try
  1020. {
  1021. SetupUtils::AnalyzeInstallation($this->oWizard, true);
  1022. }
  1023. catch(MissingDependencyException $e)
  1024. {
  1025. $oPage->warning($e->getMessage());
  1026. }
  1027. $this->bUpgrade = ($this->oWizard->GetParameter('install_mode') != 'install');
  1028. $aStepInfo = $this->GetStepInfo();
  1029. $oPage->add_style("div.choice { margin: 0.5em;}");
  1030. $oPage->add_style("div.choice a { text-decoration:none; font-weight: bold; color: #1C94C4 }");
  1031. $oPage->add_style("div.description { margin-left: 2em; }");
  1032. $oPage->add_style(".choice-disabled { color: #999; }");
  1033. $oPage->add('<table><tr>');
  1034. $sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
  1035. if (!empty($sBannerPath))
  1036. {
  1037. if (substr($sBannerPath, 0, 1) == '/')
  1038. {
  1039. // absolute path, means relative to APPROOT
  1040. $sBannerUrl = utils::GetDefaultUrlAppRoot().$sBannerPath;
  1041. }
  1042. else
  1043. {
  1044. // relative path: i.e. relative to the directory containing the XML file
  1045. $sFullPath = dirname($this->GetSourceFilePath()).'/'.$sBannerPath;
  1046. $sRealPath = realpath($sFullPath);
  1047. $sBannerUrl = utils::GetDefaultUrlAppRoot().str_replace(realpath(APPROOT), '', $sRealPath);
  1048. }
  1049. $oPage->add('<td><img src="'.$sBannerUrl.'"/><td>');
  1050. }
  1051. $sDescription = isset($aStepInfo['description']) ? $aStepInfo['description'] : '';
  1052. $oPage->add('<td>'.$sDescription.'<td>');
  1053. $oPage->add('</tr></table>');
  1054. // Build the default choices
  1055. $aDefaults = array();
  1056. $aModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1057. $this->GetDefaults($aStepInfo, $aDefaults, $aModules);
  1058. //echo "<pre>aStepInfo:\n ".print_r($aStepInfo, true)."</pre>";
  1059. //echo "<pre>aDefaults:\n ".print_r($aDefaults, true)."</pre>";
  1060. $index = $this->GetStepIndex();
  1061. // retrieve the saved selection
  1062. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  1063. $aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  1064. if (!isset($aParameters[$index]))
  1065. {
  1066. $aParameters[$index] = $aDefaults;
  1067. }
  1068. $aSelectedComponents = $aParameters[$index];
  1069. $oPage->add('<div style="height:250px;overflow:auto;border:#ccc 1px solid;">');
  1070. $this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults);
  1071. $oPage->add('</div>');
  1072. $oPage->add_script(
  1073. <<<EOF
  1074. function CheckChoice(sChoiceId)
  1075. {
  1076. var oElement = $('#'+sChoiceId);
  1077. var bChecked = (oElement.attr('checked') == 'checked');
  1078. var sId = sChoiceId.replace('choice', '');
  1079. if ((oElement.attr('type') == 'radio') && bChecked)
  1080. {
  1081. // Only the radio that is clicked is notified, let's warn the other radio buttons
  1082. sName = oElement.attr('name');
  1083. $('input[name="'+sName+'"]').each(function() {
  1084. var sRadioId = $(this).attr('id');
  1085. if ((sRadioId != sChoiceId) && (sRadioId != undefined))
  1086. {
  1087. CheckChoice(sRadioId);
  1088. }
  1089. });
  1090. }
  1091. $('#sub_choices'+sId).each(function() {
  1092. if (!bChecked)
  1093. {
  1094. $(this).addClass('choice-disabled');
  1095. }
  1096. else
  1097. {
  1098. $(this).removeClass('choice-disabled');
  1099. }
  1100. $('input', this).each(function() {
  1101. if (bChecked)
  1102. {
  1103. if ($(this).attr('data-disabled') != 'disabled')
  1104. {
  1105. // Only non-mandatory fields can be enabled
  1106. $(this).removeAttr('disabled');
  1107. }
  1108. }
  1109. else
  1110. {
  1111. $(this).attr('disabled', 'disabled');
  1112. }
  1113. });
  1114. });
  1115. }
  1116. EOF
  1117. );
  1118. $oPage->add_ready_script(
  1119. <<<EOF
  1120. $('.wiz-choice').bind('change', function() { CheckChoice($(this).attr('id')); } );
  1121. $('.wiz-choice').trigger('change');
  1122. EOF
  1123. );
  1124. }
  1125. protected function GetDefaults($aInfo, &$aDefaults, $aModules, $sParentId = '')
  1126. {
  1127. $aRetScore = array();
  1128. $aScores = array();
  1129. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  1130. foreach($aOptions as $index => $aChoice)
  1131. {
  1132. $sChoiceId = $sParentId.self::$SEP.$index;
  1133. $aScores[$sChoiceId] = array();
  1134. if (!$this->bUpgrade && isset($aChoice['default']) && $aChoice['default'])
  1135. {
  1136. $aDefaults[$sChoiceId] = $sChoiceId;
  1137. }
  1138. if ($this->bUpgrade)
  1139. {
  1140. // In upgrade mode, the defaults are the installed modules
  1141. foreach($aChoice['modules'] as $sModuleId)
  1142. {
  1143. if ($aModules[$sModuleId]['version_db'] != '')
  1144. {
  1145. // A module corresponding to this choice is installed
  1146. $aScores[$sChoiceId][$sModuleId] = true;
  1147. }
  1148. }
  1149. if (count($aScores[$sChoiceId]) == count($aChoice['modules']))
  1150. {
  1151. // All the modules are installed, this choice is selected
  1152. $aDefaults[$sChoiceId] = $sChoiceId;
  1153. }
  1154. $aRetScore = array_merge($aRetScore, $aScores[$sChoiceId]);
  1155. }
  1156. if (isset($aChoice['sub_options']))
  1157. {
  1158. $aScores[$sChoiceId] = array_merge($aScores[$sChoiceId], $this->GetDefaults($aChoice['sub_options'], $aDefaults, $sChoiceId));
  1159. }
  1160. $index++;
  1161. }
  1162. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  1163. $sChoiceName = null;
  1164. $sChoiceIdNone = null;
  1165. foreach($aAlternatives as $index => $aChoice)
  1166. {
  1167. $sChoiceId = $sParentId.self::$SEP.$index;
  1168. $aScores[$sChoiceId] = array();
  1169. if ($sChoiceName == null)
  1170. {
  1171. $sChoiceName = $sChoiceId;
  1172. }
  1173. if (!$this->bUpgrade && isset($aChoice['default']) && $aChoice['default'])
  1174. {
  1175. $aDefaults[$sChoiceName] = $sChoiceId;
  1176. }
  1177. if (isset($aChoice['sub_options']))
  1178. {
  1179. $aScores[$sChoiceId] = $this->GetDefaults($aChoice['sub_options'], $aDefaults, $aModules, $sChoiceId);
  1180. }
  1181. $index++;
  1182. }
  1183. $iMaxScore = 0;
  1184. if ($this->bUpgrade && (count($aAlternatives) > 0))
  1185. {
  1186. // The installed choices have precedence over the 'default' choices
  1187. // In case several choices share the same base modules, let's weight the alternative choices
  1188. // based on their number of installed modules
  1189. $sChoiceName = null;
  1190. foreach($aAlternatives as $index => $aChoice)
  1191. {
  1192. $sChoiceId = $sParentId.self::$SEP.$index;
  1193. if ($sChoiceName == null)
  1194. {
  1195. $sChoiceName = $sChoiceId;
  1196. }
  1197. if (array_key_exists('modules', $aChoice))
  1198. {
  1199. foreach($aChoice['modules'] as $sModuleId)
  1200. {
  1201. if ($aModules[$sModuleId]['version_db'] != '')
  1202. {
  1203. // A module corresponding to this choice is installed, increase the score of this choice
  1204. if (!isset($aScores[$sChoiceId])) $aScores[$sChoiceId] = array();
  1205. $aScores[$sChoiceId][$sModuleId] = true;
  1206. $iMaxScore = max($iMaxScore, count($aScores[$sChoiceId]));
  1207. }
  1208. }
  1209. //if (count($aScores[$sChoiceId]) == count($aChoice['modules']))
  1210. //{
  1211. // $iScore += 100; // Bonus for the parent when a choice is complete
  1212. //}
  1213. $aRetScore = array_merge($aRetScore, $aScores[$sChoiceId]);
  1214. }
  1215. $iMaxScore = max($iMaxScore, isset($aScores[$sChoiceId]) ? count($aScores[$sChoiceId]) : 0);
  1216. }
  1217. }
  1218. if ($iMaxScore > 0)
  1219. {
  1220. $aNumericScores = array();
  1221. foreach($aScores as $sChoiceId => $aModules)
  1222. {
  1223. $aNumericScores[$sChoiceId] = count($aModules);
  1224. }
  1225. // The choice with the bigger score wins !
  1226. asort($aNumericScores, SORT_NUMERIC);
  1227. $aKeys = array_keys($aNumericScores);
  1228. $sBetterChoiceId = array_pop($aKeys);
  1229. $aDefaults[$sChoiceName] = $sBetterChoiceId;
  1230. }
  1231. // echo "Scores: <pre>".print_r($aScores, true)."</pre><br/>";
  1232. // echo "Defaults: <pre>".print_r($aDefaults, true)."</pre><br/>";
  1233. return $aRetScore;
  1234. }
  1235. /**
  1236. * Converts the list of selected "choices" into a list of "modules": take into account the selected and the mandatory modules
  1237. * @param hash $aInfo Info about the "choice" array('options' => array(...), 'alternatives' => array(...))
  1238. * @param hash $aSelectedChoices List of selected choices array('name' => 'selected_value_id')
  1239. * @param hash $aModules Return parameter: List of selected modules array('module_id' => true)
  1240. * @param string $sParentId Used for recursion
  1241. * @return void
  1242. */
  1243. protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '')
  1244. {
  1245. if ($sParentId == '')
  1246. {
  1247. // Check once (before recursing) that the hidden modules are selected
  1248. foreach(SetupUtils::AnalyzeInstallation($this->oWizard) as $sModuleId => $aModule)
  1249. {
  1250. if ($sModuleId != ROOT_MODULE)
  1251. {
  1252. if (($aModule['category'] == 'authentication') || (!$aModule['visible']))
  1253. {
  1254. $aModules[$sModuleId] = true;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  1260. foreach($aOptions as $index => $aChoice)
  1261. {
  1262. $sChoiceId = $sParentId.self::$SEP.$index;
  1263. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  1264. (isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId)) )
  1265. {
  1266. $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
  1267. if (isset($aChoice['modules']))
  1268. {
  1269. foreach($aChoice['modules'] as $sModuleId)
  1270. {
  1271. $aModules[$sModuleId] = true; // store the Id of the selected module
  1272. }
  1273. }
  1274. // Recurse only for selected choices
  1275. if (isset($aChoice['sub_options']))
  1276. {
  1277. $sDisplayChoices .= '<ul>';
  1278. $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices);
  1279. $sDisplayChoices .= '</ul>';
  1280. }
  1281. $sDisplayChoices .= '</li>';
  1282. }
  1283. $index++;
  1284. }
  1285. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  1286. $sChoiceName = null;
  1287. foreach($aAlternatives as $index => $aChoice)
  1288. {
  1289. $sChoiceId = $sParentId.self::$SEP.$index;
  1290. if ($sChoiceName == null)
  1291. {
  1292. $sChoiceName = $sChoiceId;
  1293. }
  1294. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  1295. (isset($aSelectedChoices[$sChoiceName]) && ($aSelectedChoices[$sChoiceName] == $sChoiceId)) )
  1296. {
  1297. $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
  1298. if (isset($aChoice['modules']))
  1299. {
  1300. foreach($aChoice['modules'] as $sModuleId)
  1301. {
  1302. $aModules[$sModuleId] = true; // store the Id of the selected module
  1303. }
  1304. }
  1305. // Recurse only for selected choices
  1306. if (isset($aChoice['sub_options']))
  1307. {
  1308. $sDisplayChoices .= '<ul>';
  1309. $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices);
  1310. $sDisplayChoices .= '</ul>';
  1311. }
  1312. $sDisplayChoices .= '</li>';
  1313. }
  1314. $index++;
  1315. }
  1316. if ($sParentId == '')
  1317. {
  1318. // Last pass (after all the user's choices are turned into "selected" modules):
  1319. // Process 'auto_select' modules for modules that are not already selected
  1320. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1321. do
  1322. {
  1323. // Loop while new modules are added...
  1324. $bModuleAdded = false;
  1325. foreach($aAvailableModules as $sModuleId => $aModule)
  1326. {
  1327. if (($sModuleId != ROOT_MODULE) && !array_key_exists($sModuleId, $aModules) && isset($aModule['auto_select']))
  1328. {
  1329. try
  1330. {
  1331. $bSelected = false;
  1332. SetupInfo::SetSelectedModules($aModules);
  1333. eval('$bSelected = ('.$aModule['auto_select'].');');
  1334. }
  1335. catch(Exception $e)
  1336. {
  1337. $sDisplayChoices .= '<li><b>Warning: auto_select failed with exception ('.$e->getMessage().') for module "'.$sModuleId.'"</b></li>';
  1338. $bSelected = false;
  1339. }
  1340. if ($bSelected)
  1341. {
  1342. $aModules[$sModuleId] = true; // store the Id of the selected module
  1343. $bModuleAdded = true;
  1344. }
  1345. }
  1346. }
  1347. }
  1348. while($bModuleAdded);
  1349. }
  1350. return $sDisplayChoices;
  1351. }
  1352. protected function GetStepIndex()
  1353. {
  1354. switch($this->sCurrentState)
  1355. {
  1356. case 'start_install':
  1357. case 'start_upgrade':
  1358. $index = 0;
  1359. break;
  1360. default:
  1361. $index = (integer)$this->sCurrentState;
  1362. }
  1363. return $index;
  1364. }
  1365. protected function GetStepInfo($idx = null)
  1366. {
  1367. $aStepInfo = null;
  1368. if ($idx === null)
  1369. {
  1370. $index = $this->GetStepIndex();
  1371. }
  1372. else
  1373. {
  1374. $index = $idx;
  1375. }
  1376. $aSteps = array();
  1377. if (@file_exists($this->GetSourceFilePath()))
  1378. {
  1379. $aParams = new XMLParameters($this->GetSourceFilePath());
  1380. $aSteps = $aParams->Get('steps', array());
  1381. $bAddExtensionsOnly = true;
  1382. }
  1383. else
  1384. {
  1385. // No wizard configuration provided, build a standard one:
  1386. $bAddExtensionsOnly = false;
  1387. $aSteps[] = array(
  1388. 'title' => 'Modules Selection',
  1389. '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>',
  1390. 'banner' => '/images/modules.png',
  1391. 'options' => array()
  1392. );
  1393. }
  1394. // Additional step for the extensions
  1395. $aSteps[] = array(
  1396. 'title' => 'Extensions',
  1397. 'description' => '<h2>Select additional extensions to install. You can launch the installation again to install new extensions, but you cannot remove already installed extensions.</h2>',
  1398. 'banner' => '/images/extension.png',
  1399. 'options' => array()
  1400. );
  1401. try
  1402. {
  1403. $sDefaultAppPath = utils::GetDefaultUrlAppRoot();
  1404. }
  1405. catch(Exception $e)
  1406. {
  1407. $sDefaultAppPath = '..';
  1408. }
  1409. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1410. foreach($aAvailableModules as $sModuleId => $aModule)
  1411. {
  1412. if ($sModuleId == ROOT_MODULE) continue; // Convention: the version number of the application (and datamodel) are stored as a module named ROOT_MODULE
  1413. $sModuleLabel = $aModule['label'];
  1414. $sModuleHelp = $aModule['doc.more_information'];
  1415. $sMoreInfo = (!empty($aModule['doc.more_information'])) ? "<a href=\"$sDefaultAppPath{$aModule['doc.more_information']}\" target=\"_blank\">more info</a>": '';
  1416. if (($aModule['category'] != 'authentication') && ($aModule['visible']))
  1417. {
  1418. if (($bAddExtensionsOnly) && (!$this->IsExtension($aModule))) continue;
  1419. if ($this->IsExtension($aModule))
  1420. {
  1421. $iStepIndex = count($aSteps) - 1;
  1422. }
  1423. else
  1424. {
  1425. $iStepIndex = 0;
  1426. }
  1427. $aSteps[$iStepIndex]['options'][] = array(
  1428. 'title' => $sModuleLabel,
  1429. 'description' => '',
  1430. 'more_info' => $sMoreInfo,
  1431. 'default' => true, // by default offer to install all modules
  1432. 'modules' => array($sModuleId),
  1433. 'mandatory' => ($aModule['install']['flag'] & MODULE_ACTION_MANDATORY) ? true : false,
  1434. );
  1435. }
  1436. }
  1437. if (count($aSteps[count($aSteps) - 1]['options']) == 0)
  1438. {
  1439. // No extensions at all, remove the last step
  1440. array_pop($aSteps);
  1441. }
  1442. if (array_key_exists($index, $aSteps))
  1443. {
  1444. $aStepInfo = $aSteps[$index];
  1445. }
  1446. return $aStepInfo;
  1447. }
  1448. protected function GetExtensionsStepInfo()
  1449. {
  1450. // let the user select from the list of modules located in the "extensions" folder
  1451. }
  1452. protected function IsExtension($aModule)
  1453. {
  1454. // root_dir is the directory containing the module, check if its parent is "extensions"
  1455. if (basename(dirname($aModule['root_dir'])) == 'extensions')
  1456. {
  1457. return true;
  1458. }
  1459. return false;
  1460. }
  1461. protected function DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults, $sParentId = '')
  1462. {
  1463. $aOptions = isset($aStepInfo['options']) ? $aStepInfo['options'] : array();
  1464. $aAlternatives = isset($aStepInfo['alternatives']) ? $aStepInfo['alternatives'] : array();
  1465. $index = 0;
  1466. foreach($aOptions as $index => $aChoice)
  1467. {
  1468. $sAttributes = '';
  1469. $sChoiceId = $sParentId.self::$SEP.$index;
  1470. $bIsDefault = array_key_exists($sChoiceId, $aDefaults);
  1471. $bSelected = isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId);
  1472. $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
  1473. if ($bMandatory)
  1474. {
  1475. $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;');
  1476. }
  1477. else if ($bSelected)
  1478. {
  1479. $oPage->add('<div class="choice"><input class="wiz-choice" id="choice'.$sChoiceId.'" name="choice['.$sChoiceId.']" type="checkbox" checked value="'.$sChoiceId.'"/>&nbsp;');
  1480. }
  1481. else
  1482. {
  1483. $oPage->add('<div class="choice"><input class="wiz-choice" id="choice'.$sChoiceId.'" name="choice['.$sChoiceId.']" type="checkbox" value="'.$sChoiceId.'"/>&nbsp;');
  1484. }
  1485. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId);
  1486. $oPage->add('</div>');
  1487. $index++;
  1488. }
  1489. $sChoiceName = null;
  1490. $sDisabled = '';
  1491. $sChoiceIdNone = null;
  1492. foreach($aAlternatives as $index => $aChoice)
  1493. {
  1494. $sChoiceId = $sParentId.self::$SEP.$index;
  1495. if ($sChoiceName == null)
  1496. {
  1497. $sChoiceName = $sChoiceId; // All radios share the same name
  1498. }
  1499. $bIsDefault = array_key_exists($sChoiceName, $aDefaults) && ($aDefaults[$sChoiceName] == $sChoiceId);
  1500. $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
  1501. if ($bMandatory)
  1502. {
  1503. // One choice is mandatory, all alternatives are disabled
  1504. $sDisabled = ' disabled data-disabled="disabled"';
  1505. }
  1506. if ( (!isset($aChoice['sub_options']) || (count($aChoice['sub_options']) == 0)) && (!isset($aChoice['modules']) || (count($aChoice['modules']) == 0)) )
  1507. {
  1508. $sChoiceIdNone = $sChoiceId; // the "None" / empty choice
  1509. }
  1510. }
  1511. foreach($aAlternatives as $index => $aChoice)
  1512. {
  1513. $sAttributes = '';
  1514. $sChoiceId = $sParentId.self::$SEP.$index;
  1515. if ($sChoiceName == null)
  1516. {
  1517. $sChoiceName = $sChoiceId; // All radios share the same name
  1518. }
  1519. $bIsDefault = array_key_exists($sChoiceName, $aDefaults) && ($aDefaults[$sChoiceName] == $sChoiceId);
  1520. $bSelected = isset($aSelectedComponents[$sChoiceName]) && ($aSelectedComponents[$sChoiceName] == $sChoiceId);
  1521. if ( !isset($aSelectedComponents[$sChoiceName]) && ($sChoiceIdNone != null))
  1522. {
  1523. // No choice selected, select the "None" option
  1524. $bSelected = ($sChoiceId == $sChoiceIdNone);
  1525. }
  1526. $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
  1527. if ($bSelected)
  1528. {
  1529. $sAttributes = ' checked ';
  1530. }
  1531. $sHidden = '';
  1532. if ($bMandatory)
  1533. {
  1534. $sAttributes = ' checked ';
  1535. $sHidden = '<input type="hidden" name="choice['.$sChoiceName.']" value="'.$sChoiceId.'"/>';
  1536. }
  1537. $oPage->add('<div class="choice"><input class="wiz-choice" id="choice'.$sChoiceId.'" name="choice['.$sChoiceName.']" type="radio"'.$sAttributes.' value="'.$sChoiceId.'"'.$sDisabled.'/>'.$sHidden.'&nbsp;');
  1538. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId);
  1539. $oPage->add('</div>');
  1540. $index++;
  1541. }
  1542. }
  1543. protected function DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId)
  1544. {
  1545. $sMoreInfo = isset($aChoice['more_info']) ? $aChoice['more_info'] : '';
  1546. $oPage->add('<label for="choice'.$sChoiceId.'"><b>'.htmlentities($aChoice['title'], ENT_QUOTES, 'UTF-8').'</b></label> '.$sMoreInfo);
  1547. $sDescription = isset($aChoice['description']) ? htmlentities($aChoice['description'], ENT_QUOTES, 'UTF-8') : '';
  1548. $oPage->add('<div class="description">'.$sDescription.'<span id="sub_choices'.$sChoiceId.'">');
  1549. if (isset($aChoice['sub_options']))
  1550. {
  1551. $this->DisplayOptions($oPage, $aChoice['sub_options'], $aSelectedComponents, $aDefaults, $sChoiceId);
  1552. }
  1553. $oPage->add('</span></div>');
  1554. }
  1555. protected function GetSourceFilePath()
  1556. {
  1557. $sSourceDir = $this->oWizard->GetParameter('source_dir');
  1558. return $sSourceDir.'/installation.xml';
  1559. }
  1560. }
  1561. /**
  1562. * Summary of the installation tasks
  1563. */
  1564. class WizStepSummary extends WizardStep
  1565. {
  1566. protected $bDependencyCheck = null;
  1567. protected $sDependencyIssue = null;
  1568. protected function CheckDependencies()
  1569. {
  1570. if (is_null($this->bDependencyCheck))
  1571. {
  1572. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  1573. $this->bDependencyCheck = true;
  1574. try
  1575. {
  1576. SetupUtils::AnalyzeInstallation($this->oWizard, true, $aSelectedModules);
  1577. }
  1578. catch(MissingDependencyException $e)
  1579. {
  1580. $this->bDependencyCheck = false;
  1581. $this->sDependencyIssue = $e->getMessage();
  1582. }
  1583. }
  1584. return $this->bDependencyCheck;
  1585. }
  1586. public function GetTitle()
  1587. {
  1588. $sMode = $this->oWizard->GetParameter('mode', 'install');
  1589. if ($sMode == 'install')
  1590. {
  1591. return 'Ready to install';
  1592. }
  1593. else
  1594. {
  1595. return 'Ready to upgrade';
  1596. }
  1597. }
  1598. public function GetPossibleSteps()
  1599. {
  1600. return array('WizStepDone');
  1601. }
  1602. /**
  1603. * Returns the label for the " Next >> " button
  1604. * @return string The label for the button
  1605. */
  1606. public function GetNextButtonLabel()
  1607. {
  1608. return ' Install ! ';
  1609. }
  1610. public function CanMoveForward()
  1611. {
  1612. if ($this->CheckDependencies())
  1613. {
  1614. return true;
  1615. }
  1616. else
  1617. {
  1618. return false;
  1619. }
  1620. }
  1621. public function ProcessParams($bMoveForward = true)
  1622. {
  1623. return array('class' => 'WizStepDone', 'state' => '');
  1624. }
  1625. public function Display(WebPage $oPage)
  1626. {
  1627. $oPage->add_style(
  1628. <<<EOF
  1629. #params_summary {
  1630. height: 200px;
  1631. overflow: auto;
  1632. }
  1633. #params_summary div {
  1634. width:100%;
  1635. margin-top:0;
  1636. padding-top: 0.5em;
  1637. padding-left: 0;
  1638. }
  1639. #params_summary div ul {
  1640. margin-left:0;
  1641. padding-left: 20px;
  1642. }
  1643. #params_summary div.closed ul {
  1644. display:none;
  1645. }
  1646. #params_summary div li {
  1647. list-style: none;
  1648. width: 100%;
  1649. margin-left:0;
  1650. padding-left: 0em;
  1651. }
  1652. .title {
  1653. padding-left: 20px;
  1654. font-weight: bold;
  1655. cursor: pointer;
  1656. background: url(../images/minus.gif) 2px 2px no-repeat;
  1657. }
  1658. #params_summary div.closed .title {
  1659. background: url(../images/plus.gif) 2px 2px no-repeat;
  1660. }
  1661. #progress_content {
  1662. height: 200px;
  1663. overflow: auto;
  1664. text-align: center;
  1665. }
  1666. #installation_progress {
  1667. display: none;
  1668. }
  1669. EOF
  1670. );
  1671. $aInstallParams = $this->BuildConfig();
  1672. $sMode = $aInstallParams['mode'];
  1673. $sPreinstallationPhase = '';
  1674. $sDestination = ITOP_APPLICATION.(($sMode == 'install') ? ' version '.ITOP_VERSION.' is about to be installed ' : ' is about to be upgraded ');
  1675. $sDBDescription = ' <b>existing</b> database <b>'.$aInstallParams['database']['name'].'</b>';
  1676. if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes'))
  1677. {
  1678. $sDBDescription = ' <b>new</b> database <b>'.$aInstallParams['database']['name'].'</b>';
  1679. }
  1680. $sDestination .= 'into the '.$sDBDescription.' on the server <b>'.$aInstallParams['database']['server'].'</b>.';
  1681. $oPage->add('<h2>'.$sDestination.'</h2>');
  1682. $oPage->add('<fieldset id="summary"><legend>Installation Parameters</legend>');
  1683. $oPage->add('<div id="params_summary">');
  1684. $oPage->add('<div class="closed"><span class="title">Database Parameters</span><ul>');
  1685. $oPage->add('<li>Server Name: '.$aInstallParams['database']['server'].'</li>');
  1686. $oPage->add('<li>DB User Name: '.$aInstallParams['database']['user'].'</li>');
  1687. $oPage->add('<li>DB user password: '.$aInstallParams['database']['pwd'].'</li>');
  1688. if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes'))
  1689. {
  1690. $oPage->add('<li>Database Name: '.$aInstallParams['database']['name'].' (will be created)</li>');
  1691. }
  1692. else
  1693. {
  1694. $oPage->add('<li>Database Name: '.$aInstallParams['database']['name'].'</li>');
  1695. }
  1696. if ($aInstallParams['database']['prefix'] != '')
  1697. {
  1698. $oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: '.$aInstallParams['database']['prefix'].'</li>');
  1699. }
  1700. else
  1701. {
  1702. $oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: none</li>');
  1703. }
  1704. $oPage->add('</ul></div>');
  1705. $oPage->add('<div><span class="title">Data Model Configuration</span>');
  1706. $oPage->add($this->oWizard->GetParameter('display_choices'));
  1707. $oPage->add('</div>');
  1708. $oPage->add('<div class="closed"><span class="title">Other Parameters</span><ul>');
  1709. if ($sMode == 'install')
  1710. {
  1711. $oPage->add('<li>Default language: '.$aInstallParams['language'].'</li>');
  1712. }
  1713. $oPage->add('<li>URL to access the application: '.$aInstallParams['url'].'</li>');
  1714. if ($aInstallParams['sample_data'] == 'yes')
  1715. {
  1716. $oPage->add('<li>Sample data will be loaded into the database.</li>');
  1717. }
  1718. if ($aInstallParams['old_addon'])
  1719. {
  1720. $oPage->add('<li>Compatibility mode: Using the version 1.2 of the UserRightsProfiles add-on.</li>');
  1721. }
  1722. $oPage->add('</ul></div>');
  1723. if ($sMode == 'install')
  1724. {
  1725. $oPage->add('<div class="closed"><span class="title">Admininistrator Account</span><ul>');
  1726. $oPage->add('<li>Login: '.$aInstallParams['admin_account']['user'].'</li>');
  1727. $oPage->add('<li>Password: '.$aInstallParams['admin_account']['pwd'].'</li>');
  1728. $oPage->add('<li>Language: '.$aInstallParams['admin_account']['language'].'</li>');
  1729. $oPage->add('</ul></div>');
  1730. }
  1731. $aMiscOptions = $aInstallParams['options'];
  1732. if (count($aMiscOptions) > 0)
  1733. {
  1734. $oPage->add('<div class="closed"><span class="title">Miscellaneous Options</span><ul>');
  1735. foreach($aMiscOptions as $sKey => $sValue)
  1736. {
  1737. $oPage->add('<li>'.$sKey.': '.$sValue.'</li>');
  1738. }
  1739. $oPage->add('</ul></div>');
  1740. }
  1741. $aSelectedModules = $aInstallParams['selected_modules'];
  1742. if (isset($aMiscOptions['generate_config']))
  1743. {
  1744. $oDoc = new DOMDocument('1.0', 'UTF-8');
  1745. $oDoc->preserveWhiteSpace = false;
  1746. $oDoc->formatOutput = true;
  1747. $oParams = new PHPParameters();
  1748. $oParams->LoadFromHash($aInstallParams);
  1749. $oParams->ToXML($oDoc, null, 'installation');
  1750. $sXML = $oDoc->saveXML();
  1751. $oPage->add('<div class="closed"><span class="title">XML Config file</span><ul><pre>');
  1752. $oPage->add(htmlentities($sXML, ENT_QUOTES, 'UTF-8'));
  1753. $oPage->add('</pre></ul></div>');
  1754. }
  1755. $oPage->add('</div>'); // params_summary
  1756. $oPage->add('</fieldset>');
  1757. $oPage->add('<fieldset id="installation_progress"><legend>Progress of the installation</legend>');
  1758. $oPage->add('<div id="progress_content">');
  1759. $oPage->add_linked_script('../setup/jquery.progression.js');
  1760. $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>');
  1761. $oPage->add('</div>'); // progress_content
  1762. $oPage->add('</fieldset>');
  1763. $sJSONData = json_encode($aInstallParams);
  1764. $oPage->add('<input type="hidden" id="installer_parameters" value="'.htmlentities($sJSONData, ENT_QUOTES, 'UTF-8').'"/>');
  1765. if (!$this->CheckDependencies())
  1766. {
  1767. $oPage->error($this->sDependencyIssue);
  1768. }
  1769. $oPage->add_ready_script(
  1770. <<<EOF
  1771. $("#params_summary div").addClass('closed');
  1772. $("#params_summary .title").click(function() { $(this).parent().toggleClass('closed'); } );
  1773. $("#btn_next").bind("click.install", function(event) {
  1774. $('#summary').hide();
  1775. $('#installation_progress').show();
  1776. $(this).attr("disabled", "disabled"); event.preventDefault(); ExecuteStep("");
  1777. });
  1778. $("#wiz_form").data("installation_status", "not started")
  1779. EOF
  1780. );
  1781. }
  1782. /**
  1783. * Prepare the parameters to execute the installation asynchronously
  1784. * @return Hash A big hash array that can be converted to XML or JSON with all the needed parameters
  1785. */
  1786. protected function BuildConfig()
  1787. {
  1788. $sMode = $this->oWizard->GetParameter('install_mode', 'install');
  1789. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  1790. $sBackupDestination = '';
  1791. $sPreviousConfigurationFile = '';
  1792. $sDBName = $this->oWizard->GetParameter('db_name');
  1793. if ($sMode == 'upgrade')
  1794. {
  1795. $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', '');
  1796. if (!empty($sPreviousVersionDir))
  1797. {
  1798. $aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir);
  1799. if ($aPreviousInstance['found'])
  1800. {
  1801. $sPreviousConfigurationFile = $aPreviousInstance['configuration_file'];
  1802. }
  1803. }
  1804. if ($this->oWizard->GetParameter('db_backup', false))
  1805. {
  1806. $sBackupDestination = $this->oWizard->GetParameter('db_backup_path', '');
  1807. }
  1808. }
  1809. else
  1810. {
  1811. $sDBNewName = $this->oWizard->GetParameter('db_new_name', '');
  1812. if ($sDBNewName != '')
  1813. {
  1814. $sDBName = $sDBNewName; // Database will be created
  1815. }
  1816. }
  1817. $sSourceDir = $this->oWizard->GetParameter('source_dir');
  1818. $aCopies = array();
  1819. if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous'))
  1820. {
  1821. $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir');
  1822. $aCopies[] = array('source' => $sSourceDir, 'destination' => 'modules'); // Source is an absolute path, destination is relative to APPROOT
  1823. $aCopies[] = array('source' => $sPreviousVersionDir.'/portal', 'destination' => 'portal'); // Source is an absolute path, destination is relative to APPROOT
  1824. $sSourceDir = APPROOT.'modules';
  1825. }
  1826. if (($sMode == 'upgrade'))
  1827. {
  1828. // Copy the previous extensions, if any
  1829. $sPreviousExtensionsDir = $this->oWizard->GetParameter('copy_extensions_from');
  1830. if (is_dir($sPreviousExtensionsDir))
  1831. {
  1832. // Copy the extensions one by one to merge them with the existing extensions in /extensions
  1833. $aExtensions = glob($sPreviousExtensionsDir.'/*', GLOB_ONLYDIR);
  1834. foreach($aExtensions as $sDirPath)
  1835. {
  1836. $sExtName = basename($sDirPath);
  1837. $aCopies[] = array('source' => $sDirPath, 'destination' => 'extensions/'.$sExtName); // Source is an absolute path, destination is relative to APPROOT
  1838. }
  1839. }
  1840. }
  1841. $aInstallParams = array (
  1842. 'mode' => $sMode,
  1843. 'preinstall' => array (
  1844. 'copies' => $aCopies,
  1845. // 'backup' => see below
  1846. ),
  1847. 'source_dir' => str_replace(APPROOT, '', $sSourceDir),
  1848. 'datamodel_version' => $this->oWizard->GetParameter('datamodel_version'), //TODO: let the installer compute this automatically...
  1849. 'previous_configuration_file' => $sPreviousConfigurationFile,
  1850. 'extensions_dir' => 'extensions',
  1851. 'target_env' => 'production',
  1852. 'workspace_dir' => '',
  1853. 'database' => array (
  1854. 'server' => $this->oWizard->GetParameter('db_server'),
  1855. 'user' => $this->oWizard->GetParameter('db_user'),
  1856. 'pwd' => $this->oWizard->GetParameter('db_pwd'),
  1857. 'name' => $sDBName,
  1858. 'prefix' => $this->oWizard->GetParameter('db_prefix'),
  1859. ),
  1860. 'url' => $this->oWizard->GetParameter('application_url'),
  1861. 'admin_account' => array (
  1862. 'user' => $this->oWizard->GetParameter('admin_user'),
  1863. 'pwd' => $this->oWizard->GetParameter('admin_pwd'),
  1864. 'language' => $this->oWizard->GetParameter('admin_language'),
  1865. ),
  1866. 'language' => $this->oWizard->GetParameter('default_language'),
  1867. 'selected_modules' => $aSelectedModules,
  1868. 'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false ,
  1869. 'old_addon' => $this->oWizard->GetParameter('old_addon', false), // whether or not to use the "old" userrights profile addon
  1870. 'options' => json_decode($this->oWizard->GetParameter('misc_options', '[]'), true),
  1871. );
  1872. if ($sBackupDestination != '')
  1873. {
  1874. $aInstallParams['preinstall']['backup'] = array (
  1875. 'destination' => $sBackupDestination,
  1876. 'configuration_file' => $sPreviousConfigurationFile,
  1877. );
  1878. }
  1879. return $aInstallParams;
  1880. }
  1881. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  1882. {
  1883. $oParameters = new PHPParameters();
  1884. $sStep = $aParameters['installer_step'];
  1885. $sJSONParameters = $aParameters['installer_config'];
  1886. $oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
  1887. $oInstaller = new ApplicationInstaller($oParameters);
  1888. $aRes = $oInstaller->ExecuteStep($sStep);
  1889. if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != ''))
  1890. {
  1891. // Tell the web page to move the progress bar and to launch the next step
  1892. $sMessage = addslashes(htmlentities($aRes['next-step-label'], ENT_QUOTES, 'UTF-8'));
  1893. $oPage->add_ready_script(
  1894. <<<EOF
  1895. $("#wiz_form").data("installation_status", "running");
  1896. WizardUpdateButtons();
  1897. $('#setup_msg').html('$sMessage');
  1898. $('#progress').progression( {Current:{$aRes['percentage-completed']}, Maximum: 100, aBackgroundImg: GetAbsoluteUrlAppRoot()+'setup/orange-progress.gif', aTextColor: '#000000'} );
  1899. //$("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
  1900. ExecuteStep('{$aRes['next-step']}');
  1901. EOF
  1902. );
  1903. }
  1904. else if ($aRes['status'] != ApplicationInstaller::ERROR)
  1905. {
  1906. // Installation complete, move to the next step of the wizard
  1907. $oPage->add_ready_script(
  1908. <<<EOF
  1909. $("#wiz_form").data("installation_status", "completed");
  1910. $('#progress').progression( {Current:100, Maximum: 100, aBackgroundImg: GetAbsoluteUrlAppRoot()+'setup/orange-progress.gif', aTextColor: '#000000'} );
  1911. WizardUpdateButtons();
  1912. $("#btn_next").unbind("click.install");
  1913. $("#btn_next").click();
  1914. EOF
  1915. );
  1916. }
  1917. else
  1918. {
  1919. $sMessage = addslashes(htmlentities($aRes['message'], ENT_QUOTES, 'UTF-8'));
  1920. $oPage->add_ready_script(
  1921. <<<EOF
  1922. $("#wiz_form").data("installation_status", "error");
  1923. WizardUpdateButtons();
  1924. $('#setup_msg').html('$sMessage');
  1925. EOF
  1926. );
  1927. }
  1928. }
  1929. /**
  1930. * Tells whether the "Next" button should be enabled interactively
  1931. * @return string A piece of javascript code returning either true or false
  1932. */
  1933. public function JSCanMoveForward()
  1934. {
  1935. return 'return (($("#wiz_form").data("installation_status") === "not started") || ($("#wiz_form").data("installation_status") === "completed"));';
  1936. }
  1937. /**
  1938. * Tells whether the "Next" button should be enabled interactively
  1939. * @return string A piece of javascript code returning either true or false
  1940. */
  1941. public function JSCanMoveBackward()
  1942. {
  1943. return 'var sStatus = $("#wiz_form").data("installation_status"); return ((sStatus === "not started") || (sStatus === "error"));';
  1944. }
  1945. }
  1946. /**
  1947. * Summary of the installation tasks
  1948. */
  1949. class WizStepDone extends WizardStep
  1950. {
  1951. public function GetTitle()
  1952. {
  1953. return 'Done';
  1954. }
  1955. public function GetPossibleSteps()
  1956. {
  1957. return array();
  1958. }
  1959. public function ProcessParams($bMoveForward = true)
  1960. {
  1961. return array('class' => '', 'state' => '');
  1962. }
  1963. public function Display(WebPage $oPage)
  1964. {
  1965. // Check if there are some manual steps required:
  1966. $aManualSteps = array();
  1967. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1968. $sRootUrl = utils::GetAbsoluteUrlAppRoot();
  1969. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  1970. foreach($aSelectedModules as $sModuleId)
  1971. {
  1972. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  1973. {
  1974. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $sRootUrl.$aAvailableModules[$sModuleId]['doc.manual_setup'];
  1975. }
  1976. }
  1977. if (count($aManualSteps) > 0)
  1978. {
  1979. $oPage->add("<h2>Manual operations required</h2>");
  1980. $oPage->p("In order to complete the installation, the following manual operations are required:");
  1981. foreach($aManualSteps as $sModuleLabel => $sUrl)
  1982. {
  1983. $oPage->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  1984. }
  1985. $oPage->add("<h2>Congratulations for installing ".ITOP_APPLICATION."</h2>");
  1986. }
  1987. else
  1988. {
  1989. $oPage->add("<h2>Congratulations for installing ".ITOP_APPLICATION."</h2>");
  1990. $oPage->ok("The installation completed successfully.");
  1991. }
  1992. if (($this->oWizard->GetParameter('mode', '') == 'upgrade') && $this->oWizard->GetParameter('db_backup', false))
  1993. {
  1994. $sBackupDestination = $this->oWizard->GetParameter('db_backup_path', '');
  1995. if (file_exists($sBackupDestination))
  1996. {
  1997. // To mitigate security risks: pass only the filename without the extension, the download will add the extension itself
  1998. $sTruncatedFilePath = preg_replace('/\.zip$/', '', $sBackupDestination);
  1999. $oPage->p('Your backup is ready');
  2000. $oPage->p('<a style="background:transparent;" href="'.utils::GetAbsoluteUrlAppRoot().'setup/ajax.dataloader.php?operation=async_action&step_class=WizStepDone&params[backup]='.urlencode($sTruncatedFilePath).'" target="_blank"><img src="../images/tar.png" style="border:0;vertical-align:middle;">&nbsp;Download '.basename($sBackupDestination).'</a>');
  2001. }
  2002. else
  2003. {
  2004. $oPage->p('<img src="../images/error.png"/>&nbsp;Warning: Backup creation failed !');
  2005. }
  2006. }
  2007. // Form goes here.. No back button since the job is done !
  2008. $oPage->add('<table style="width:600px;border:0;padding:0;"><tr>');
  2009. $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>");
  2010. $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>");
  2011. $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>");
  2012. $oPage->add('</tr></table>');
  2013. $sForm = '<form method="post" action="'.$this->oWizard->GetParameter('application_url').'pages/UI.php">';
  2014. $sForm .= '<input type="hidden" name="auth_user" value="'.htmlentities($this->oWizard->GetParameter('admin_user'), ENT_QUOTES, 'UTF-8').'">';
  2015. $sForm .= '<input type="hidden" name="auth_pwd" value="'.htmlentities($this->oWizard->GetParameter('admin_pwd'), ENT_QUOTES, 'UTF-8').'">';
  2016. $sForm .= "<p style=\"text-align:center;width:100%\"><button id=\"enter_itop\" type=\"submit\">Enter ".ITOP_APPLICATION."</button></p>";
  2017. $sForm .= '</form>';
  2018. $sPHPVersion = phpversion();
  2019. $sMySQLVersion = SetupUtils::GetMySQLVersion($this->oWizard->GetParameter('db_server'), $this->oWizard->GetParameter('db_user'), $this->oWizard->GetParameter('db_pwd'));
  2020. $oPage->add('<img style="border:0" src="http://www.combodo.com/stats/?p='.urlencode(ITOP_APPLICATION).'&v='.urlencode(ITOP_VERSION).'&php='.urlencode($sPHPVersion).'&mysql='.urlencode($sMySQLVersion).'&os='.urlencode(PHP_OS).'"/>');
  2021. $sForm = addslashes($sForm);
  2022. $oPage->add_ready_script("$('#wiz_form').after('$sForm');");
  2023. }
  2024. public function CanMoveForward()
  2025. {
  2026. return false;
  2027. }
  2028. public function CanMoveBackward()
  2029. {
  2030. return false;
  2031. }
  2032. /**
  2033. * Tells whether this step of the wizard requires that the configuration file be writable
  2034. * @return bool True if the wizard will possibly need to modify the configuration at some point
  2035. */
  2036. public function RequiresWritableConfig()
  2037. {
  2038. return false; //This step executes once the config was written and secured
  2039. }
  2040. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  2041. {
  2042. $oParameters = new PHPParameters();
  2043. // For security reasons: add the extension now so that this action can be used to read *only* .zip files from the disk...
  2044. $sBackupFile = $aParameters['backup'].'.zip';
  2045. if (file_exists($sBackupFile))
  2046. {
  2047. // Make sure there is NO output at all before our content, otherwise the document will be corrupted
  2048. $sPreviousContent = ob_get_clean();
  2049. $oPage->SetContentType('application/zip');
  2050. $oPage->SetContentDisposition('attachment', basename($sBackupFile));
  2051. $oPage->add(file_get_contents($sBackupFile));
  2052. }
  2053. }
  2054. }