wizardsteps.class.inc.php 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601
  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. public function Display(WebPage $oPage)
  620. {
  621. $aLicenses = SetupUtils::GetLicenses();
  622. $oPage->add('<h2>Licenses agreements for the components of '.ITOP_APPLICATION.'</h2>');
  623. $oPage->add_style('div a.no-arrow { background:transparent; padding-left:0;}');
  624. $oPage->add_style('.toggle { cursor:pointer; text-decoration:underline; color:#1C94C4; }');
  625. $oPage->add('<fieldset>');
  626. $oPage->add('<legend>Components of '.ITOP_APPLICATION.'</legend>');
  627. $oPage->add('<ul>');
  628. foreach($aLicenses as $index => $oLicense)
  629. {
  630. $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>)');
  631. $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>');
  632. $oPage->add_ready_script('$(".license_text a").attr("target", "_blank").addClass("no-arrow");');
  633. $oPage->add_ready_script('$("#toggle_'.$index.'").click( function() { $("#license_'.$index.'").toggle(); } );');
  634. }
  635. $oPage->add('</ul>');
  636. $oPage->add('</fieldset>');
  637. $sChecked = ($this->oWizard->GetParameter('accept_license', 'no') == 'yes') ? ' checked ' : '';
  638. $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>');
  639. $oPage->add_ready_script('$("#accept").bind("click change", function() { WizardUpdateButtons(); });');
  640. }
  641. /**
  642. * Tells whether the "Next" button should be enabled interactively
  643. * @return string A piece of javascript code returning either true or false
  644. */
  645. public function JSCanMoveForward()
  646. {
  647. return 'return ($("#accept").attr("checked") === "checked");';
  648. }
  649. }
  650. /**
  651. * License acceptation screen (when upgrading)
  652. */
  653. class WizStepLicense2 extends WizStepLicense
  654. {
  655. public function GetPossibleSteps()
  656. {
  657. return array('WizStepUpgradeMiscParams');
  658. }
  659. public function ProcessParams($bMoveForward = true)
  660. {
  661. return array('class' => 'WizStepUpgradeMiscParams', 'state' => '');
  662. }
  663. }
  664. /**
  665. * Database Connection parameters screen
  666. */
  667. class WizStepDBParams extends WizardStep
  668. {
  669. public function GetTitle()
  670. {
  671. return 'Database Configuration';
  672. }
  673. public function GetPossibleSteps()
  674. {
  675. return array('WizStepAdminAccount');
  676. }
  677. public function ProcessParams($bMoveForward = true)
  678. {
  679. $this->oWizard->SaveParameter('db_server', '');
  680. $this->oWizard->SaveParameter('db_user', '');
  681. $this->oWizard->SaveParameter('db_pwd', '');
  682. $this->oWizard->SaveParameter('db_name', '');
  683. $this->oWizard->SaveParameter('db_prefix', '');
  684. $this->oWizard->SaveParameter('new_db_name', '');
  685. $this->oWizard->SaveParameter('create_db', '');
  686. $this->oWizard->SaveParameter('db_new_name', '');
  687. return array('class' => 'WizStepAdminAccount', 'state' => '');
  688. }
  689. public function Display(WebPage $oPage)
  690. {
  691. $oPage->add('<h2>Configuration of the database connection:</h2>');
  692. $sDBServer = $this->oWizard->GetParameter('db_server', '');
  693. $sDBUser = $this->oWizard->GetParameter('db_user', '');
  694. $sDBPwd = $this->oWizard->GetParameter('db_pwd', '');
  695. $sDBName = $this->oWizard->GetParameter('db_name', '');
  696. $sDBPrefix = $this->oWizard->GetParameter('db_prefix', '');
  697. $sNewDBName = $this->oWizard->GetParameter('db_new_name', false);
  698. $oPage->add('<table>');
  699. SetupUtils::DisplayDBParameters($oPage, true, $sDBServer, $sDBUser, $sDBPwd, $sDBName, $sDBPrefix, $sNewDBName);
  700. $oPage->add('</table>');
  701. $sCreateDB = $this->oWizard->GetParameter('create_db', 'yes');
  702. if ($sCreateDB == 'no')
  703. {
  704. $oPage->add_ready_script('$("#existing_db").attr("checked", "checked");');
  705. }
  706. else
  707. {
  708. $oPage->add_ready_script('$("#create_db").attr("checked", "checked");');
  709. }
  710. }
  711. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  712. {
  713. switch($sCode)
  714. {
  715. case 'check_db':
  716. SetupUtils:: AsyncCheckDB($oPage, $aParameters);
  717. break;
  718. }
  719. }
  720. /**
  721. * Tells whether the "Next" button should be enabled interactively
  722. * @return string A piece of javascript code returning either true or false
  723. */
  724. public function JSCanMoveForward()
  725. {
  726. return
  727. <<<EOF
  728. if ($("#wiz_form").data("db_connection") === "error") return false;
  729. var bRet = true;
  730. bRet = ValidateField("db_name", true) && bRet;
  731. bRet = ValidateField("db_new_name", true) && bRet;
  732. bRet = ValidateField("db_prefix", true) && bRet;
  733. return bRet;
  734. EOF
  735. ;
  736. }
  737. }
  738. /**
  739. * Administrator Account definition screen
  740. */
  741. class WizStepAdminAccount extends WizardStep
  742. {
  743. public function GetTitle()
  744. {
  745. return 'Administrator Account';
  746. }
  747. public function GetPossibleSteps()
  748. {
  749. return array('WizStepMiscParams');
  750. }
  751. public function ProcessParams($bMoveForward = true)
  752. {
  753. $this->oWizard->SaveParameter('admin_user', '');
  754. $this->oWizard->SaveParameter('admin_pwd', '');
  755. $this->oWizard->SaveParameter('confirm_pwd', '');
  756. $this->oWizard->SaveParameter('admin_language', 'EN US');
  757. return array('class' => 'WizStepMiscParams', 'state' => '');
  758. }
  759. public function Display(WebPage $oPage)
  760. {
  761. $sAdminUser = $this->oWizard->GetParameter('admin_user', 'admin');
  762. $sAdminPwd = $this->oWizard->GetParameter('admin_pwd', '');
  763. $sConfirmPwd = $this->oWizard->GetParameter('confirm_pwd', '');
  764. $sAdminLanguage = $this->oWizard->GetParameter('admin_language', 'EN US');
  765. $oPage->add('<h2>Definition of the Administrator Account</h2>');
  766. $oPage->add('<fieldset>');
  767. $oPage->add('<legend>Administrator Account</legend>');
  768. $oPage->add('<table>');
  769. $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>');
  770. $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>');
  771. $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>');
  772. $sSourceDir = APPROOT.'dictionaries/';
  773. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  774. $oPage->add('<tr><td>Language: </td><td>');
  775. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'admin_language', $sAdminLanguage));
  776. $oPage->add('</td></tr>');
  777. $oPage->add('</table>');
  778. $oPage->add('</fieldset>');
  779. $oPage->add_ready_script(
  780. <<<EOF
  781. $('#admin_user').bind('change keyup', function() { WizardUpdateButtons(); } );
  782. $('#admin_pwd').bind('change keyup', function() { WizardUpdateButtons(); } );
  783. $('#confirm_pwd').bind('change keyup', function() { WizardUpdateButtons(); } );
  784. EOF
  785. );
  786. }
  787. /**
  788. * Tells whether the "Next" button should be enabled interactively
  789. * @return string A piece of javascript code returning either true or false
  790. */
  791. public function JSCanMoveForward()
  792. {
  793. return
  794. <<<EOF
  795. bRet = ($('#admin_user').val() != '');
  796. if (!bRet)
  797. {
  798. $("#v_admin_user").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  799. }
  800. else
  801. {
  802. $("#v_admin_user").html('');
  803. }
  804. bPasswordsMatch = ($('#admin_pwd').val() == $('#confirm_pwd').val());
  805. if (!bPasswordsMatch)
  806. {
  807. $('#v_admin_pwd').html('<img src="../images/validation_error.png" title="Retyped password do not match"/>');
  808. }
  809. else
  810. {
  811. $('#v_admin_pwd').html('');
  812. }
  813. bRet = bPasswordsMatch && bRet;
  814. return bRet;
  815. EOF
  816. ;
  817. }}
  818. /**
  819. * Miscellaneous Parameters (URL, Sample Data)
  820. */
  821. class WizStepMiscParams extends WizardStep
  822. {
  823. public function GetTitle()
  824. {
  825. return 'Miscellaneous Parameters';
  826. }
  827. public function GetPossibleSteps()
  828. {
  829. return array('WizStepModulesChoice');
  830. }
  831. public function ProcessParams($bMoveForward = true)
  832. {
  833. $this->oWizard->SaveParameter('default_language', '');
  834. $this->oWizard->SaveParameter('application_url', '');
  835. $this->oWizard->SaveParameter('graphviz_path', '');
  836. $this->oWizard->SaveParameter('sample_data', 'yes');
  837. return array('class' => 'WizStepModulesChoice', 'state' => 'start_install');
  838. }
  839. public function Display(WebPage $oPage)
  840. {
  841. $sDefaultLanguage = $this->oWizard->GetParameter('default_language', $this->oWizard->GetParameter('admin_language'));
  842. $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot());
  843. $sDefaultGraphvizPath = (strtolower(substr(PHP_OS, 0, 3)) === 'win') ? 'C:\\Program Files\\Graphviz\\bin\\dot.exe' : '/usr/bin/dot';
  844. $sGraphvizPath = $this->oWizard->GetParameter('graphviz_path', $sDefaultGraphvizPath);
  845. $sSampleData = $this->oWizard->GetParameter('sample_data', 'yes');
  846. $oPage->add('<h2>Additional parameters</h2>');
  847. $oPage->add('<fieldset>');
  848. $oPage->add('<legend>Default Language</legend>');
  849. $oPage->add('<table>');
  850. $sSourceDir = APPROOT.'dictionaries/';
  851. $aLanguages = SetupUtils::GetAvailableLanguages($sSourceDir);
  852. $oPage->add('<tr><td>Default Language: </td><td>');
  853. $oPage->add(SetupUtils::GetLanguageSelect($sSourceDir, 'default_language', $sDefaultLanguage));
  854. $oPage->add('</td></tr>');
  855. $oPage->add('</table>');
  856. $oPage->add('</fieldset>');
  857. $oPage->add('<fieldset>');
  858. $oPage->add('<legend>Application URL</legend>');
  859. $oPage->add('<table>');
  860. $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>');
  861. $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>');
  862. $oPage->add('</table>');
  863. $oPage->add('</fieldset>');
  864. $oPage->add('<fieldset>');
  865. $oPage->add('<legend>Path to Graphviz\' dot application</legend>');
  866. $oPage->add('<table>');
  867. $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>');
  868. $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>');
  869. $oPage->add('<tr><td colspan="2"><span id="graphviz_status"></span></td><tr>');
  870. $oPage->add('</table>');
  871. $oPage->add('</fieldset>');
  872. $oPage->add('<fieldset>');
  873. $oPage->add('<legend>Sample Data</legend>');
  874. $sChecked = ($sSampleData == 'yes') ? ' checked ' : '';
  875. $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.');
  876. $sChecked = ($sSampleData == 'no') ? ' checked ' : '';
  877. $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.');
  878. $oPage->add('</fieldset>');
  879. $oPage->add_ready_script(
  880. <<<EOF
  881. $('#application_url').bind('change keyup', function() { WizardUpdateButtons(); } );
  882. $('#graphviz_path').bind('change keyup init', function() { WizardUpdateButtons(); WizardAsyncAction('check_graphviz', { graphviz_path: $('#graphviz_path').val() }); } ).trigger('init');
  883. $('#btn_next').click(function() {
  884. bRet = true;
  885. if ($(this).attr('data-graphviz') != 'ok')
  886. {
  887. bRet = confirm('The impact analysis will not be displayed properly. Are you sure you want to continue?');
  888. }
  889. return bRet;
  890. });
  891. EOF
  892. );
  893. }
  894. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  895. {
  896. switch($sCode)
  897. {
  898. case 'check_graphviz':
  899. $sGraphvizPath = $aParameters['graphviz_path'];
  900. $oCheck = SetupUtils::CheckGraphviz($sGraphvizPath);
  901. $sMessage = json_encode($oCheck->sLabel);
  902. switch($oCheck->iSeverity)
  903. {
  904. case CheckResult::INFO:
  905. $sStatus = 'ok';
  906. $sMessage = json_encode('<img src="../images/validation_ok.png">&nbsp;'.$oCheck->sLabel);
  907. break;
  908. default:
  909. case CheckResult::ERROR:
  910. case CheckResult::WARNING:
  911. $sStatus = 'ko';
  912. $sMessage = json_encode('<img src="../images/error.png">&nbsp;'.$oCheck->sLabel);
  913. }
  914. $oPage->add_ready_script(
  915. <<<EOF
  916. $("#graphviz_status").html($sMessage);
  917. $('#btn_next').attr('data-graphviz', '$sStatus');
  918. EOF
  919. );
  920. break;
  921. }
  922. }
  923. /**
  924. * Tells whether the "Next" button should be enabled interactively
  925. * @return string A piece of javascript code returning either true or false
  926. */
  927. public function JSCanMoveForward()
  928. {
  929. return
  930. <<<EOF
  931. bRet = ($('#application_url').val() != '');
  932. if (!bRet)
  933. {
  934. $("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  935. }
  936. else
  937. {
  938. $("#v_application_url").html('');
  939. }
  940. bGraphviz = ($('#graphviz_path').val() != '');
  941. if (!bGraphviz)
  942. {
  943. // Does not prevent to move forward
  944. $("#v_graphviz_path").html('<img src="../images/validation_error.png" title="Impact analysis will not display properly"/>');
  945. }
  946. else
  947. {
  948. $("#v_graphviz_path").html('');
  949. }
  950. return bRet;
  951. EOF
  952. ;
  953. }
  954. }
  955. /**
  956. * Miscellaneous Parameters (URL...) in case of upgrade
  957. */
  958. class WizStepUpgradeMiscParams extends WizardStep
  959. {
  960. public function GetTitle()
  961. {
  962. return 'Miscellaneous Parameters';
  963. }
  964. public function GetPossibleSteps()
  965. {
  966. return array('WizStepModulesChoice');
  967. }
  968. public function ProcessParams($bMoveForward = true)
  969. {
  970. $this->oWizard->SaveParameter('application_url', '');
  971. $this->oWizard->SaveParameter('graphviz_path', '');
  972. return array('class' => 'WizStepModulesChoice', 'state' => 'start_upgrade');
  973. }
  974. public function Display(WebPage $oPage)
  975. {
  976. $sApplicationURL = $this->oWizard->GetParameter('application_url', utils::GetDefaultUrlAppRoot());
  977. $sDefaultGraphvizPath = (strtolower(substr(PHP_OS, 0, 3)) === 'win') ? 'C:\\Program Files\\Graphviz\\bin\\dot.exe' : '/usr/bin/dot';
  978. $sGraphvizPath = $this->oWizard->GetParameter('graphviz_path', $sDefaultGraphvizPath);
  979. $oPage->add('<h2>Additional parameters</h2>');
  980. $oPage->add('<fieldset>');
  981. $oPage->add('<legend>Application URL</legend>');
  982. $oPage->add('<table>');
  983. $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>');
  984. $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>');
  985. $oPage->add('</table>');
  986. $oPage->add('</fieldset>');
  987. $oPage->add('<fieldset>');
  988. $oPage->add('<legend>Path to Graphviz\' dot application</legend>');
  989. $oPage->add('<table>');
  990. $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>');
  991. $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>');
  992. $oPage->add('<tr><td colspan="2"><span id="graphviz_status"></span></td><tr>');
  993. $oPage->add('</table>');
  994. $oPage->add('</fieldset>');
  995. $oPage->add_ready_script(
  996. <<<EOF
  997. $('#application_url').bind('change keyup', function() { WizardUpdateButtons(); } );
  998. $('#graphviz_path').bind('change keyup init', function() { WizardUpdateButtons(); WizardAsyncAction('check_graphviz', { graphviz_path: $('#graphviz_path').val() }); } ).trigger('init');
  999. $('#btn_next').click(function() {
  1000. bRet = true;
  1001. if ($(this).attr('data-graphviz') != 'ok')
  1002. {
  1003. bRet = confirm('The impact analysis will not be displayed properly. Are you sure you want to continue?');
  1004. }
  1005. return bRet;
  1006. });
  1007. EOF
  1008. );
  1009. }
  1010. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  1011. {
  1012. switch($sCode)
  1013. {
  1014. case 'check_graphviz':
  1015. $sGraphvizPath = $aParameters['graphviz_path'];
  1016. $oCheck = SetupUtils::CheckGraphviz($sGraphvizPath);
  1017. $sMessage = json_encode($oCheck->sLabel);
  1018. switch($oCheck->iSeverity)
  1019. {
  1020. case CheckResult::INFO:
  1021. $sStatus = 'ok';
  1022. $sMessage = json_encode('<img src="../images/validation_ok.png">&nbsp;'.$oCheck->sLabel);
  1023. break;
  1024. default:
  1025. case CheckResult::ERROR:
  1026. case CheckResult::WARNING:
  1027. $sStatus = 'ko';
  1028. $sMessage = json_encode('<img src="../images/error.png">&nbsp;'.$oCheck->sLabel);
  1029. }
  1030. $oPage->add_ready_script(
  1031. <<<EOF
  1032. $("#graphviz_status").html($sMessage);
  1033. $('#btn_next').attr('data-graphviz', '$sStatus');
  1034. EOF
  1035. );
  1036. break;
  1037. }
  1038. }
  1039. /**
  1040. * Tells whether the "Next" button should be enabled interactively
  1041. * @return string A piece of javascript code returning either true or false
  1042. */
  1043. public function JSCanMoveForward()
  1044. {
  1045. return
  1046. <<<EOF
  1047. bRet = ($('#application_url').val() != '');
  1048. if (!bRet)
  1049. {
  1050. $("#v_application_url").html('<img src="../images/validation_error.png" title="This field cannot be empty"/>');
  1051. }
  1052. else
  1053. {
  1054. $("#v_application_url").html('');
  1055. }
  1056. bGraphviz = ($('#graphviz_path').val() != '');
  1057. if (!bGraphviz)
  1058. {
  1059. // Does not prevent to move forward
  1060. $("#v_graphviz_path").html('<img src="../images/validation_error.png" title="Impact analysis will not display properly"/>');
  1061. }
  1062. else
  1063. {
  1064. $("#v_graphviz_path").html('');
  1065. }
  1066. return bRet;
  1067. EOF
  1068. ;
  1069. }
  1070. }
  1071. /**
  1072. * Choice of the modules to be installed
  1073. */
  1074. class WizStepModulesChoice extends WizardStep
  1075. {
  1076. static protected $SEP = '_';
  1077. protected $bUpgrade = false;
  1078. /**
  1079. *
  1080. * @var iTopExtensionsMap
  1081. */
  1082. protected $oExtensionsMap;
  1083. /**
  1084. * Whether we were able to load the choices from the database or not
  1085. * @var bool
  1086. */
  1087. protected $bChoicesFromDatabase;
  1088. public function __construct(WizardController $oWizard, $sCurrentState)
  1089. {
  1090. parent::__construct($oWizard, $sCurrentState);
  1091. $this->bChoicesFromDatabase = false;
  1092. $this->oExtensionsMap = new iTopExtensionsMap();
  1093. $sPreviousSourceDir = $this->oWizard->GetParameter('previous_version_dir', '');
  1094. $sConfigPath = null;
  1095. if (($sPreviousSourceDir !== '') && is_readable($sPreviousSourceDir.'/conf/production/config-itop.php'))
  1096. {
  1097. $sConfigPath = $sPreviousSourceDir.'/conf/production/config-itop.php';
  1098. }
  1099. else if (is_readable(utils::GetConfigFilePath('production')))
  1100. {
  1101. $sConfigPath = utils::GetConfigFilePath('production');
  1102. }
  1103. if ($sConfigPath !== null)
  1104. {
  1105. $oConfig = new Config($sConfigPath);
  1106. $this->bChoicesFromDatabase = $this->oExtensionsMap->LoadChoicesFromDatabase($oConfig);
  1107. }
  1108. //echo '<div style="display:block;position:fixed;width:100px;height:20px;top:0;left:0;font-size:10pt;">Default: '.($this->bChoicesFromDatabase ? 'DB' : 'Guess').'</div>';
  1109. }
  1110. public function GetTitle()
  1111. {
  1112. $aStepInfo = $this->GetStepInfo();
  1113. $sTitle = isset($aStepInfo['title']) ? $aStepInfo['title'] : 'Modules selection';
  1114. return $sTitle;
  1115. }
  1116. public function GetPossibleSteps()
  1117. {
  1118. return array('WizStepModulesChoice', 'WizStepSummary');
  1119. }
  1120. public function ProcessParams($bMoveForward = true)
  1121. {
  1122. // Accumulates the selected modules:
  1123. $index = $this->GetStepIndex();
  1124. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  1125. $aSelectedChoices = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  1126. $aSelected = utils::ReadParam('choice', array());
  1127. $aSelectedChoices[$index] = $aSelected;
  1128. $this->oWizard->SetParameter('selected_components', json_encode($aSelectedChoices));
  1129. if ($this->GetStepInfo($index) == null)
  1130. {
  1131. throw new Exception('Internal error: invalid step "'.$index.'" for the choice of modules.');
  1132. }
  1133. else if ($bMoveForward)
  1134. {
  1135. if ($this->GetStepInfo(1 + $index) != null)
  1136. {
  1137. return array('class' => 'WizStepModulesChoice', 'state' => (1+$index));
  1138. }
  1139. else
  1140. {
  1141. // Exiting this step of the wizard, let's convert the selection into a list of modules
  1142. $aModules = array();
  1143. $aExtensions = array();
  1144. $sDisplayChoices = '<ul>';
  1145. for($i = 0; $i <= $index; $i++)
  1146. {
  1147. $aStepInfo = $this->GetStepInfo($i);
  1148. $sDisplayChoices .= $this->GetSelectedModules($aStepInfo, $aSelectedChoices[$i], $aModules, '', '', $aExtensions);
  1149. }
  1150. $sDisplayChoices .= '</ul>';
  1151. if (class_exists('CreateITILProfilesInstaller'))
  1152. {
  1153. $this->oWizard->SetParameter('old_addon', true);
  1154. }
  1155. $this->oWizard->SetParameter('selected_modules', json_encode(array_keys($aModules)));
  1156. $this->oWizard->SetParameter('selected_extensions', json_encode($aExtensions));
  1157. $this->oWizard->SetParameter('display_choices', $sDisplayChoices);
  1158. return array('class' => 'WizStepSummary', 'state' => '');
  1159. }
  1160. }
  1161. }
  1162. public function Display(WebPage $oPage)
  1163. {
  1164. $this->DisplayStep($oPage);
  1165. }
  1166. protected function DisplayStep($oPage)
  1167. {
  1168. // Sanity check (not stopper, to let developpers go further...)
  1169. try
  1170. {
  1171. SetupUtils::AnalyzeInstallation($this->oWizard, true);
  1172. }
  1173. catch(MissingDependencyException $e)
  1174. {
  1175. $oPage->warning($e->getMessage());
  1176. }
  1177. $this->bUpgrade = ($this->oWizard->GetParameter('install_mode') != 'install');
  1178. $aStepInfo = $this->GetStepInfo();
  1179. $oPage->add_style("div.choice { margin: 0.5em;}");
  1180. $oPage->add_style("div.choice a { text-decoration:none; font-weight: bold; color: #1C94C4 }");
  1181. $oPage->add_style("div.description { margin-left: 2em; }");
  1182. $oPage->add_style(".choice-disabled { color: #999; }");
  1183. $oPage->add('<table class="module-selection-banner"><tr>');
  1184. $sBannerPath = isset($aStepInfo['banner']) ? $aStepInfo['banner'] : '';
  1185. if (!empty($sBannerPath))
  1186. {
  1187. if (substr($sBannerPath, 0, 1) == '/')
  1188. {
  1189. // absolute path, means relative to APPROOT
  1190. $sBannerUrl = utils::GetDefaultUrlAppRoot().$sBannerPath;
  1191. }
  1192. else
  1193. {
  1194. // relative path: i.e. relative to the directory containing the XML file
  1195. $sFullPath = dirname($this->GetSourceFilePath()).'/'.$sBannerPath;
  1196. $sRealPath = realpath($sFullPath);
  1197. $sBannerUrl = utils::GetDefaultUrlAppRoot().str_replace(realpath(APPROOT), '', $sRealPath);
  1198. }
  1199. $oPage->add('<td><img src="'.$sBannerUrl.'"/><td>');
  1200. }
  1201. $sDescription = isset($aStepInfo['description']) ? $aStepInfo['description'] : '';
  1202. $oPage->add('<td>'.$sDescription.'<td>');
  1203. $oPage->add('</tr></table>');
  1204. // Build the default choices
  1205. $aDefaults = array();
  1206. $aModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1207. $aDefaults = $this->GetDefaults($aStepInfo, $aModules);
  1208. //echo "<pre>aStepInfo:\n ".print_r($aStepInfo, true)."</pre>";
  1209. //echo "<pre>aDefaults:\n ".print_r($aDefaults, true)."</pre>";
  1210. $index = $this->GetStepIndex();
  1211. // retrieve the saved selection
  1212. // use json_encode:decode to store a hash array: step_id => array(input_name => selected_input_id)
  1213. $aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  1214. if (!isset($aParameters[$index]))
  1215. {
  1216. $aParameters[$index] = $aDefaults;
  1217. }
  1218. $aSelectedComponents = $aParameters[$index];
  1219. $oPage->add('<div class="module-selection-body">');
  1220. $this->DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults);
  1221. $oPage->add('</div>');
  1222. $oPage->add_script(
  1223. <<<EOF
  1224. function CheckChoice(sChoiceId)
  1225. {
  1226. var oElement = $('#'+sChoiceId);
  1227. var bChecked = (oElement.attr('checked') == 'checked');
  1228. var sId = sChoiceId.replace('choice', '');
  1229. if ((oElement.attr('type') == 'radio') && bChecked)
  1230. {
  1231. // Only the radio that is clicked is notified, let's warn the other radio buttons
  1232. sName = oElement.attr('name');
  1233. $('input[name="'+sName+'"]').each(function() {
  1234. var sRadioId = $(this).attr('id');
  1235. if ((sRadioId != sChoiceId) && (sRadioId != undefined))
  1236. {
  1237. CheckChoice(sRadioId);
  1238. }
  1239. });
  1240. }
  1241. $('#sub_choices'+sId).each(function() {
  1242. if (!bChecked)
  1243. {
  1244. $(this).addClass('choice-disabled');
  1245. }
  1246. else
  1247. {
  1248. $(this).removeClass('choice-disabled');
  1249. }
  1250. $('input', this).each(function() {
  1251. if (bChecked)
  1252. {
  1253. if ($(this).attr('data-disabled') != 'disabled')
  1254. {
  1255. // Only non-mandatory fields can be enabled
  1256. $(this).removeAttr('disabled');
  1257. }
  1258. }
  1259. else
  1260. {
  1261. $(this).attr('disabled', 'disabled');
  1262. }
  1263. });
  1264. });
  1265. }
  1266. EOF
  1267. );
  1268. $oPage->add_ready_script(
  1269. <<<EOF
  1270. $('.wiz-choice').bind('change', function() { CheckChoice($(this).attr('id')); } );
  1271. $('.wiz-choice').trigger('change');
  1272. EOF
  1273. );
  1274. }
  1275. protected function GetDefaults($aInfo, $aModules, $sParentId = '')
  1276. {
  1277. $aDefaults = array();
  1278. if (!$this->bChoicesFromDatabase)
  1279. {
  1280. $this->GuessDefaultsFromModules($aInfo, $aDefaults, $aModules, $sParentId);
  1281. }
  1282. else
  1283. {
  1284. $this->GetDefaultsFromDatabase($aInfo, $aDefaults, $sParentId);
  1285. }
  1286. return $aDefaults;
  1287. }
  1288. protected function GetDefaultsFromDatabase($aInfo, &$aDefaults, $sParentId)
  1289. {
  1290. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  1291. foreach($aOptions as $index => $aChoice)
  1292. {
  1293. $sChoiceId = $sParentId.self::$SEP.$index;
  1294. if ($this->bUpgrade)
  1295. {
  1296. if ($this->oExtensionsMap->IsMarkedAsChosen($aChoice['extension_code']))
  1297. {
  1298. $aDefaults[$sChoiceId] = $sChoiceId;
  1299. }
  1300. }
  1301. else if (isset($aChoice['default']) && $aChoice['default'])
  1302. {
  1303. $aDefaults[$sChoiceId] = $sChoiceId;
  1304. }
  1305. // Recurse for sub_options (if any)
  1306. if (isset($aChoice['sub_options']))
  1307. {
  1308. $this->GetDefaultsFromDatabase($aChoice['sub_options'], $aDefaults, $sChoiceId);
  1309. }
  1310. }
  1311. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  1312. $sChoiceName = null;
  1313. foreach($aAlternatives as $index => $aChoice)
  1314. {
  1315. $sChoiceId = $sParentId.self::$SEP.$index;
  1316. if ($sChoiceName == null)
  1317. {
  1318. $sChoiceName = $sChoiceId; // All radios share the same name
  1319. }
  1320. if ($this->bUpgrade)
  1321. {
  1322. if ($this->oExtensionsMap->IsMarkedAsChosen($aChoice['extension_code']))
  1323. {
  1324. $aDefaults[$sChoiceName] = $sChoiceId;
  1325. }
  1326. }
  1327. else if (isset($aChoice['default']) && $aChoice['default'])
  1328. {
  1329. $aDefaults[$sChoiceName] = $sChoiceId;
  1330. }
  1331. // Recurse for sub_options (if any)
  1332. if (isset($aChoice['sub_options']))
  1333. {
  1334. $this->GetDefaultsFromDatabase($aChoice['sub_options'], $aDefaults, $sChoiceId);
  1335. }
  1336. }
  1337. }
  1338. /**
  1339. * Try to guess the user choices based on the current list of installed modules...
  1340. * @param array $aInfo
  1341. * @param array $aDefaults
  1342. * @param array $aModules
  1343. * @param string $sParentId
  1344. * @return array
  1345. */
  1346. protected function GuessDefaultsFromModules($aInfo, &$aDefaults, $aModules, $sParentId = '')
  1347. {
  1348. $aRetScore = array();
  1349. $aScores = array();
  1350. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  1351. foreach($aOptions as $index => $aChoice)
  1352. {
  1353. $sChoiceId = $sParentId.self::$SEP.$index;
  1354. $aScores[$sChoiceId] = array();
  1355. if (!$this->bUpgrade && isset($aChoice['default']) && $aChoice['default'])
  1356. {
  1357. $aDefaults[$sChoiceId] = $sChoiceId;
  1358. }
  1359. if ($this->bUpgrade)
  1360. {
  1361. // In upgrade mode, the defaults are the installed modules
  1362. foreach($aChoice['modules'] as $sModuleId)
  1363. {
  1364. if ($aModules[$sModuleId]['version_db'] != '')
  1365. {
  1366. // A module corresponding to this choice is installed
  1367. $aScores[$sChoiceId][$sModuleId] = true;
  1368. }
  1369. }
  1370. if (count($aScores[$sChoiceId]) == count($aChoice['modules']))
  1371. {
  1372. // All the modules are installed, this choice is selected
  1373. $aDefaults[$sChoiceId] = $sChoiceId;
  1374. }
  1375. $aRetScore = array_merge($aRetScore, $aScores[$sChoiceId]);
  1376. }
  1377. if (isset($aChoice['sub_options']))
  1378. {
  1379. $aScores[$sChoiceId] = array_merge($aScores[$sChoiceId], $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $sChoiceId));
  1380. }
  1381. $index++;
  1382. }
  1383. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  1384. $sChoiceName = null;
  1385. $sChoiceIdNone = null;
  1386. foreach($aAlternatives as $index => $aChoice)
  1387. {
  1388. $sChoiceId = $sParentId.self::$SEP.$index;
  1389. $aScores[$sChoiceId] = array();
  1390. if ($sChoiceName == null)
  1391. {
  1392. $sChoiceName = $sChoiceId;
  1393. }
  1394. if (!$this->bUpgrade && isset($aChoice['default']) && $aChoice['default'])
  1395. {
  1396. $aDefaults[$sChoiceName] = $sChoiceId;
  1397. }
  1398. if (isset($aChoice['sub_options']))
  1399. {
  1400. // By default (i.e. install-mode), sub options can only be checked if the parent option is checked by default
  1401. if ($this->bUpgrade || (isset($aChoice['default']) && $aChoice['default']))
  1402. {
  1403. $aScores[$sChoiceId] = $this->GuessDefaultsFromModules($aChoice['sub_options'], $aDefaults, $aModules, $sChoiceId);
  1404. }
  1405. }
  1406. $index++;
  1407. }
  1408. $iMaxScore = 0;
  1409. if ($this->bUpgrade && (count($aAlternatives) > 0))
  1410. {
  1411. // The installed choices have precedence over the 'default' choices
  1412. // In case several choices share the same base modules, let's weight the alternative choices
  1413. // based on their number of installed modules
  1414. $sChoiceName = null;
  1415. foreach($aAlternatives as $index => $aChoice)
  1416. {
  1417. $sChoiceId = $sParentId.self::$SEP.$index;
  1418. if ($sChoiceName == null)
  1419. {
  1420. $sChoiceName = $sChoiceId;
  1421. }
  1422. if (array_key_exists('modules', $aChoice))
  1423. {
  1424. foreach($aChoice['modules'] as $sModuleId)
  1425. {
  1426. if ($aModules[$sModuleId]['version_db'] != '')
  1427. {
  1428. // A module corresponding to this choice is installed, increase the score of this choice
  1429. if (!isset($aScores[$sChoiceId])) $aScores[$sChoiceId] = array();
  1430. $aScores[$sChoiceId][$sModuleId] = true;
  1431. $iMaxScore = max($iMaxScore, count($aScores[$sChoiceId]));
  1432. }
  1433. }
  1434. //if (count($aScores[$sChoiceId]) == count($aChoice['modules']))
  1435. //{
  1436. // $iScore += 100; // Bonus for the parent when a choice is complete
  1437. //}
  1438. $aRetScore = array_merge($aRetScore, $aScores[$sChoiceId]);
  1439. }
  1440. $iMaxScore = max($iMaxScore, isset($aScores[$sChoiceId]) ? count($aScores[$sChoiceId]) : 0);
  1441. }
  1442. }
  1443. if ($iMaxScore > 0)
  1444. {
  1445. $aNumericScores = array();
  1446. foreach($aScores as $sChoiceId => $aModules)
  1447. {
  1448. $aNumericScores[$sChoiceId] = count($aModules);
  1449. }
  1450. // The choice with the bigger score wins !
  1451. asort($aNumericScores, SORT_NUMERIC);
  1452. $aKeys = array_keys($aNumericScores);
  1453. $sBetterChoiceId = array_pop($aKeys);
  1454. $aDefaults[$sChoiceName] = $sBetterChoiceId;
  1455. }
  1456. // echo "Scores: <pre>".print_r($aScores, true)."</pre><br/>";
  1457. // echo "Defaults: <pre>".print_r($aDefaults, true)."</pre><br/>";
  1458. return $aRetScore;
  1459. }
  1460. /**
  1461. * Converts the list of selected "choices" into a list of "modules": take into account the selected and the mandatory modules
  1462. * @param hash $aInfo Info about the "choice" array('options' => array(...), 'alternatives' => array(...))
  1463. * @param hash $aSelectedChoices List of selected choices array('name' => 'selected_value_id')
  1464. * @param hash $aModules Return parameter: List of selected modules array('module_id' => true)
  1465. * @param string $sParentId Used for recursion
  1466. * @return string A text representation of what will be installed
  1467. */
  1468. protected function GetSelectedModules($aInfo, $aSelectedChoices, &$aModules, $sParentId = '', $sDisplayChoices = '', &$aSelectedExtensions = null)
  1469. {
  1470. if ($sParentId == '')
  1471. {
  1472. // Check once (before recursing) that the hidden modules are selected
  1473. foreach(SetupUtils::AnalyzeInstallation($this->oWizard) as $sModuleId => $aModule)
  1474. {
  1475. if (($sModuleId != ROOT_MODULE) && !isset($aModules[$sModuleId]))
  1476. {
  1477. if (($aModule['category'] == 'authentication') || (!$aModule['visible'] && !isset($aModule['auto_select'])))
  1478. {
  1479. $aModules[$sModuleId] = true;
  1480. $sDisplayChoices .= '<li><i>'.$aModule['label'].' (hidden)</i></li>';
  1481. }
  1482. }
  1483. }
  1484. }
  1485. $aOptions = isset($aInfo['options']) ? $aInfo['options'] : array();
  1486. foreach($aOptions as $index => $aChoice)
  1487. {
  1488. $sChoiceId = $sParentId.self::$SEP.$index;
  1489. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  1490. (isset($aSelectedChoices[$sChoiceId]) && ($aSelectedChoices[$sChoiceId] == $sChoiceId)) )
  1491. {
  1492. $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
  1493. if (isset($aChoice['modules']))
  1494. {
  1495. foreach($aChoice['modules'] as $sModuleId)
  1496. {
  1497. $aModules[$sModuleId] = true; // store the Id of the selected module
  1498. }
  1499. }
  1500. $sChoiceType = isset($aChoice['type']) ? $aChoice['type'] : 'wizard_option';
  1501. if ($aSelectedExtensions !== null)
  1502. {
  1503. $aSelectedExtensions[] = $aChoice['extension_code'];
  1504. }
  1505. // Recurse only for selected choices
  1506. if (isset($aChoice['sub_options']))
  1507. {
  1508. $sDisplayChoices .= '<ul>';
  1509. $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices, $aSelectedExtensions);
  1510. $sDisplayChoices .= '</ul>';
  1511. }
  1512. $sDisplayChoices .= '</li>';
  1513. }
  1514. $index++;
  1515. }
  1516. $aAlternatives = isset($aInfo['alternatives']) ? $aInfo['alternatives'] : array();
  1517. $sChoiceName = null;
  1518. foreach($aAlternatives as $index => $aChoice)
  1519. {
  1520. $sChoiceId = $sParentId.self::$SEP.$index;
  1521. if ($sChoiceName == null)
  1522. {
  1523. $sChoiceName = $sChoiceId;
  1524. }
  1525. if ( (isset($aChoice['mandatory']) && $aChoice['mandatory']) ||
  1526. (isset($aSelectedChoices[$sChoiceName]) && ($aSelectedChoices[$sChoiceName] == $sChoiceId)) )
  1527. {
  1528. $sDisplayChoices .= '<li>'.$aChoice['title'].'</li>';
  1529. if ($aSelectedExtensions !== null)
  1530. {
  1531. $aSelectedExtensions[] = $aChoice['extension_code'];
  1532. }
  1533. if (isset($aChoice['modules']))
  1534. {
  1535. foreach($aChoice['modules'] as $sModuleId)
  1536. {
  1537. $aModules[$sModuleId] = true; // store the Id of the selected module
  1538. }
  1539. }
  1540. // Recurse only for selected choices
  1541. if (isset($aChoice['sub_options']))
  1542. {
  1543. $sDisplayChoices .= '<ul>';
  1544. $sDisplayChoices = $this->GetSelectedModules($aChoice['sub_options'], $aSelectedChoices, $aModules, $sChoiceId, $sDisplayChoices, $aSelectedExtensions);
  1545. $sDisplayChoices .= '</ul>';
  1546. }
  1547. $sDisplayChoices .= '</li>';
  1548. }
  1549. $index++;
  1550. }
  1551. if ($sParentId == '')
  1552. {
  1553. // Last pass (after all the user's choices are turned into "selected" modules):
  1554. // Process 'auto_select' modules for modules that are not already selected
  1555. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  1556. do
  1557. {
  1558. // Loop while new modules are added...
  1559. $bModuleAdded = false;
  1560. foreach($aAvailableModules as $sModuleId => $aModule)
  1561. {
  1562. if (($sModuleId != ROOT_MODULE) && !array_key_exists($sModuleId, $aModules) && isset($aModule['auto_select']))
  1563. {
  1564. try
  1565. {
  1566. $bSelected = false;
  1567. SetupInfo::SetSelectedModules($aModules);
  1568. eval('$bSelected = ('.$aModule['auto_select'].');');
  1569. }
  1570. catch(Exception $e)
  1571. {
  1572. $sDisplayChoices .= '<li><b>Warning: auto_select failed with exception ('.$e->getMessage().') for module "'.$sModuleId.'"</b></li>';
  1573. $bSelected = false;
  1574. }
  1575. if ($bSelected)
  1576. {
  1577. $aModules[$sModuleId] = true; // store the Id of the selected module
  1578. $sDisplayChoices .= '<li><b>'.$aModule['label'].' (auto_select)</b></li>';
  1579. $bModuleAdded = true;
  1580. }
  1581. }
  1582. }
  1583. }
  1584. while($bModuleAdded);
  1585. }
  1586. return $sDisplayChoices;
  1587. }
  1588. protected function GetStepIndex()
  1589. {
  1590. switch($this->sCurrentState)
  1591. {
  1592. case 'start_install':
  1593. case 'start_upgrade':
  1594. $index = 0;
  1595. break;
  1596. default:
  1597. $index = (integer)$this->sCurrentState;
  1598. }
  1599. return $index;
  1600. }
  1601. protected function GetStepInfo($idx = null)
  1602. {
  1603. $aStepInfo = null;
  1604. if ($idx === null)
  1605. {
  1606. $index = $this->GetStepIndex();
  1607. }
  1608. else
  1609. {
  1610. $index = $idx;
  1611. }
  1612. $aSteps = array();
  1613. $this->oWizard->SetParameter('additional_extensions_modules', json_encode(array())); // Default value, no additional extensions
  1614. if (@file_exists($this->GetSourceFilePath()))
  1615. {
  1616. // Found an "installation.xml" file, let's us tis definition for the wizard
  1617. $aParams = new XMLParameters($this->GetSourceFilePath());
  1618. $aSteps = $aParams->Get('steps', array());
  1619. // Additional step for the "extensions"
  1620. $aStepDefinition = array(
  1621. 'title' => 'Extensions',
  1622. '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>',
  1623. 'banner' => '/images/extension.png',
  1624. 'options' => array()
  1625. );
  1626. foreach($this->oExtensionsMap->GetAllExtensions() as $oExtension)
  1627. {
  1628. if ($oExtension->sSource !== iTopExtension::SOURCE_WIZARD)
  1629. {
  1630. $aStepDefinition['options'][] = array(
  1631. 'extension_code' => $oExtension->sCode,
  1632. 'title' => $oExtension->sLabel,
  1633. 'description' => $oExtension->sDescription,
  1634. 'more_info' => $oExtension->sMoreInfoUrl,
  1635. 'default' => true, // by default offer to install all modules
  1636. 'modules' => $oExtension->aModules,
  1637. 'mandatory' => $oExtension->bMandatory || ($oExtension->sSource === iTopExtension::SOURCE_REMOTE),
  1638. 'source_label' => $this->GetExtensionSourceLabel($oExtension->sSource),
  1639. );
  1640. }
  1641. }
  1642. // Display this step of the wizard only if there is something to display
  1643. if (count($aStepDefinition['options']) !== 0)
  1644. {
  1645. $aSteps[] = $aStepDefinition;
  1646. $this->oWizard->SetParameter('additional_extensions_modules', json_encode($aStepDefinition['options']));
  1647. }
  1648. }
  1649. else
  1650. {
  1651. // No wizard configuration provided, build a standard one with just one big list
  1652. $aStepDefinition = array(
  1653. 'title' => 'Modules Selection',
  1654. '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>',
  1655. 'banner' => '/images/modules.png',
  1656. 'options' => array()
  1657. );
  1658. foreach($this->oExtensionsMap->GetAllExtensions() as $oExtension)
  1659. {
  1660. if ($oExtension->sSource)
  1661. {
  1662. $aStepDefinition['options'][] = array(
  1663. 'extension_code' => $oExtension->sCode,
  1664. 'title' => $oExtension->sLabel,
  1665. 'description' => $oExtension->sDescription,
  1666. 'more_info' => $oExtension->sMoreInfoUrl,
  1667. 'default' => true, // by default offer to install all modules
  1668. 'modules' => $oExtension->aModules,
  1669. 'mandatory' => $oExtension->bMandatory || ($oExtension->sSource !== iTopExtension::SOURCE_REMOTE),
  1670. 'source_label' => $this->GetExtensionSourceLabel($oExtension->sSource),
  1671. );
  1672. }
  1673. }
  1674. $aSteps[] = $aStepDefinition;
  1675. }
  1676. if (array_key_exists($index, $aSteps))
  1677. {
  1678. $aStepInfo = $aSteps[$index];
  1679. }
  1680. return $aStepInfo;
  1681. }
  1682. protected function GetExtensionSourceLabel($sSource)
  1683. {
  1684. switch($sSource)
  1685. {
  1686. case iTopExtension::SOURCE_MANUAL:
  1687. $sResult = 'Extension';
  1688. break;
  1689. case iTopExtension::SOURCE_REMOTE:
  1690. $sResult = (ITOP_APPLICATION == 'iTop') ? 'iTop-Hub' : 'ITSM-Designer';
  1691. break;
  1692. default:
  1693. $sResult = '';
  1694. }
  1695. if ($sResult == '')
  1696. {
  1697. return '';
  1698. }
  1699. 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>';
  1700. }
  1701. protected function DisplayOptions($oPage, $aStepInfo, $aSelectedComponents, $aDefaults, $sParentId = '', $bAllDisabled = false)
  1702. {
  1703. $aOptions = isset($aStepInfo['options']) ? $aStepInfo['options'] : array();
  1704. $aAlternatives = isset($aStepInfo['alternatives']) ? $aStepInfo['alternatives'] : array();
  1705. $index = 0;
  1706. $sAllDisabled = '';
  1707. if ($bAllDisabled)
  1708. {
  1709. $sAllDisabled = 'disabled data-disabled="disabled" ';
  1710. }
  1711. foreach($aOptions as $index => $aChoice)
  1712. {
  1713. $sAttributes = '';
  1714. $sChoiceId = $sParentId.self::$SEP.$index;
  1715. $sDataId = 'data-id="'.htmlentities($aChoice['extension_code'], ENT_QUOTES, 'UTF-8').'"';
  1716. $sId = htmlentities($aChoice['extension_code'], ENT_QUOTES, 'UTF-8');
  1717. $bIsDefault = array_key_exists($sChoiceId, $aDefaults);
  1718. $bSelected = isset($aSelectedComponents[$sChoiceId]) && ($aSelectedComponents[$sChoiceId] == $sChoiceId);
  1719. $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
  1720. $bDisabled = false;
  1721. if ($bMandatory)
  1722. {
  1723. $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;');
  1724. $bDisabled = true;
  1725. }
  1726. else if ($bSelected)
  1727. {
  1728. $oPage->add('<div class="choice" '.$sDataId.'><input class="wiz-choice" '.$sAllDisabled.'id="'.$sId.'" name="choice['.$sChoiceId.']" type="checkbox" checked value="'.$sChoiceId.'"/>&nbsp;');
  1729. }
  1730. else
  1731. {
  1732. $oPage->add('<div class="choice" '.$sDataId.'><input class="wiz-choice" '.$sAllDisabled.'id="'.$sId.'" name="choice['.$sChoiceId.']" type="checkbox" value="'.$sChoiceId.'"/>&nbsp;');
  1733. }
  1734. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled);
  1735. $oPage->add('</div>');
  1736. $index++;
  1737. }
  1738. $sChoiceName = null;
  1739. $sDisabled = '';
  1740. $bDisabled = false;
  1741. $sChoiceIdNone = null;
  1742. foreach($aAlternatives as $index => $aChoice)
  1743. {
  1744. $sChoiceId = $sParentId.self::$SEP.$index;
  1745. if ($sChoiceName == null)
  1746. {
  1747. $sChoiceName = $sChoiceId; // All radios share the same name
  1748. }
  1749. $bIsDefault = array_key_exists($sChoiceName, $aDefaults) && ($aDefaults[$sChoiceName] == $sChoiceId);
  1750. $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
  1751. if ($bMandatory || $bAllDisabled)
  1752. {
  1753. // One choice is mandatory, all alternatives are disabled
  1754. $sDisabled = ' disabled data-disabled="disabled"';
  1755. $bDisabled = true;
  1756. }
  1757. if ( (!isset($aChoice['sub_options']) || (count($aChoice['sub_options']) == 0)) && (!isset($aChoice['modules']) || (count($aChoice['modules']) == 0)) )
  1758. {
  1759. $sChoiceIdNone = $sChoiceId; // the "None" / empty choice
  1760. }
  1761. }
  1762. if (!array_key_exists($sChoiceName, $aDefaults) || ($aDefaults[$sChoiceName] == $sChoiceIdNone))
  1763. {
  1764. // The "none" choice does not disable the selection !!
  1765. $sDisabled = '';
  1766. $bDisabled = false;
  1767. }
  1768. foreach($aAlternatives as $index => $aChoice)
  1769. {
  1770. $sAttributes = '';
  1771. $sChoiceId = $sParentId.self::$SEP.$index;
  1772. $sDataId = 'data-id="'.htmlentities($aChoice['extension_code'], ENT_QUOTES, 'UTF-8').'"';
  1773. $sId = htmlentities($aChoice['extension_code'], ENT_QUOTES, 'UTF-8');
  1774. if ($sChoiceName == null)
  1775. {
  1776. $sChoiceName = $sChoiceId; // All radios share the same name
  1777. }
  1778. $bIsDefault = array_key_exists($sChoiceName, $aDefaults) && ($aDefaults[$sChoiceName] == $sChoiceId);
  1779. $bSelected = isset($aSelectedComponents[$sChoiceName]) && ($aSelectedComponents[$sChoiceName] == $sChoiceId);
  1780. if ( !isset($aSelectedComponents[$sChoiceName]) && ($sChoiceIdNone != null))
  1781. {
  1782. // No choice selected, select the "None" option
  1783. $bSelected = ($sChoiceId == $sChoiceIdNone);
  1784. }
  1785. $bMandatory = (isset($aChoice['mandatory']) && $aChoice['mandatory']) || ($this->bUpgrade && $bIsDefault);
  1786. if ($bSelected)
  1787. {
  1788. $sAttributes = ' checked ';
  1789. }
  1790. $sHidden = '';
  1791. if ($bMandatory)
  1792. {
  1793. $sAttributes = ' checked ';
  1794. $sHidden = '<input type="hidden" name="choice['.$sChoiceName.']" value="'.$sChoiceId.'"/>';
  1795. }
  1796. $oPage->add('<div class="choice" '.$sDataId.'><input class="wiz-choice" id="'.$sId.'" name="choice['.$sChoiceName.']" type="radio"'.$sAttributes.' value="'.$sChoiceId.'"'.$sDisabled.'/>'.$sHidden.'&nbsp;');
  1797. $this->DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled);
  1798. $oPage->add('</div>');
  1799. $index++;
  1800. }
  1801. }
  1802. protected function DisplayChoice($oPage, $aChoice, $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled = false)
  1803. {
  1804. $sMoreInfo = (isset($aChoice['more_info']) && ($aChoice['more_info'] != '')) ? '<a target="_blank" href="'.$aChoice['more_info'].'">More information</a>' : '';
  1805. $sSourceLabel = isset($aChoice['source_label']) ? $aChoice['source_label'] : '';
  1806. $sId = htmlentities($aChoice['extension_code'], ENT_QUOTES, 'UTF-8');
  1807. $oPage->add('<label for="'.$sId.'"><b>'.htmlentities($aChoice['title'], ENT_QUOTES, 'UTF-8').'</b>'.$sSourceLabel.'</label> '.$sMoreInfo);
  1808. $sDescription = isset($aChoice['description']) ? htmlentities($aChoice['description'], ENT_QUOTES, 'UTF-8') : '';
  1809. $oPage->add('<div class="description">'.$sDescription.'<span id="sub_choices'.$sChoiceId.'">');
  1810. if (isset($aChoice['sub_options']))
  1811. {
  1812. $this->DisplayOptions($oPage, $aChoice['sub_options'], $aSelectedComponents, $aDefaults, $sChoiceId, $bDisabled);
  1813. }
  1814. $oPage->add('</span></div>');
  1815. }
  1816. protected function GetSourceFilePath()
  1817. {
  1818. $sSourceDir = $this->oWizard->GetParameter('source_dir');
  1819. return $sSourceDir.'/installation.xml';
  1820. }
  1821. }
  1822. /**
  1823. * Summary of the installation tasks
  1824. */
  1825. class WizStepSummary extends WizardStep
  1826. {
  1827. protected $bDependencyCheck = null;
  1828. protected $sDependencyIssue = null;
  1829. protected function CheckDependencies()
  1830. {
  1831. if (is_null($this->bDependencyCheck))
  1832. {
  1833. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  1834. $this->bDependencyCheck = true;
  1835. try
  1836. {
  1837. SetupUtils::AnalyzeInstallation($this->oWizard, true, $aSelectedModules);
  1838. }
  1839. catch(MissingDependencyException $e)
  1840. {
  1841. $this->bDependencyCheck = false;
  1842. $this->sDependencyIssue = $e->getMessage();
  1843. }
  1844. }
  1845. return $this->bDependencyCheck;
  1846. }
  1847. public function GetTitle()
  1848. {
  1849. $sMode = $this->oWizard->GetParameter('mode', 'install');
  1850. if ($sMode == 'install')
  1851. {
  1852. return 'Ready to install';
  1853. }
  1854. else
  1855. {
  1856. return 'Ready to upgrade';
  1857. }
  1858. }
  1859. public function GetPossibleSteps()
  1860. {
  1861. return array('WizStepDone');
  1862. }
  1863. /**
  1864. * Returns the label for the " Next >> " button
  1865. * @return string The label for the button
  1866. */
  1867. public function GetNextButtonLabel()
  1868. {
  1869. return ' Install ! ';
  1870. }
  1871. public function CanMoveForward()
  1872. {
  1873. if ($this->CheckDependencies())
  1874. {
  1875. return true;
  1876. }
  1877. else
  1878. {
  1879. return false;
  1880. }
  1881. }
  1882. public function ProcessParams($bMoveForward = true)
  1883. {
  1884. return array('class' => 'WizStepDone', 'state' => '');
  1885. }
  1886. public function Display(WebPage $oPage)
  1887. {
  1888. $oPage->add_style(
  1889. <<<EOF
  1890. #params_summary {
  1891. height: 200px;
  1892. overflow: auto;
  1893. }
  1894. #params_summary div {
  1895. width:100%;
  1896. margin-top:0;
  1897. padding-top: 0.5em;
  1898. padding-left: 0;
  1899. }
  1900. #params_summary div ul {
  1901. margin-left:0;
  1902. padding-left: 20px;
  1903. }
  1904. #params_summary div.closed ul {
  1905. display:none;
  1906. }
  1907. #params_summary div li {
  1908. list-style: none;
  1909. width: 100%;
  1910. margin-left:0;
  1911. padding-left: 0em;
  1912. }
  1913. .title {
  1914. padding-left: 20px;
  1915. font-weight: bold;
  1916. cursor: pointer;
  1917. background: url(../images/minus.gif) 2px 2px no-repeat;
  1918. }
  1919. #params_summary div.closed .title {
  1920. background: url(../images/plus.gif) 2px 2px no-repeat;
  1921. }
  1922. #progress_content {
  1923. height: 200px;
  1924. overflow: auto;
  1925. text-align: center;
  1926. }
  1927. #installation_progress {
  1928. display: none;
  1929. }
  1930. EOF
  1931. );
  1932. $aInstallParams = $this->BuildConfig();
  1933. $sMode = $aInstallParams['mode'];
  1934. $sDestination = ITOP_APPLICATION.(($sMode == 'install') ? ' version '.ITOP_VERSION.' is about to be installed ' : ' is about to be upgraded ');
  1935. $sDBDescription = ' <b>existing</b> database <b>'.$aInstallParams['database']['name'].'</b>';
  1936. if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes'))
  1937. {
  1938. $sDBDescription = ' <b>new</b> database <b>'.$aInstallParams['database']['name'].'</b>';
  1939. }
  1940. $sDestination .= 'into the '.$sDBDescription.' on the server <b>'.$aInstallParams['database']['server'].'</b>.';
  1941. $oPage->add('<h2>'.$sDestination.'</h2>');
  1942. $oPage->add('<fieldset id="summary"><legend>Installation Parameters</legend>');
  1943. $oPage->add('<div id="params_summary">');
  1944. $oPage->add('<div class="closed"><span class="title">Database Parameters</span><ul>');
  1945. $oPage->add('<li>Server Name: '.$aInstallParams['database']['server'].'</li>');
  1946. $oPage->add('<li>DB User Name: '.$aInstallParams['database']['user'].'</li>');
  1947. $oPage->add('<li>DB user password: '.$aInstallParams['database']['pwd'].'</li>');
  1948. if (($sMode == 'install') && ($this->oWizard->GetParameter('create_db') == 'yes'))
  1949. {
  1950. $oPage->add('<li>Database Name: '.$aInstallParams['database']['name'].' (will be created)</li>');
  1951. }
  1952. else
  1953. {
  1954. $oPage->add('<li>Database Name: '.$aInstallParams['database']['name'].'</li>');
  1955. }
  1956. if ($aInstallParams['database']['prefix'] != '')
  1957. {
  1958. $oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: '.$aInstallParams['database']['prefix'].'</li>');
  1959. }
  1960. else
  1961. {
  1962. $oPage->add('<li>Prefix for the '.ITOP_APPLICATION.' tables: none</li>');
  1963. }
  1964. $oPage->add('</ul></div>');
  1965. $oPage->add('<div><span class="title">Data Model Configuration</span>');
  1966. $oPage->add($this->oWizard->GetParameter('display_choices'));
  1967. $oPage->add('</div>');
  1968. $oPage->add('<div class="closed"><span class="title">Other Parameters</span><ul>');
  1969. if ($sMode == 'install')
  1970. {
  1971. $oPage->add('<li>Default language: '.$aInstallParams['language'].'</li>');
  1972. }
  1973. $oPage->add('<li>URL to access the application: '.$aInstallParams['url'].'</li>');
  1974. $oPage->add('<li>Graphviz\' dot path: '.$aInstallParams['graphviz_path'].'</li>');
  1975. if ($aInstallParams['sample_data'] == 'yes')
  1976. {
  1977. $oPage->add('<li>Sample data will be loaded into the database.</li>');
  1978. }
  1979. if ($aInstallParams['old_addon'])
  1980. {
  1981. $oPage->add('<li>Compatibility mode: Using the version 1.2 of the UserRightsProfiles add-on.</li>');
  1982. }
  1983. $oPage->add('</ul></div>');
  1984. if ($sMode == 'install')
  1985. {
  1986. $oPage->add('<div class="closed"><span class="title">Admininistrator Account</span><ul>');
  1987. $oPage->add('<li>Login: '.$aInstallParams['admin_account']['user'].'</li>');
  1988. $oPage->add('<li>Password: '.$aInstallParams['admin_account']['pwd'].'</li>');
  1989. $oPage->add('<li>Language: '.$aInstallParams['admin_account']['language'].'</li>');
  1990. $oPage->add('</ul></div>');
  1991. }
  1992. $aMiscOptions = $aInstallParams['options'];
  1993. if (count($aMiscOptions) > 0)
  1994. {
  1995. $oPage->add('<div class="closed"><span class="title">Miscellaneous Options</span><ul>');
  1996. foreach($aMiscOptions as $sKey => $sValue)
  1997. {
  1998. $oPage->add('<li>'.$sKey.': '.$sValue.'</li>');
  1999. }
  2000. $oPage->add('</ul></div>');
  2001. }
  2002. $aSelectedModules = $aInstallParams['selected_modules'];
  2003. if (isset($aMiscOptions['generate_config']))
  2004. {
  2005. $oDoc = new DOMDocument('1.0', 'UTF-8');
  2006. $oDoc->preserveWhiteSpace = false;
  2007. $oDoc->formatOutput = true;
  2008. $oParams = new PHPParameters();
  2009. $oParams->LoadFromHash($aInstallParams);
  2010. $oParams->ToXML($oDoc, null, 'installation');
  2011. $sXML = $oDoc->saveXML();
  2012. $oPage->add('<div class="closed"><span class="title">XML Config file</span><ul><pre>');
  2013. $oPage->add(htmlentities($sXML, ENT_QUOTES, 'UTF-8'));
  2014. $oPage->add('</pre></ul></div>');
  2015. }
  2016. $oPage->add('</div>'); // params_summary
  2017. $oPage->add('</fieldset>');
  2018. $oPage->add('<fieldset id="installation_progress"><legend>Progress of the installation</legend>');
  2019. $oPage->add('<div id="progress_content">');
  2020. $oPage->add_linked_script('../setup/jquery.progression.js');
  2021. $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>');
  2022. $oPage->add('</div>'); // progress_content
  2023. $oPage->add('</fieldset>');
  2024. $sJSONData = json_encode($aInstallParams);
  2025. $oPage->add('<input type="hidden" id="installer_parameters" value="'.htmlentities($sJSONData, ENT_QUOTES, 'UTF-8').'"/>');
  2026. if (!$this->CheckDependencies())
  2027. {
  2028. $oPage->error($this->sDependencyIssue);
  2029. }
  2030. $oPage->add_ready_script(
  2031. <<<EOF
  2032. $("#params_summary div").addClass('closed');
  2033. $("#params_summary .title").click(function() { $(this).parent().toggleClass('closed'); } );
  2034. $("#btn_next").bind("click.install", function(event) {
  2035. $('#summary').hide();
  2036. $('#installation_progress').show();
  2037. $(this).attr("disabled", "disabled"); event.preventDefault(); ExecuteStep("");
  2038. });
  2039. $("#wiz_form").data("installation_status", "not started")
  2040. EOF
  2041. );
  2042. }
  2043. /**
  2044. * Prepare the parameters to execute the installation asynchronously
  2045. * @return Hash A big hash array that can be converted to XML or JSON with all the needed parameters
  2046. */
  2047. protected function BuildConfig()
  2048. {
  2049. $sMode = $this->oWizard->GetParameter('install_mode', 'install');
  2050. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  2051. $aSelectedExtensions = json_decode($this->oWizard->GetParameter('selected_extensions'), true);
  2052. $sBackupDestination = '';
  2053. $sPreviousConfigurationFile = '';
  2054. $sDBName = $this->oWizard->GetParameter('db_name');
  2055. if ($sMode == 'upgrade')
  2056. {
  2057. $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir', '');
  2058. if (!empty($sPreviousVersionDir))
  2059. {
  2060. $aPreviousInstance = SetupUtils::GetPreviousInstance($sPreviousVersionDir);
  2061. if ($aPreviousInstance['found'])
  2062. {
  2063. $sPreviousConfigurationFile = $aPreviousInstance['configuration_file'];
  2064. }
  2065. }
  2066. if ($this->oWizard->GetParameter('db_backup', false))
  2067. {
  2068. $sBackupDestination = $this->oWizard->GetParameter('db_backup_path', '');
  2069. }
  2070. }
  2071. else
  2072. {
  2073. $sDBNewName = $this->oWizard->GetParameter('db_new_name', '');
  2074. if ($sDBNewName != '')
  2075. {
  2076. $sDBName = $sDBNewName; // Database will be created
  2077. }
  2078. }
  2079. $sSourceDir = $this->oWizard->GetParameter('source_dir');
  2080. $aCopies = array();
  2081. if (($sMode == 'upgrade') && ($this->oWizard->GetParameter('upgrade_type') == 'keep-previous'))
  2082. {
  2083. $sPreviousVersionDir = $this->oWizard->GetParameter('previous_version_dir');
  2084. $aCopies[] = array('source' => $sSourceDir, 'destination' => 'modules'); // Source is an absolute path, destination is relative to APPROOT
  2085. $aCopies[] = array('source' => $sPreviousVersionDir.'/portal', 'destination' => 'portal'); // Source is an absolute path, destination is relative to APPROOT
  2086. $sSourceDir = APPROOT.'modules';
  2087. }
  2088. if (($sMode == 'upgrade'))
  2089. {
  2090. // Copy the previous extensions, if any
  2091. $sPreviousExtensionsDir = $this->oWizard->GetParameter('copy_extensions_from');
  2092. if (is_dir($sPreviousExtensionsDir))
  2093. {
  2094. // Copy the extensions one by one to merge them with the existing extensions in /extensions
  2095. $aExtensions = glob($sPreviousExtensionsDir.'/*', GLOB_ONLYDIR);
  2096. foreach($aExtensions as $sDirPath)
  2097. {
  2098. $sExtName = basename($sDirPath);
  2099. $aCopies[] = array('source' => $sDirPath, 'destination' => 'extensions/'.$sExtName); // Source is an absolute path, destination is relative to APPROOT
  2100. }
  2101. }
  2102. }
  2103. $aInstallParams = array (
  2104. 'mode' => $sMode,
  2105. 'preinstall' => array (
  2106. 'copies' => $aCopies,
  2107. // 'backup' => see below
  2108. ),
  2109. 'source_dir' => str_replace(APPROOT, '', $sSourceDir),
  2110. 'datamodel_version' => $this->oWizard->GetParameter('datamodel_version'), //TODO: let the installer compute this automatically...
  2111. 'previous_configuration_file' => $sPreviousConfigurationFile,
  2112. 'extensions_dir' => 'extensions',
  2113. 'target_env' => 'production',
  2114. 'workspace_dir' => '',
  2115. 'database' => array (
  2116. 'server' => $this->oWizard->GetParameter('db_server'),
  2117. 'user' => $this->oWizard->GetParameter('db_user'),
  2118. 'pwd' => $this->oWizard->GetParameter('db_pwd'),
  2119. 'name' => $sDBName,
  2120. 'prefix' => $this->oWizard->GetParameter('db_prefix'),
  2121. ),
  2122. 'url' => $this->oWizard->GetParameter('application_url'),
  2123. 'graphviz_path' => $this->oWizard->GetParameter('graphviz_path'),
  2124. 'admin_account' => array (
  2125. 'user' => $this->oWizard->GetParameter('admin_user'),
  2126. 'pwd' => $this->oWizard->GetParameter('admin_pwd'),
  2127. 'language' => $this->oWizard->GetParameter('admin_language'),
  2128. ),
  2129. 'language' => $this->oWizard->GetParameter('default_language'),
  2130. 'selected_modules' => $aSelectedModules,
  2131. 'selected_extensions' => $aSelectedExtensions,
  2132. 'sample_data' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? true : false ,
  2133. 'old_addon' => $this->oWizard->GetParameter('old_addon', false), // whether or not to use the "old" userrights profile addon
  2134. 'options' => json_decode($this->oWizard->GetParameter('misc_options', '[]'), true),
  2135. );
  2136. if ($sBackupDestination != '')
  2137. {
  2138. $aInstallParams['preinstall']['backup'] = array (
  2139. 'destination' => $sBackupDestination,
  2140. 'configuration_file' => $sPreviousConfigurationFile,
  2141. );
  2142. }
  2143. return $aInstallParams;
  2144. }
  2145. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  2146. {
  2147. $oParameters = new PHPParameters();
  2148. $sStep = $aParameters['installer_step'];
  2149. $sJSONParameters = $aParameters['installer_config'];
  2150. $oParameters->LoadFromHash(json_decode($sJSONParameters, true /* bAssoc */));
  2151. $oInstaller = new ApplicationInstaller($oParameters);
  2152. $aRes = $oInstaller->ExecuteStep($sStep);
  2153. if (($aRes['status'] != ApplicationInstaller::ERROR) && ($aRes['next-step'] != ''))
  2154. {
  2155. // Tell the web page to move the progress bar and to launch the next step
  2156. $sMessage = addslashes(htmlentities($aRes['next-step-label'], ENT_QUOTES, 'UTF-8'));
  2157. $oPage->add_ready_script(
  2158. <<<EOF
  2159. $("#wiz_form").data("installation_status", "running");
  2160. WizardUpdateButtons();
  2161. $('#setup_msg').html('$sMessage');
  2162. $('#progress').progression( {Current:{$aRes['percentage-completed']}, Maximum: 100, aBackgroundImg: GetAbsoluteUrlAppRoot()+'setup/orange-progress.gif', aTextColor: '#000000'} );
  2163. //$("#percentage").html('{$aRes['percentage-completed']} % completed<br/>{$aRes['next-step-label']}');
  2164. ExecuteStep('{$aRes['next-step']}');
  2165. EOF
  2166. );
  2167. }
  2168. else if ($aRes['status'] != ApplicationInstaller::ERROR)
  2169. {
  2170. // Installation complete, move to the next step of the wizard
  2171. $oPage->add_ready_script(
  2172. <<<EOF
  2173. $("#wiz_form").data("installation_status", "completed");
  2174. $('#progress').progression( {Current:100, Maximum: 100, aBackgroundImg: GetAbsoluteUrlAppRoot()+'setup/orange-progress.gif', aTextColor: '#000000'} );
  2175. WizardUpdateButtons();
  2176. $("#btn_next").unbind("click.install");
  2177. $("#btn_next").click();
  2178. EOF
  2179. );
  2180. }
  2181. else
  2182. {
  2183. $sMessage = addslashes(htmlentities($aRes['message'], ENT_QUOTES, 'UTF-8'));
  2184. $oPage->add_ready_script(
  2185. <<<EOF
  2186. $("#wiz_form").data("installation_status", "error");
  2187. WizardUpdateButtons();
  2188. $('#setup_msg').html('$sMessage');
  2189. EOF
  2190. );
  2191. }
  2192. }
  2193. /**
  2194. * Tells whether the "Next" button should be enabled interactively
  2195. * @return string A piece of javascript code returning either true or false
  2196. */
  2197. public function JSCanMoveForward()
  2198. {
  2199. return 'return (($("#wiz_form").data("installation_status") === "not started") || ($("#wiz_form").data("installation_status") === "completed"));';
  2200. }
  2201. /**
  2202. * Tells whether the "Next" button should be enabled interactively
  2203. * @return string A piece of javascript code returning either true or false
  2204. */
  2205. public function JSCanMoveBackward()
  2206. {
  2207. return 'var sStatus = $("#wiz_form").data("installation_status"); return ((sStatus === "not started") || (sStatus === "error"));';
  2208. }
  2209. }
  2210. /**
  2211. * Summary of the installation tasks
  2212. */
  2213. class WizStepDone extends WizardStep
  2214. {
  2215. public function GetTitle()
  2216. {
  2217. return 'Done';
  2218. }
  2219. public function GetPossibleSteps()
  2220. {
  2221. return array();
  2222. }
  2223. public function ProcessParams($bMoveForward = true)
  2224. {
  2225. return array('class' => '', 'state' => '');
  2226. }
  2227. public function Display(WebPage $oPage)
  2228. {
  2229. // Check if there are some manual steps required:
  2230. $aManualSteps = array();
  2231. $aAvailableModules = SetupUtils::AnalyzeInstallation($this->oWizard);
  2232. $sRootUrl = utils::GetAbsoluteUrlAppRoot();
  2233. $aSelectedModules = json_decode($this->oWizard->GetParameter('selected_modules'), true);
  2234. foreach($aSelectedModules as $sModuleId)
  2235. {
  2236. if (!empty($aAvailableModules[$sModuleId]['doc.manual_setup']))
  2237. {
  2238. $aManualSteps[$aAvailableModules[$sModuleId]['label']] = $sRootUrl.$aAvailableModules[$sModuleId]['doc.manual_setup'];
  2239. }
  2240. }
  2241. if (count($aManualSteps) > 0)
  2242. {
  2243. $oPage->add("<h2>Manual operations required</h2>");
  2244. $oPage->p("In order to complete the installation, the following manual operations are required:");
  2245. foreach($aManualSteps as $sModuleLabel => $sUrl)
  2246. {
  2247. $oPage->p("<a href=\"$sUrl\" target=\"_blank\">Manual instructions for $sModuleLabel</a>");
  2248. }
  2249. $oPage->add("<h2>Congratulations for installing ".ITOP_APPLICATION."</h2>");
  2250. }
  2251. else
  2252. {
  2253. $oPage->add("<h2>Congratulations for installing ".ITOP_APPLICATION."</h2>");
  2254. $oPage->ok("The installation completed successfully.");
  2255. }
  2256. if (($this->oWizard->GetParameter('mode', '') == 'upgrade') && $this->oWizard->GetParameter('db_backup', false))
  2257. {
  2258. $sBackupDestination = $this->oWizard->GetParameter('db_backup_path', '');
  2259. if (file_exists($sBackupDestination.'.tar.gz'))
  2260. {
  2261. // To mitigate security risks: pass only the filename without the extension, the download will add the extension itself
  2262. $oPage->p('Your backup is ready');
  2263. $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>');
  2264. }
  2265. else
  2266. {
  2267. $oPage->p('<img src="../images/error.png"/>&nbsp;Warning: Backup creation failed !');
  2268. }
  2269. }
  2270. // Form goes here.. No back button since the job is done !
  2271. $oPage->add('<table id="placeholder" style="width:600px;border:0;padding:0;"><tr>');
  2272. $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>");
  2273. $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>");
  2274. $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>");
  2275. $oPage->add('</tr></table>');
  2276. $oConfig = new Config(utils::GetConfigFilePath());
  2277. $sIframeUrl = $oConfig->GetModuleSetting('itop-hub-connector', 'setup_url', '');
  2278. if ($sIframeUrl != '')
  2279. {
  2280. $oPage->add('<iframe id="fresh_content" style="border:0; width:100%; display:none;" src="'.$sIframeUrl.'"></iframe>');
  2281. $oPage->add_script("window.addEventListener('message', function(event) {
  2282. if (event.data === 'itophub_load_completed')
  2283. {
  2284. $('#fresh_content').height($('#placeholder').height());
  2285. $('#placeholder').hide();
  2286. $('#fresh_content').show();
  2287. }
  2288. }, false);
  2289. ");
  2290. }
  2291. $sForm = '<form method="post" action="'.$this->oWizard->GetParameter('application_url').'pages/UI.php">';
  2292. $sForm .= '<input type="hidden" name="auth_user" value="'.htmlentities($this->oWizard->GetParameter('admin_user'), ENT_QUOTES, 'UTF-8').'">';
  2293. $sForm .= '<input type="hidden" name="auth_pwd" value="'.htmlentities($this->oWizard->GetParameter('admin_pwd'), ENT_QUOTES, 'UTF-8').'">';
  2294. $sForm .= "<p style=\"text-align:center;width:100%\"><button id=\"enter_itop\" type=\"submit\">Enter ".ITOP_APPLICATION."</button></p>";
  2295. $sForm .= '</form>';
  2296. $sPHPVersion = phpversion();
  2297. $sMySQLVersion = SetupUtils::GetMySQLVersion($this->oWizard->GetParameter('db_server'), $this->oWizard->GetParameter('db_user'), $this->oWizard->GetParameter('db_pwd'));
  2298. $aParameters = json_decode($this->oWizard->GetParameter('selected_components', '{}'), true);
  2299. $sCompactWizChoices = array();
  2300. foreach($aParameters as $iStep => $aChoices)
  2301. {
  2302. $aShortChoices = array();
  2303. foreach($aChoices as $sChoiceCode)
  2304. {
  2305. $sShortCode = str_replace('_', '', $sChoiceCode);
  2306. $aShortChoices[] = $sShortCode;
  2307. }
  2308. $sCompactWizChoices[] = implode(' ',$aShortChoices);
  2309. }
  2310. $sInstallMode = 'i';
  2311. if ($this->oWizard->GetParameter('install_mode', 'install') == 'upgrade')
  2312. {
  2313. if (!$this->oWizard->GetParameter('license'))
  2314. {
  2315. // When the version does not change we don't ask for the licence again
  2316. $sInstallMode = 'r';
  2317. }
  2318. else
  2319. {
  2320. // An actual upgrade
  2321. $sInstallMode = 'u';
  2322. }
  2323. }
  2324. $aUrlParams = array(
  2325. 'p' => ITOP_APPLICATION,
  2326. 'v' => ITOP_VERSION,
  2327. 'php' => $sPHPVersion,
  2328. 'mysql' => $sMySQLVersion,
  2329. 'os' => PHP_OS,
  2330. 's' => ($this->oWizard->GetParameter('sample_data', '') == 'yes') ? 1 : 0 ,
  2331. 'l' => $this->oWizard->GetParameter('default_language'),
  2332. 'i' => $sInstallMode,
  2333. 'w' => json_encode($sCompactWizChoices),
  2334. );
  2335. $aSafeParams = array();
  2336. foreach($aUrlParams as $sCode => $sValue)
  2337. {
  2338. $aSafeParams[] = $sCode.'='.urlencode($sValue);
  2339. }
  2340. $sImgUrl = 'http://www.combodo.com/stats/?'.implode('&', $aSafeParams);
  2341. $aAdditionalModules = array();
  2342. foreach(json_decode($this->oWizard->GetParameter('additional_extensions_modules'), true) as $idx => $aModuleInfo)
  2343. {
  2344. if (in_array('_'.$idx, $aParameters[count($aParameters)-1]))
  2345. {
  2346. // Extensions "choices" can now have more than one module
  2347. foreach($aModuleInfo['modules'] as $sModuleName)
  2348. {
  2349. $aAdditionalModules[] = $sModuleName;
  2350. }
  2351. }
  2352. }
  2353. $idx = 0;
  2354. $aReportedModules = array();
  2355. while($idx < count($aAdditionalModules) && (strlen($sImgUrl.'&m='.urlencode(implode(' ', $aReportedModules))) < 2000)) // reasonable limit for the URL: 2000 chars
  2356. {
  2357. $aReportedModules[] = $aAdditionalModules[$idx];
  2358. $idx++;
  2359. }
  2360. $sImgUrl .= '&m='.urlencode(implode(' ', $aReportedModules));
  2361. $oPage->add('<img style="border:0" src="'.$sImgUrl.'"/>');
  2362. $sForm = addslashes($sForm);
  2363. $oPage->add_ready_script("$('#wiz_form').after('$sForm');");
  2364. }
  2365. public function CanMoveForward()
  2366. {
  2367. return false;
  2368. }
  2369. public function CanMoveBackward()
  2370. {
  2371. return false;
  2372. }
  2373. /**
  2374. * Tells whether this step of the wizard requires that the configuration file be writable
  2375. * @return bool True if the wizard will possibly need to modify the configuration at some point
  2376. */
  2377. public function RequiresWritableConfig()
  2378. {
  2379. return false; //This step executes once the config was written and secured
  2380. }
  2381. public function AsyncAction(WebPage $oPage, $sCode, $aParameters)
  2382. {
  2383. // For security reasons: add the extension now so that this action can be used to read *only* .tar.gz files from the disk...
  2384. $sBackupFile = $aParameters['backup'].'.tar.gz';
  2385. if (file_exists($sBackupFile))
  2386. {
  2387. // Make sure there is NO output at all before our content, otherwise the document will be corrupted
  2388. $sPreviousContent = ob_get_clean();
  2389. $oPage->SetContentType('application/gzip');
  2390. $oPage->SetContentDisposition('attachment', basename($sBackupFile));
  2391. $oPage->add(file_get_contents($sBackupFile));
  2392. }
  2393. }
  2394. }