setuppage.class.inc.php 7.4 KB

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