wizardsteps.class.inc.php 83 KB

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