setuppage.class.inc.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <?php
  2. // Copyright (C) 2010-2012 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * Web page used for the setup
  20. *
  21. * @copyright Copyright (C) 2010-2012 Combodo SARL
  22. * @license http://opensource.org/licenses/AGPL-3.0
  23. */
  24. require_once(APPROOT."/application/nicewebpage.class.inc.php");
  25. require_once(APPROOT."setup/modulediscovery.class.inc.php");
  26. require_once(APPROOT."setup/runtimeenv.class.inc.php");
  27. define('INSTALL_LOG_FILE', APPROOT.'/log/setup.log');
  28. date_default_timezone_set('Europe/Paris');
  29. class SetupPage extends NiceWebPage
  30. {
  31. public function __construct($sTitle)
  32. {
  33. parent::__construct($sTitle);
  34. $this->add_linked_script("../js/jquery.blockUI.js");
  35. $this->add_linked_script("../setup/setup.js");
  36. $this->add_style("
  37. body {
  38. background-color: #eee;
  39. margin: 0;
  40. padding: 0;
  41. font-size: 10pt;
  42. overflow-y: auto;
  43. }
  44. #header {
  45. width: 600px;
  46. margin-left: auto;
  47. margin-right: auto;
  48. margin-top: 50px;
  49. padding: 20px;
  50. background: #f6f6f1;
  51. height: 54px;
  52. border-top: 1px solid #000;
  53. border-left: 1px solid #000;
  54. border-right: 1px solid #000;
  55. }
  56. #header img {
  57. border: 0;
  58. vertical-align: middle;
  59. margin-right: 20px;
  60. }
  61. #header h1 {
  62. vertical-align: middle;
  63. height: 54px;
  64. noline-height: 54px;
  65. margin: 0;
  66. }
  67. #setup {
  68. width: 600px;
  69. margin-left: auto;
  70. margin-right: auto;
  71. padding: 20px;
  72. background-color: #fff;
  73. border-left: 1px solid #000;
  74. border-right: 1px solid #000;
  75. border-bottom: 1px solid #000;
  76. }
  77. .center {
  78. text-align: center;
  79. }
  80. h1 {
  81. color: #1C94C4;
  82. font-size: 16pt;
  83. }
  84. h2 {
  85. color: #000;
  86. font-size: 14pt;
  87. }
  88. h3 {
  89. color: #1C94C4;
  90. font-size: 12pt;
  91. font-weight: bold;
  92. }
  93. .next {
  94. width: 100%;
  95. text-align: right;
  96. }
  97. .v-spacer {
  98. padding-top: 1em;
  99. }
  100. button {
  101. margin-top: 1em;
  102. padding-left: 1em;
  103. padding-right: 1em;
  104. }
  105. p.info {
  106. padding-left: 50px;
  107. background: url(../images/info-mid.png) no-repeat left -5px;
  108. min-height: 48px;
  109. }
  110. p.ok {
  111. padding-left: 50px;
  112. background: url(../images/clean-mid.png) no-repeat left -8px;
  113. min-height: 48px;
  114. }
  115. p.warning {
  116. padding-left: 50px;
  117. background: url(../images/messagebox_warning-mid.png) no-repeat left -5px;
  118. min-height: 48px;
  119. }
  120. p.error {
  121. padding-left: 50px;
  122. background: url(../images/stop-mid.png) no-repeat left -5px;
  123. min-height: 48px;
  124. }
  125. td.label {
  126. text-align: left;
  127. }
  128. label.read-only {
  129. color: #666;
  130. cursor: text;
  131. }
  132. td.input {
  133. text-align: left;
  134. }
  135. table.formTable {
  136. border: 0;
  137. cellpadding: 2px;
  138. cellspacing: 0;
  139. }
  140. .wizlabel, .wizinput {
  141. color: #000;
  142. font-size: 10pt;
  143. }
  144. .wizhelp {
  145. color: #333;
  146. font-size: 8pt;
  147. }
  148. #progress {
  149. border:1px solid #000000;
  150. width: 180px;
  151. height: 20px;
  152. line-height: 20px;
  153. text-align: center;
  154. margin: 5px;
  155. }
  156. h3.clickable {
  157. background: url(../images/plus.gif) no-repeat left;
  158. padding-left:16px;
  159. cursor: hand;
  160. }
  161. h3.clickable.open {
  162. background: url(../images/minus.gif) no-repeat left;
  163. padding-left:16px;
  164. cursor: hand;
  165. }
  166. ");
  167. }
  168. /**
  169. * Overriden because the application is not fully loaded when the setup is being run
  170. */
  171. public function GetAbsoluteUrlAppRoot()
  172. {
  173. return '../';
  174. }
  175. /**
  176. * Overriden because the application is not fully loaded when the setup is being run
  177. */
  178. public function GetAbsoluteUrlModulesRoot()
  179. {
  180. return $this->GetAbsoluteUrlAppRoot().utils::GetCurrentEnvironment();
  181. }
  182. /**
  183. * Overriden because the application is not fully loaded when the setup is being run
  184. */
  185. function GetApplicationContext()
  186. {
  187. return '';
  188. }
  189. public function info($sText)
  190. {
  191. $this->add("<p class=\"info\">$sText</p>\n");
  192. $this->log_info($sText);
  193. }
  194. public function ok($sText)
  195. {
  196. $this->add("<p class=\"ok\">$sText</p>\n");
  197. $this->log_ok($sText);
  198. }
  199. public function warning($sText)
  200. {
  201. $this->add("<p class=\"warning\">$sText</p>\n");
  202. $this->log_warning($sText);
  203. }
  204. public function error($sText)
  205. {
  206. $this->add("<p class=\"error\">$sText</p>\n");
  207. $this->log_error($sText);
  208. }
  209. public function form($aData)
  210. {
  211. $this->add("<table class=\"formTable\">\n");
  212. foreach($aData as $aRow)
  213. {
  214. $this->add("<tr>\n");
  215. if (isset($aRow['label']) && isset($aRow['input']) && isset($aRow['help']))
  216. {
  217. $this->add("<td class=\"wizlabel\">{$aRow['label']}</td>\n");
  218. $this->add("<td class=\"wizinput\">{$aRow['input']}</td>\n");
  219. $this->add("<td class=\"wizhelp\">{$aRow['help']}</td>\n");
  220. }
  221. else if (isset($aRow['label']) && isset($aRow['help']))
  222. {
  223. $this->add("<td colspan=\"2\" class=\"wizlabel\">{$aRow['label']}</td>\n");
  224. $this->add("<td class=\"wizhelp\">{$aRow['help']}</td>\n");
  225. }
  226. else if (isset($aRow['label']) && isset($aRow['input']))
  227. {
  228. $this->add("<td class=\"wizlabel\">{$aRow['label']}</td>\n");
  229. $this->add("<td colspan=\"2\" class=\"wizinput\">{$aRow['input']}</td>\n");
  230. }
  231. else if (isset($aRow['label']))
  232. {
  233. $this->add("<td colspan=\"3\" class=\"wizlabel\">{$aRow['label']}</td>\n");
  234. }
  235. $this->add("</tr>\n");
  236. }
  237. $this->add("</table>\n");
  238. }
  239. public function collapsible($sId, $sTitle, $aItems, $bOpen = true)
  240. {
  241. $this->add("<h3 class=\"clickable open\" id=\"{$sId}\">$sTitle</h3>");
  242. $this->p('<ul id="'.$sId.'_list">');
  243. foreach($aItems as $sItem)
  244. {
  245. $this->p("<li>$sItem</li>\n");
  246. }
  247. $this->p('</ul>');
  248. $this->add_ready_script("$('#{$sId}').click( function() { $(this).toggleClass('open'); $('#{$sId}_list').toggle();} );\n");
  249. if (!$bOpen)
  250. {
  251. $this->add_ready_script("$('#{$sId}').toggleClass('open'); $('#{$sId}_list').toggle();\n");
  252. }
  253. }
  254. public function output()
  255. {
  256. $this->s_content = "<div id=\"header\"><h1><a href=\"http://www.combodo.com/itop\" target=\"_blank\"><img title=\"iTop by Combodo\" src=\"../images/itop-logo.png\"></a>&nbsp;".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</h1>\n</div><div id=\"setup\">{$this->s_content}\n</div>\n";
  257. return parent::output();
  258. }
  259. public static function log_error($sText)
  260. {
  261. self::log("Error - ".$sText);
  262. }
  263. public static function log_warning($sText)
  264. {
  265. self::log("Warning - ".$sText);
  266. }
  267. public static function log_info($sText)
  268. {
  269. self::log("Info - ".$sText);
  270. }
  271. public static function log_ok($sText)
  272. {
  273. self::log("Ok - ".$sText);
  274. }
  275. public static function log($sText)
  276. {
  277. $hLogFile = @fopen(INSTALL_LOG_FILE, 'a');
  278. if ($hLogFile !== false)
  279. {
  280. $sDate = date('Y-m-d H:i:s');
  281. fwrite($hLogFile, "$sDate - $sText\n");
  282. fclose($hLogFile);
  283. }
  284. }
  285. } // End of class