wizardsteps.class.inc.php 69 KB

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