wizardsteps.class.inc.php 83 KB

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