wizardsteps.class.inc.php 67 KB

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