wizardsteps.class.inc.php 76 KB

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