ultimix

- Main Page
- Data Structures
- Files
- Examples

- File List
- Globals

install.php
Go to the documentation of this file.
1 <?php
2
3 /*
4 * This source code is a part of the Ultimix Project.
5 * It is distributed under BSD licence. All other third side source code (like tinyMCE) is distributed under
6 * it's own licence wich could be found from the corresponding files or sources.
7 * This source code is provided "as is" without any warranties or garanties.
8 *
9 * Have a nice day!
10 *
11 * @url http://ultimix.sorceforge.net
12 *
13 * @author Alexey "gdever" Dodonov
14 */
15
16 require_once( './packages/core/core.php' );
17 require_once( './include/php/startup.php' );
18
19 @unlink( './packages/cache/data/cache' );
20 @unlink( './packages/cache/data/table' );
21
32 function install_step_1()
33 {
34 $CachedFS = get_package( 'cached_fs' );
35 $Page = $CachedFS->file_get_contents( "./install/res/templates/install_template_1.tpl" );
36 print( $Page );
37 exit( 0 );
38 }
39
54 function handle_connection_error( $Silent )
55 {
56 if( $Silent === false )
57 {
58 $CachedFS = get_package( 'cached_fs' );
59 $Page = $CachedFS->file_get_contents( "./install/res/templates/install_template_2.tpl" );
60 $Page = str_replace( '{error_message}' , 'An error occured while database connection' , $Page );
61
62 $Security = get_package( 'security' );
63
64 $PlaceHolders = array( '{host}' , '{database}' , '{prefix}' , '{user}' , '{password}' );
65 $Data = array(
66 $Security->get_gp( 'host' , 'string' , '' ) , $Security->get_gp( 'database' , 'string' , '' ) ,
67 $Security->get_gp( 'prefix' , 'string' , '' ) , $Security->get_gp( 'user' , 'string' , '' ) ,
68 $Security->get_gp( 'password' , 'string' , '' )
69 );
70 $Page = str_replace( $PlaceHolders , $Data , $Page );
71
72 print( $Page );
73 exit( 0 );
74 }
75 }
76
111 function handle_step_2( $Host , $Database , $Prefix , $User , $Password , $Silent = false )
112 {
113 $DatabaseAlgorithms = get_package( 'database::database_algorithms' , 'last' , __FILE__ );
114 $CachedFS = get_package( 'cached_fs' );
115 $CachedFS->file_put_contents(
116 "packages/_core_data/conf/cf_mysql_database" , "$Host#$User#$Password#$Database#$Prefix"
117 );
118
119 if( $DatabaseAlgorithms->try_connect() )
120 {
121 $DBScript = file_get_contents( './install/sql/data.sql' , 'cleaned' );
122 $DBScript = str_replace( '{prefix}' , $Prefix , $DBScript );
123 $DatabaseAlgorithms->execute_query_set( $DBScript );
124 if( $Silent === false )
125 {
126 header( 'Location: ./install.php?page=3' );
127 exit( 0 );
128 }
129 }
130 else
131 {
132 handle_connection_error( $Silent );
133 }
134 }
135
146 function show_step_2_form()
147 {
148 $CachedFS = get_package( 'cached_fs' );
149 $Page = $CachedFS->file_get_contents( "./install/res/templates/install_template_2.tpl" );
150
151 $Needles = array( '{host}' , '{user}' , '{password}' , '{database}' , '{prefix}' , '{error_message}' );
152
153 $Config = $CachedFS->file_get_contents( "packages/_core_data/conf/cf_mysql_database" );
154 $Replacements = array_merge( explode( '#' , $Config ) , array( '' ) );
155
156 print( str_replace( $Needles , $Replacements , $Page ) );
157 exit( 0 );
158 }
159
174 function install_step_2( $Silent = false )
175 {
176 $Security = get_package( 'security' );
177
178 if( $Security->get_gp( 'setup_db' ) )
179 {
180 handle_step_2(
181 $Security->get_gp( 'host' , 'string' , '' ) , $Security->get_gp( 'database' , 'string' , '' ) ,
182 $Security->get_gp( 'prefix' , 'string' , '' ) , $Security->get_gp( 'user' , 'string' , '' ) ,
183 $Security->get_gp( 'password' , 'string' , '' ) , $Silent
184 );
185 }
186 else
187 {
188 show_step_2_form();
189 }
190 }
191
210 function handle_step_3( $HttpHost , $Silent = false )
211 {
212 $HttpHost = rtrim( $HttpHost , '/\\' );
213 $HtAccess = file_get_contents( './install/res/templates/tpl.htaccess' );
214 $HtAccess = str_replace( '{http_host}' , $HttpHost , $HtAccess );
215 file_put_contents( '.htaccess' , $HtAccess );
216
217 file_put_contents(
218 './packages/_core_data/conf/cf_settings' , "HTTP_HOST=$HttpHost\r\nGZIP_TRAFFIC=false"
219 );
220
221 if( $Silent === false )
222 {
223 header( 'Location: ./install.php?page=4' );
224 exit( 0 );
225 }
226 }
227
246 function install_step_3( $HttpHost , $Silent = false )
247 {
248 $CachedFS = get_package( 'cached_fs' );
249 $Security = get_package( 'security' );
250
251 if( $HttpHost === false )
252 {
253 if( $Silent === false )
254 {
255 $Page = $CachedFS->file_get_contents( "./install/res/templates/install_template_3.tpl" );
256 $Page = str_replace(
257 '{http_root}' ,
258 rtrim( 'http://'.$_SERVER[ 'SERVER_NAME' ].dirname( $_SERVER[ 'REQUEST_URI' ] ) , '/\\' ) ,
259 $Page
260 );
261 print( $Page );
262 exit( 0 );
263 }
264 }
265 else
266 {
267 handle_step_3( $HttpHost , $Silent );
268 }
269 }
270
281 function install_step_4()
282 {
283 $CachedFS = get_package( 'cached_fs' );
284 $Page = $CachedFS->file_get_contents( "./install/res/templates/install_template_4.tpl" );
285 print( $Page );
286 exit( 0 );
287 }
288
307 function handle_installation_steps()
308 {
309 $Security = get_package( 'security' );
310 $Page = $Security->get_gp( 'page' , 'integer' , 1 );
311
312 switch( $Page )
313 {
314 case( 1 ):install_step_1();
315
316 case( 2 ):install_step_2( false );
317
318 case( 3 ):
319 install_step_3( $Security->get_gp( 'http_root' , 'string' , false ) , false );
320 break;
321
322 case( 4 ):install_step_4();
323 }
324 }
325
336 function run_installation_wizard()
337 {
338 try
339 {
340 if( isset( $_GET[ 'auto_install' ] ) === true )
341 {
342 $DBS = file_get_contents( './install/conf/cf_db_settings' );
343 $DBS = explode( '#' , $DBS );
344
345 install_step_2( $DBS[ 0 ] , $DBS[ 1 ] , $DBS[ 2 ] , $DBS[ 3 ] , $DBS[ 4 ] , true );
346
347 $HttpHost = rtrim( 'http://'.$_SERVER[ 'SERVER_NAME' ].dirname( $_SERVER[ 'REQUEST_URI' ] ) , '/\\' );
348 install_step_3( $HttpHost , true );
349 }
350 else
351 {
352 handle_installation_steps();
353 }
354 }
355 catch( Exception $e )
356 {
357 handle_script_error( true , $e );
358 }
359 }
360
361 /* running wizard */
362 run_installation_wizard();
363 ?>