wizardsteps.class.inc.php 76 KB

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