wizardsteps.class.inc.php 89 KB

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