wizardsteps.class.inc.php 75 KB

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