wizardsteps.class.inc.php 90 KB

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