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