wizardsteps.class.inc.php 90 KB

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