setuppage.class.inc.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. class SetupPage extends NiceWebPage
  29. {
  30. public function __construct($sTitle)
  31. {
  32. parent::__construct($sTitle);
  33. $this->add_linked_script("../js/jquery.blockUI.js");
  34. $this->add_linked_script("../setup/setup.js");
  35. $this->add_style("
  36. body {
  37. background-color: #eee;
  38. margin: 0;
  39. padding: 0;
  40. font-size: 10pt;
  41. overflow-y: auto;
  42. }
  43. #header {
  44. width: 600px;
  45. margin-left: auto;
  46. margin-right: auto;
  47. margin-top: 50px;
  48. padding: 20px;
  49. background: #f6f6f1;
  50. height: 54px;
  51. border-top: 1px solid #000;
  52. border-left: 1px solid #000;
  53. border-right: 1px solid #000;
  54. }
  55. #header img {
  56. border: 0;
  57. vertical-align: middle;
  58. margin-right: 20px;
  59. }
  60. #header h1 {
  61. vertical-align: middle;
  62. height: 54px;
  63. noline-height: 54px;
  64. margin: 0;
  65. }
  66. #setup {
  67. width: 600px;
  68. margin-left: auto;
  69. margin-right: auto;
  70. padding: 20px;
  71. background-color: #fff;
  72. border-left: 1px solid #000;
  73. border-right: 1px solid #000;
  74. border-bottom: 1px solid #000;
  75. }
  76. .center {
  77. text-align: center;
  78. }
  79. h1 {
  80. color: #555555;
  81. font-size: 16pt;
  82. }
  83. h2 {
  84. color: #000;
  85. font-size: 14pt;
  86. }
  87. h3 {
  88. color: #1C94C4;
  89. font-size: 12pt;
  90. font-weight: bold;
  91. }
  92. .next {
  93. width: 100%;
  94. text-align: right;
  95. }
  96. .v-spacer {
  97. padding-top: 1em;
  98. }
  99. button {
  100. margin-top: 1em;
  101. padding-left: 1em;
  102. padding-right: 1em;
  103. }
  104. p.info {
  105. padding-left: 50px;
  106. background: url(../images/info-mid.png) no-repeat left -5px;
  107. min-height: 48px;
  108. }
  109. p.ok {
  110. padding-left: 50px;
  111. background: url(../images/clean-mid.png) no-repeat left -8px;
  112. min-height: 48px;
  113. }
  114. p.warning {
  115. padding-left: 50px;
  116. background: url(../images/messagebox_warning-mid.png) no-repeat left -5px;
  117. min-height: 48px;
  118. }
  119. p.error {
  120. padding-left: 50px;
  121. background: url(../images/stop-mid.png) no-repeat left -5px;
  122. min-height: 48px;
  123. }
  124. td.label {
  125. text-align: left;
  126. }
  127. label.read-only {
  128. color: #666;
  129. cursor: text;
  130. }
  131. td.input {
  132. text-align: left;
  133. }
  134. table.formTable {
  135. border: 0;
  136. cellpadding: 2px;
  137. cellspacing: 0;
  138. }
  139. .wizlabel, .wizinput {
  140. color: #000;
  141. font-size: 10pt;
  142. }
  143. .wizhelp {
  144. color: #333;
  145. font-size: 8pt;
  146. }
  147. #progress {
  148. border:1px solid #000000;
  149. width: 180px;
  150. height: 20px;
  151. line-height: 20px;
  152. text-align: center;
  153. margin: 5px;
  154. }
  155. h3.clickable {
  156. background: url(../images/plus.gif) no-repeat left;
  157. padding-left:16px;
  158. cursor: hand;
  159. }
  160. h3.clickable.open {
  161. background: url(../images/minus.gif) no-repeat left;
  162. padding-left:16px;
  163. cursor: hand;
  164. }
  165. ");
  166. }
  167. /**
  168. * Overriden because the application is not fully loaded when the setup is being run
  169. */
  170. public function GetAbsoluteUrlAppRoot()
  171. {
  172. return '../';
  173. }
  174. /**
  175. * Overriden because the application is not fully loaded when the setup is being run
  176. */
  177. public function GetAbsoluteUrlModulesRoot()
  178. {
  179. return $this->GetAbsoluteUrlAppRoot().utils::GetCurrentEnvironment();
  180. }
  181. /**
  182. * Overriden because the application is not fully loaded when the setup is being run
  183. */
  184. function GetApplicationContext()
  185. {
  186. return '';
  187. }
  188. public function info($sText)
  189. {
  190. $this->add("<p class=\"info\">$sText</p>\n");
  191. $this->log_info($sText);
  192. }
  193. public function ok($sText)
  194. {
  195. $this->add("<p class=\"ok\">$sText</p>\n");
  196. $this->log_ok($sText);
  197. }
  198. public function warning($sText)
  199. {
  200. $this->add("<p class=\"warning\">$sText</p>\n");
  201. $this->log_warning($sText);
  202. }
  203. public function error($sText)
  204. {
  205. $this->add("<p class=\"error\">$sText</p>\n");
  206. $this->log_error($sText);
  207. }
  208. public function form($aData)
  209. {
  210. $this->add("<table class=\"formTable\">\n");
  211. foreach($aData as $aRow)
  212. {
  213. $this->add("<tr>\n");
  214. if (isset($aRow['label']) && isset($aRow['input']) && isset($aRow['help']))
  215. {
  216. $this->add("<td class=\"wizlabel\">{$aRow['label']}</td>\n");
  217. $this->add("<td class=\"wizinput\">{$aRow['input']}</td>\n");
  218. $this->add("<td class=\"wizhelp\">{$aRow['help']}</td>\n");
  219. }
  220. else if (isset($aRow['label']) && isset($aRow['help']))
  221. {
  222. $this->add("<td colspan=\"2\" class=\"wizlabel\">{$aRow['label']}</td>\n");
  223. $this->add("<td class=\"wizhelp\">{$aRow['help']}</td>\n");
  224. }
  225. else if (isset($aRow['label']) && isset($aRow['input']))
  226. {
  227. $this->add("<td class=\"wizlabel\">{$aRow['label']}</td>\n");
  228. $this->add("<td colspan=\"2\" class=\"wizinput\">{$aRow['input']}</td>\n");
  229. }
  230. else if (isset($aRow['label']))
  231. {
  232. $this->add("<td colspan=\"3\" class=\"wizlabel\">{$aRow['label']}</td>\n");
  233. }
  234. $this->add("</tr>\n");
  235. }
  236. $this->add("</table>\n");
  237. }
  238. public function collapsible($sId, $sTitle, $aItems, $bOpen = true)
  239. {
  240. $this->add("<h3 class=\"clickable open\" id=\"{$sId}\">$sTitle</h3>");
  241. $this->p('<ul id="'.$sId.'_list">');
  242. foreach($aItems as $sItem)
  243. {
  244. $this->p("<li>$sItem</li>\n");
  245. }
  246. $this->p('</ul>');
  247. $this->add_ready_script("$('#{$sId}').click( function() { $(this).toggleClass('open'); $('#{$sId}_list').toggle();} );\n");
  248. if (!$bOpen)
  249. {
  250. $this->add_ready_script("$('#{$sId}').toggleClass('open'); $('#{$sId}_list').toggle();\n");
  251. }
  252. }
  253. public function output()
  254. {
  255. $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?itopversion=".ITOP_VERSION."\"></a>&nbsp;".htmlentities($this->s_title, ENT_QUOTES, 'UTF-8')."</h1>\n</div><div id=\"setup\">{$this->s_content}\n</div>\n";
  256. return parent::output();
  257. }
  258. public static function log_error($sText)
  259. {
  260. self::log("Error - ".$sText);
  261. }
  262. public static function log_warning($sText)
  263. {
  264. self::log("Warning - ".$sText);
  265. }
  266. public static function log_info($sText)
  267. {
  268. self::log("Info - ".$sText);
  269. }
  270. public static function log_ok($sText)
  271. {
  272. self::log("Ok - ".$sText);
  273. }
  274. public static function log($sText)
  275. {
  276. $hLogFile = @fopen(INSTALL_LOG_FILE, 'a');
  277. if ($hLogFile !== false)
  278. {
  279. $sDate = date('Y-m-d H:i:s');
  280. fwrite($hLogFile, "$sDate - $sText\n");
  281. fclose($hLogFile);
  282. }
  283. }
  284. } // End of class