setuppage.class.inc.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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("../application/nicewebpage.class.inc.php");
  25. define('INSTALL_LOG_FILE', '../setup.log');
  26. class SetupWebPage extends NiceWebPage
  27. {
  28. public function __construct($sTitle)
  29. {
  30. parent::__construct($sTitle);
  31. $this->add_linked_script("../js/jquery.blockUI.js");
  32. $this->add_linked_script("./setup.js");
  33. $this->add_style("
  34. body {
  35. background-color: #eee;
  36. margin: 0;
  37. padding: 0;
  38. font-size: 10pt;
  39. overflow-y: auto;
  40. }
  41. #header {
  42. width: 600px;
  43. margin-left: auto;
  44. margin-right: auto;
  45. margin-top: 50px;
  46. padding: 20px;
  47. background: #f6f6f1;
  48. height: 54px;
  49. border-top: 1px solid #000;
  50. border-left: 1px solid #000;
  51. border-right: 1px solid #000;
  52. }
  53. #header img {
  54. border: 0;
  55. vertical-align: middle;
  56. margin-right: 20px;
  57. }
  58. #header h1 {
  59. vertical-align: middle;
  60. height: 54px;
  61. noline-height: 54px;
  62. margin: 0;
  63. }
  64. #setup {
  65. width: 600px;
  66. margin-left: auto;
  67. margin-right: auto;
  68. padding: 20px;
  69. background-color: #fff;
  70. border-left: 1px solid #000;
  71. border-right: 1px solid #000;
  72. border-bottom: 1px solid #000;
  73. }
  74. .center {
  75. text-align: center;
  76. }
  77. h1 {
  78. color: #1C94C4;
  79. font-size: 16pt;
  80. }
  81. h2 {
  82. color: #000;
  83. font-size: 14pt;
  84. }
  85. .next {
  86. width: 100%;
  87. text-align: right;
  88. }
  89. .v-spacer {
  90. padding-top: 1em;
  91. }
  92. button {
  93. margin-top: 1em;
  94. padding-left: 1em;
  95. padding-right: 1em;
  96. }
  97. p.info {
  98. padding-left: 50px;
  99. background: url(../images/info-mid.png) no-repeat left -5px;
  100. height: 48px;
  101. }
  102. p.ok {
  103. padding-left: 50px;
  104. background: url(../images/clean-mid.png) no-repeat left -8px;
  105. height: 48px;
  106. }
  107. p.warning {
  108. padding-left: 50px;
  109. background: url(../images/messagebox_warning-mid.png) no-repeat left -5px;
  110. height: 48px;
  111. }
  112. p.error {
  113. padding-left: 50px;
  114. background: url(../images/stop-mid.png) no-repeat left -5px;
  115. height: 48px;
  116. }
  117. td.label {
  118. text-align: left;
  119. }
  120. label.read-only {
  121. color: #666;
  122. cursor: text;
  123. }
  124. td.input {
  125. text-align: left;
  126. }
  127. table.formTable {
  128. border: 0;
  129. cellpadding: 2px;
  130. cellspacing: 0;
  131. }
  132. .wizlabel, .wizinput {
  133. color: #000;
  134. font-size: 10pt;
  135. }
  136. .wizhelp {
  137. color: #333;
  138. font-size: 8pt;
  139. }
  140. #progress {
  141. border:1px solid #000000;
  142. width: 180px;
  143. height: 20px;
  144. line-height: 20px;
  145. text-align: center;
  146. margin: 5px;
  147. }
  148. ");
  149. }
  150. public function info($sText)
  151. {
  152. $this->add("<p class=\"info\">$sText</p>\n");
  153. $this->log_info($sText);
  154. }
  155. public function ok($sText)
  156. {
  157. $this->add("<p class=\"ok\">$sText</p>\n");
  158. $this->log_ok($sText);
  159. }
  160. public function warning($sText)
  161. {
  162. $this->add("<p class=\"warning\">$sText</p>\n");
  163. $this->log_warning($sText);
  164. }
  165. public function error($sText)
  166. {
  167. $this->add("<p class=\"error\">$sText</p>\n");
  168. $this->log_error($sText);
  169. }
  170. public function form($aData)
  171. {
  172. $this->add("<table class=\"formTable\">\n");
  173. foreach($aData as $aRow)
  174. {
  175. $this->add("<tr>\n");
  176. if (isset($aRow['label']) && isset($aRow['input']) && isset($aRow['help']))
  177. {
  178. $this->add("<td class=\"wizlabel\">{$aRow['label']}</td>\n");
  179. $this->add("<td class=\"wizinput\">{$aRow['input']}</td>\n");
  180. $this->add("<td class=\"wizhelp\">{$aRow['help']}</td>\n");
  181. }
  182. else if (isset($aRow['label']) && isset($aRow['help']))
  183. {
  184. $this->add("<td colspan=\"2\" class=\"wizlabel\">{$aRow['label']}</td>\n");
  185. $this->add("<td class=\"wizhelp\">{$aRow['help']}</td>\n");
  186. }
  187. else if (isset($aRow['label']) && isset($aRow['input']))
  188. {
  189. $this->add("<td class=\"wizlabel\">{$aRow['label']}</td>\n");
  190. $this->add("<td colspan=\"2\" class=\"wizinput\">{$aRow['input']}</td>\n");
  191. }
  192. else if (isset($aRow['label']))
  193. {
  194. $this->add("<td colspan=\"3\" class=\"wizlabel\">{$aRow['label']}</td>\n");
  195. }
  196. $this->add("</tr>\n");
  197. }
  198. $this->add("</table>\n");
  199. }
  200. public function output()
  201. {
  202. $this->s_content = "<div id=\"header\"><h1><a href=\"http://www.combodo.com/itop\"><img title=\"iTop by Combodo\" src=\"../images/itop-logo.png\"></a>&nbsp;{$this->s_title}</h1>\n</div><div id=\"setup\">{$this->s_content}\n</div>\n";
  203. return parent::output();
  204. }
  205. public static function log_error($sText)
  206. {
  207. self::log("Error - ".$sText);
  208. }
  209. public static function log_warning($sText)
  210. {
  211. self::log("Warning - ".$sText);
  212. }
  213. public static function log_info($sText)
  214. {
  215. self::log("Info - ".$sText);
  216. }
  217. public static function log_ok($sText)
  218. {
  219. self::log("Ok - ".$sText);
  220. }
  221. public static function log($sText)
  222. {
  223. $hLogFile = @fopen(INSTALL_LOG_FILE, 'a');
  224. if ($hLogFile !== false)
  225. {
  226. $sDate = date('Y-m-d H:i:s');
  227. fwrite($hLogFile, "$sDate - $sText\n");
  228. fclose($hLogFile);
  229. }
  230. }
  231. static $m_aModuleArgs = array(
  232. 'label' => 'One line description shown during the interactive setup',
  233. 'dependencies' => 'array of module ids',
  234. 'mandatory' => 'boolean',
  235. 'visible' => 'boolean',
  236. 'datamodel' => 'array of data model files',
  237. 'dictionary' => 'array of dictionary files',
  238. 'data.struct' => 'array of structural data files',
  239. 'data.sample' => 'array of sample data files',
  240. 'doc.manual_setup' => 'url',
  241. 'doc.more_information' => 'url',
  242. );
  243. static $m_aModules = array();
  244. // All the entries below are list of (relative) file paths
  245. static $m_aFilesList = array('datamodel', 'dictionary', 'data.struct', 'data.sample');
  246. public static function AddModule($sFilePath, $sId, $aArgs)
  247. {
  248. foreach (self::$m_aModuleArgs as $sArgName => $sArgDesc)
  249. {
  250. if (!array_key_exists($sArgName, $aArgs))
  251. {
  252. throw new Exception("Module '$sId': missing argument '$sArgName'");
  253. }
  254. }
  255. self::$m_aModules[$sId] = $aArgs;
  256. $sDirPart = dirname($sFilePath).'/';
  257. foreach(self::$m_aFilesList as $sAttribute)
  258. {
  259. // All the items below are list of files, that are relative to the current file
  260. // being loaded, let's update their path to store a full (absolute) path in the config
  261. foreach(self::$m_aModules[$sId][$sAttribute] as $idx => $sRelativePath)
  262. {
  263. self::$m_aModules[$sId][$sAttribute][$idx] = $sDirPart.$sRelativePath;
  264. }
  265. }
  266. }
  267. public static function GetModules()
  268. {
  269. return self::$m_aModules;
  270. }
  271. } // End of class
  272. ?>