wizardsteps.class.inc.php 81 KB

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