wizardsteps.class.inc.php 75 KB

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