Mailer project rwritten:
[mailer.git] / inc / ajax / ajax_installer.php
1 <?php
2 /************************************************************************
3  * Mailer v0.2.1-FINAL                                Start: 06/24/2012 *
4  * ===================                          Last change: 06/24/2012 *
5  *                                                                      *
6  * -------------------------------------------------------------------- *
7  * File              : ajax_installer.php                               *
8  * -------------------------------------------------------------------- *
9  * Short description : AJAX-related functions for installer             *
10  * -------------------------------------------------------------------- *
11  * Kurzbeschreibung  : AJAX-bezogene Funktionen fuer Installer          *
12  * -------------------------------------------------------------------- *
13  * $Revision::                                                        $ *
14  * $Date::                                                            $ *
15  * $Tag:: 0.2.1-FINAL                                                 $ *
16  * $Author::                                                          $ *
17  * -------------------------------------------------------------------- *
18  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
19  * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
20  * For more information visit: http://mxchange.org                      *
21  *                                                                      *
22  * This program is free software; you can redistribute it and/or modify *
23  * it under the terms of the GNU General Public License as published by *
24  * the Free Software Foundation; either version 2 of the License, or    *
25  * (at your option) any later version.                                  *
26  *                                                                      *
27  * This program is distributed in the hope that it will be useful,      *
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
30  * GNU General Public License for more details.                         *
31  *                                                                      *
32  * You should have received a copy of the GNU General Public License    *
33  * along with this program; if not, write to the Free Software          *
34  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,               *
35  * MA  02110-1301  USA                                                  *
36  ************************************************************************/
37
38 // Some security stuff...
39 if ((!defined('__SECURITY')) || (!isAjaxOutputMode()) || (!isInstallationPhase())) {
40         header('HTTP/1.1 403 Forbidden');
41         die(json_encode(array('reply_content' => 'Access forbidden'), JSON_FORCE_OBJECT));
42 } // END - if
43
44 //-----------------------------------------------------------------------------
45 //         Generic call-back functions, they all rely on session data
46 //-----------------------------------------------------------------------------
47
48 // Establish a database link
49 function establishAjaxInstallerDatabaseLink () {
50         // This requires some session data
51         if (!isSessionDataSet(array('mysql_host', 'mysql_dbase', 'mysql_prefix', 'mysql_login', 'mysql_password1', 'mysql_password2', 'mysql_engine'))) {
52                 // Some required session data is not set
53                 reportBug(__FUNCTION__, __LINE__, 'Required session data for this step not found.');
54         } // END - if
55
56         // Remove any previous flag
57         unsetSqlLinkUp(__FUNCTION__, __LINE__);
58
59         // Establish link
60         $linkResource = SQL_CONNECT(getSession('mysql_host'), getSession('mysql_login'), getSession('mysql_password1'), __FUNCTION__, __LINE__);
61
62         // Is this a link resource?
63         if (!is_resource($linkResource)) {
64                 // Is not a resource
65                 reportBug(__FUNCTION__, __LINE__, 'linkResource[]=' . gettype($linkResource) . ', expected: link resource');
66         } // END - if
67
68         // Does selecting the database work?
69         if (!SQL_SELECT_DB(getSession('mysql_dbase'), __FUNCTION__, __LINE__)) {
70                 // Could not be selected
71                 reportBug(__FUNCTION__, __LINE__, 'Could not select database ' . getSession('mysql_dbase'));
72         } elseif ((!isFileReadable(getSession('base_path') . 'install/tables.sql')) || (!isFileReadable(getSession('base_path') . 'install/menu-'.getLanguage().'.sql'))) {
73                 // Installation area not found
74                 reportBug(__FUNCTION__, __LINE__, 'SQL dumps not found. Please extract ALL files from the archive or checkout all files out from SVN.');
75         } elseif (ifFatalErrorsDetected()) {
76                 // Some other fatal error occured
77                 reportBug(__FUNCTION__, __LINE__, 'Some fatal error detected, please check debug.log for details.');
78         } // END - if
79
80         // Set type, prefix from POST data and database name for later queries
81         setConfigEntry('_TABLE_TYPE'  , getSession('mysql_engine'));
82         setConfigEntry('_MYSQL_PREFIX', getSession('mysql_prefix'));
83         setConfigEntry('__DB_NAME'    , getSession('mysql_dbase'));
84 }
85
86 //-----------------------------------------------------------------------------
87 //             Call-back functions for processing AJAX requests
88 //-----------------------------------------------------------------------------
89
90 // Processes AJAX requests for installer
91 function doAjaxProcessInstall () {
92         // 'do' must always be set and installation phase must be true
93         if (!isInstallationPhase()) {
94                 // This shall not happen
95                 reportBug(__FUNCTION__, __LINE__, 'This AJAX request handler was called outside the installer.');
96         } elseif (!isPostRequestElementSet('do')) {
97                 // This shall not happen
98                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "do" which is fatal.');
99         } // END - if
100
101         // Notify all modules that we are installing
102         $GLOBALS['__mailer_installing'] = TRUE;
103
104         // Again we do a call-back, so generate a function name depending on 'do'
105         $callbackName = 'doAjaxInstaller' . capitalizeUnderscoreString(postRequestElement('do'));
106
107         // Is the call-back function there?
108         if (!function_exists($callbackName)) {
109                 // This shall not happen
110                 reportBug(__FUNCTION__, __LINE__, 'AJAX call-back ' . $callbackName . ' does not exist.');
111         } // END - if
112
113         // Call the function
114         call_user_func($callbackName);
115
116         // Is the status fine or template not found (404)?
117         sendAjaxContent();
118 }
119
120 // Processes installer request for testing
121 function doAjaxInstallerTest () {
122         // Load the "test passed" template
123         setAjaxReplyContent(loadTemplate('ajax_test_passed', TRUE));
124
125         // All okay if we reach this point
126         setHttpStatus('200 OK');
127 }
128
129 // Processes installer requests for footer navigation
130 function doAjaxInstallerFooterNavigation () {
131         // 'tab' must always be set to determine which navigation buttons shall be visible
132         if (!isPostRequestElementSet('tab')) {
133                 // This shall not happen
134                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "tab" which is fatal.');
135         } // END - if
136
137         // Init array for footer navigation
138         $enabledNavigations = array();
139
140         // "Detect" the 'tab' value
141         switch (postRequestElement('tab')) {
142                 case 'base_data': // Also 'previous' is valid
143                 case 'database_config':
144                 case 'smtp_config':
145                 case 'other_config':
146                 case 'extensions':
147                         array_push($enabledNavigations, 'previous');
148                 case 'welcome': // Only 'next' works for welcome page
149                         array_push($enabledNavigations, 'next');
150                         break;
151
152                 case 'overview': // Enable only 'previous'
153                         array_push($enabledNavigations, 'previous');
154                         if (isInstallationDataCompleted()) {
155                                 // Add 'finish'
156                                 array_push($enabledNavigations, 'finish');
157                         } // END - if
158                         break;
159
160                 default: // Unsupported value
161                         // This shall not happen
162                         reportBug(__FUNCTION__, __LINE__, 'Unsupported "tab" value ' . postRequestElement('tab') . ' detected.');
163
164                         // This will never be reached
165                         break;
166         } // END - switch
167
168         // Output the array for JSON reply
169         setAjaxReplyContent(encodeJson($enabledNavigations));
170
171         // All okay if we reach this point
172         setHttpStatus('200 OK');
173 }
174
175 // Processes installer AJAX calls for content-requests
176 function doAjaxInstallerDoStep () {
177         // 'step' must be there
178         if (!isPostRequestElementSet('step')) {
179                 // This shall not happen
180                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "step" which is fatal.');
181         } // END - if
182
183         // Construct call-back name
184         $callbackName = 'doAjaxInstallerStep' . capitalizeUnderscoreString(postRequestElement('step'));
185
186         // Is the function there?
187         if (function_exists($callbackName)) {
188                 // Call it for setting values in session
189                 call_user_func($callbackName);
190         } else {
191                 // Log missing functions
192                 reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' does not exist.');
193         }
194
195         // Set dummy content
196         setAjaxReplyContent(encodeJson(postRequestElement('step').'=OK'));
197
198         // All okay if we reach this point
199         setHttpStatus('200 OK');
200 }
201
202 // Processes installer AJAX calls for content-requests
203 function doAjaxInstallerRequestContent () {
204         // 'tab' must be there
205         if (!isPostRequestElementSet('tab')) {
206                 // This shall not happen
207                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "tab" which is fatal.');
208         } // END - if
209
210         // Construct call-back name for value-preset
211         $callbackName = 'doAjaxPrepareInstaller' . capitalizeUnderscoreString(postRequestElement('tab'));
212
213         // Is the function there?
214         if (function_exists($callbackName)) {
215                 // Call it for setting values in session
216                 call_user_func($callbackName);
217         } else {
218                 // Log missing functions
219                 reportBug(__FUNCTION__, __LINE__, 'Call-back function ' . $callbackName . ' does not exist.');
220         }
221
222         // Is the HTTP status still the same? (204 No Content)
223         if (getHttpStatus() == '204 No Content') {
224                 // We use the current access level 'install' as prefix and construct a template name
225                 setAjaxReplyContent(loadTemplate('install_page_' . trim(postRequestElement('tab')), TRUE));
226
227                 // Has the template been loaded?
228                 if (isset($GLOBALS['template_content']['html']['install_page_' . trim(postRequestElement('tab'))])) {
229                         // All okay if we reach this point
230                         setHttpStatus('200 OK');
231                 } else {
232                         // Set 404 error
233                         setHttpStatus('404 Not Found');
234                 }
235         } // END - if
236 }
237
238 // Process installer AJAX call for change-warning
239 function doAjaxInstallerChangeWarning () {
240         // 'elements' and 'button' must be there
241         if ((!isPostRequestElementSet('elements')) || (!isPostRequestElementSet('button'))) {
242                 // This shall not happen
243                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "elements" and/or "button" which is fatal.');
244         } // END - if
245
246         // "Walk" through all elements
247         $OUT = '<ol>';
248         foreach (explode(':', postRequestElement('elements')) as $element) {
249                 // Is it an extension?
250                 if (substr($element, 0, 4) == 'ext_') {
251                         // Add row for extension
252                         $OUT .= '<li>{%message,INSTALLER_CHANGED_ELEMENT_EXTENSION=' . str_replace('_', '-', $element) . '%}</li>';
253                 } else {
254                         // Add generic row
255                         $OUT .= '<li>{--INSTALLER_CHANGED_ELEMENT_' . strtoupper($element) . '--}</li>';
256                 }
257         } // END - foreach
258         $OUT .= '</ol>';
259
260         // Prepare content
261         $content = array(
262                 'out'     => $OUT,
263                 'button'  => postRequestElement('button'),
264                 'message' => '{--INSTALLER_TAB_NAVIGATION_' . strtoupper(postRequestElement('button')) . '_LINK--}',
265         );
266
267         if (in_array(postRequestElement('button'), array('previous', 'next'))) {
268                 // Load 'prefixed' template
269                 setAjaxReplyContent(loadTemplate('install_warning_' . postRequestElement('button'), TRUE, $content));
270         } else {
271                 // Load 'tab' template
272                 setAjaxReplyContent(loadTemplate('install_warning_tab', TRUE, $content));
273         }
274
275         // All okay if we reach this point
276         setHttpStatus('200 OK');
277 }
278
279 // Process installer AJAC call for saving changes
280 function doAjaxInstallerSaveChanges () {
281         // 'tab' must always be set to create a post-check-callback
282         if (!isPostRequestElementSet('tab')) {
283                 // This shall not happen
284                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "tab" which is fatal.');
285         } // END - if
286
287         // Save the tab for pre-"filtering"
288         $currentTab = postRequestElement('tab');
289
290         // Remove some elements which should not be saved
291         foreach (array('tab', 'do', 'level') as $removedElement) {
292                 // Remove this element from POST data
293                 unsetPostRequestElement($removedElement);
294         } // END - foreach
295
296         // Default is failed save attempt (e.g. nothing to save)
297         $saveStatus = array(
298                 'status'        => 'failed',
299                 'message'       => '{--INSTALLER_SAVE_CHANGES_FAILED--}',
300                 // Don't set this to false, or else it will be returned as 'failed' but is saved
301                 'is_saved'      => TRUE,
302                 'failed_fields' => array()
303         );
304
305         // Init overall status
306         $isAllSaved = TRUE;
307
308         // Now set all remaining data in session
309         foreach (postRequestArray() as $key => $value) {
310                 // Set it, if it is valid, else it will be added to $saveStatus (call-by-reference)
311                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value[' . gettype($value) . '=' . $value);
312                 $saveStatus['is_saved'] = (
313                         // Is the data valid?
314                         (isInstallerDataValid($saveStatus, $key, $value))
315                 &&
316                         // And can it be stored in session?
317                         (setSession($key, $value))
318                 );
319
320                 // Save the overall status for below final check
321                 $isAllSaved = (($isAllSaved === TRUE) && ($saveStatus['is_saved'] === TRUE));
322                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value[' . gettype($value) . '=' . $value . ',is_saved=' . intval($saveStatus['is_saved']) . ',isAllSaved=' . intval($isAllSaved));
323         } // END - foreach
324
325         // 'is_saved' is still true?
326         if ($isAllSaved === TRUE) {
327                 // Set 'done' and message
328                 $saveStatus['status']  = 'done';
329                 $saveStatus['message'] = '{--INSTALLER_SAVE_CHANGES_DONE--}';
330
331                 // Then do the post-check
332                 doInstallerPostCheck($currentTab, $saveStatus);
333         } // END - if
334
335         // Output the status array for JSON reply
336         setAjaxReplyContent(encodeJson($saveStatus));
337
338         // All okay if we reach this point
339         setHttpStatus('200 OK');
340 }
341
342 // ----------------------------------------------------------------------------
343 //          Call-back functions for preparing installer page requests
344 // ----------------------------------------------------------------------------
345
346 // Prepare AJAX request 'welcome'
347 function doAjaxPrepareInstallerWelcome () {
348         // Kept empty to prevent logfile entry
349 }
350
351 // Prepare AJAX request 'base_data'
352 function doAjaxPrepareInstallerBaseData () {
353         // Is 'base_path' not set?
354         if (!isSessionVariableSet('base_path')) {
355                 // Then set it from PATH
356                 setSession('base_path', getPath());
357         } // END - if
358
359         // Is 'base_url' not set?
360         if (!isSessionVariableSet('base_url')) {
361                 // Then set it from URL
362                 setSession('base_url', getUrl());
363         } // END - if
364
365         // Is 'main_title' not set?
366         if (!isSessionVariableSet('main_title')) {
367                 // Then set it from default main title
368                 setSession('main_title', '{--DEFAULT_MAIN_TITLE--}');
369         } // END - if
370
371         // Is 'slogan' not set?
372         if (!isSessionVariableSet('slogan')) {
373                 // Then set it from default slogan
374                 setSession('slogan', '{--DEFAULT_SLOGAN--}');
375         } // END - if
376
377         // Is 'webmaster' not set?
378         if (!isSessionVariableSet('webmaster')) {
379                 // Then set it from default webmaster email address
380                 setSession('webmaster', '{--DEFAULT_WEBMASTER--}');
381         } // END - if
382 }
383
384 // Prepare AJAX request 'database_config'
385 function doAjaxPrepareInstallerDatabaseConfig () {
386         // Is 'mysql_host' not set?
387         if (!isSessionVariableSet('mysql_host')) {
388                 // Then set it directly
389                 setSession('mysql_host', 'localhost');
390         } // END - if
391
392         // Is 'mysql_dbase' not set?
393         if (!isSessionVariableSet('mysql_dbase')) {
394                 // Then set it directly
395                 setSession('mysql_dbase', 'your_database');
396         } // END - if
397
398         // Is 'mysql_prefix' not set?
399         if (!isSessionVariableSet('mysql_prefix')) {
400                 // Then set it directly
401                 setSession('mysql_prefix', 'mailer');
402         } // END - if
403
404         // Is 'mysql_login' not set?
405         if (!isSessionVariableSet('mysql_login')) {
406                 // Then set it directly
407                 setSession('mysql_login', 'your_login');
408         } // END - if
409
410         // Is 'mysql_dbase' not set?
411         if (!isSessionVariableSet('mysql_password1')) {
412                 // Then set it directly
413                 setSession('mysql_password1', '');
414         } // END - if
415
416         // Is 'mysql_password2' not set?
417         if (!isSessionVariableSet('mysql_password2')) {
418                 // Then set it directly
419                 setSession('mysql_password2', '');
420         } // END - if
421
422         // Is 'mysql_engine' not set?
423         if (!isSessionVariableSet('mysql_engine')) {
424                 // Then set it directly
425                 setSession('mysql_engine', 'MyISAM');
426         } // END - if
427 }
428
429 // Prepare AJAX request 'smtp_config'
430 function doAjaxPrepareInstallerSmtpConfig () {
431         // Kept empty to prevent logfile entry because SMTP settings are optional
432 }
433
434 // Prepare AJAX request 'other_config'
435 function doAjaxPrepareInstallerOtherConfig () {
436         // Is 'output_mode' not set?
437         if (!isSessionVariableSet('output_mode')) {
438                 // Then set it directly
439                 setSession('output_mode', 'render');
440         } // END - if
441
442         // Is 'warn_no_pass' not set?
443         if (!isSessionVariableSet('warn_no_pass')) {
444                 // Then set it directly
445                 setSession('warn_no_pass', 'Y');
446         } // END - if
447
448         // Is 'write_footer' not set?
449         if (!isSessionVariableSet('write_footer')) {
450                 // Then set it directly
451                 setSession('write_footer', 'Y');
452         } // END - if
453
454         // Is 'enable_backlink' not set?
455         if (!isSessionVariableSet('enable_backlink')) {
456                 // Then set it directly
457                 setSession('enable_backlink', 'Y');
458         } // END - if
459 }
460
461 // Prepare AJAX request 'extensions'
462 function doAjaxPrepareInstallerExtensions () {
463         // Is 'extensions' set?
464         if (!isSessionVariableSet('extensions')) {
465                 /*
466                  * At least ext-sql_patches and ext-task should be installed
467                  *(ext-sql_patches is a must!)
468                  */
469                 setSession('extensions', 'admins:sql_patches:task');
470         } elseif (strpos(getSession('extensions'), 'sql_patches') === FALSE) {
471                 // Add missing ext-sql_patches
472                 setSession('extensions', getSession('extensions') . ':sql_patches');
473         }
474 }
475
476 // Prepare AJAX request 'overview'
477 function doAjaxPrepareInstallerOverview () {
478         // 'tab' must always be set to create a post-check-callback
479         if (!isPostRequestElementSet('tab')) {
480                 // This shall not happen
481                 reportBug(__FUNCTION__, __LINE__, 'The JavaScript did not send "tab" which is fatal.');
482         } // END - if
483
484         // Save the tab for pre-"filtering"
485         $currentTab = postRequestElement('tab');
486
487         // Default is failed save attempt (e.g. nothing to save)
488         $verificationStatus = array(
489                 // Status code, can be 'failed' or 'done'
490                 'status'        => 'failed',
491                 // Status message (e.g. for output)
492                 'message'       => '{--INSTALLER_OVERVIEW_FINAL_CHECK_FAILED--}',
493                 // Don't set this to false, or else it will be returned as 'failed' but is saved
494                 'is_valid'      => TRUE,
495                 // Failed fields
496                 'failed_fields' => array()
497         );
498
499         // Init overall status and final output
500         $isAllValid = TRUE;
501         $output     = '';
502
503         // Check all data in session
504         foreach (array_keys($GLOBALS['installer_groups']) as $key) {
505                 // Get values from session
506                 $value = getSession($key);
507
508                 // Is the data valid?
509                 $verificationStatus['is_valid'] = (isInstallerDataValid($verificationStatus, $key, $value));
510
511                 // Is this step okay?
512                 if ($verificationStatus['is_valid'] === TRUE) {
513                         // Add this key/value pair to a overview group
514                         addKeyValueToInstallerOverviewGroup($key, $value);
515                 } // END - if
516
517                 // Save the overall status for below final check
518                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',is_valid=' . intval($verificationStatus['is_valid']) . ',isAllValid=' . intval($isAllValid));
519                 $isAllValid = (($isAllValid === TRUE) && ($verificationStatus['is_valid'] === TRUE));
520         } // END - foreach
521
522         // Is it still true?
523         if ((isInstallationDataCompleted()) && ($isAllValid === TRUE)) {
524                 // Set 'done' and message
525                 $verificationStatus['status']  = 'done';
526                 $verificationStatus['message'] = '{--INSTALLER_OVERVIEW_FINAL_CHECK_DONE--}';
527
528                 // Then do the post-check
529                 doInstallerPostCheck($currentTab, $verificationStatus);
530         } // END - if
531
532         // Is it still valid?
533         if ($verificationStatus['status'] != 'done') {
534                 // Log message away
535                 //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Final check on all stored data failed. message=' . $verificationStatus['message']);
536
537                 // Process failed fields
538                 $verificationStatus['failed_fields'] = handleInstallerFailedFields($verificationStatus['failed_fields']);
539
540                 // Output the array for JSON reply
541                 setAjaxReplyContent(loadTemplate('install_overview_failed', TRUE, $verificationStatus));
542
543                 /*
544                  * Something went wrong, this might happen when e.g. the user has tried
545                  * to save invalid database login data but hit reload button on error
546                  * message.
547                  */
548                 setHttpStatus('200 OK');
549
550                 // Abort here
551                 return;
552         } // END - if
553 }
554
555 // ----------------------------------------------------------------------------
556 //            Call-back functions for doing installation steps
557 // ----------------------------------------------------------------------------
558
559 // Call-back function to import first tables.sql file
560 function doAjaxInstallerStepImportTablesSql () {
561         // Establish database link
562         establishAjaxInstallerDatabaseLink();
563
564         // Init SQL array
565         initSqls();
566
567         // Import tables.sql
568         importInstallSqlDump('tables');
569
570         // Are some SQLs found?
571         if (countSqls() == 0) {
572                 // Abort here
573                 reportBug(__FUNCTION__, __LINE__, '{--INSTALLER_SQL_IMPORT_FAILED--}');
574         } // END - if
575
576         // Now run all queries through
577         runFilterChain('run_sqls');
578
579         // Close SQL link
580         SQL_CLOSE(__FUNCTION__, __LINE__);
581 }
582
583 // Call-back function to import menu SQL file
584 function doAjaxInstallerStepImportMenuSql () {
585         // Establish database link
586         establishAjaxInstallerDatabaseLink();
587
588         // Init SQL array
589         initSqls();
590
591         // Import tables.sql
592         importInstallSqlDump('menu-' . getLanguage());
593
594         // Are some SQLs found?
595         if (countSqls() == 0) {
596                 // Abort here
597                 reportBug(__FUNCTION__, __LINE__, '{--INSTALLER_SQL_IMPORT_FAILED--}');
598         } // END - if
599
600         // Now run all queries through
601         runFilterChain('run_sqls');
602
603         // Close SQL link
604         SQL_CLOSE(__FUNCTION__, __LINE__);
605 }
606
607 // Call-back function to install some important extensions
608 function doAjaxInstallerStepInstallExtensions () {
609         // Only one element is required
610         if (!isSessionVariableSet('extensions')) {
611                 // Some required session data is not set
612                 reportBug(__FUNCTION__, __LINE__, 'Required session data for this step not found.');
613         } // END - if
614
615         // Establish database link
616         establishAjaxInstallerDatabaseLink();
617
618         // Get all extensions
619         $extensions = explode(':', getSession('extensions'));
620
621         // Make sure ext-sql_patches is first
622         array_unshift($extensions, 'sql_patches');
623
624         // "Walk" through all extensions
625         foreach ($extensions as $key => $ext_name) {
626                 // Is ext-sql_patches not at key=0?
627                 if (($key == 0) && ($ext_name == 'sql_patches')) {
628                         // Then skip this entry
629                         continue;
630                 } elseif ((!loadExtension($ext_name, 'test', '0.0.0', TRUE)) || (!registerExtension($ext_name, NULL))) {
631                         // Didn't work
632                         reportBug(__FUNCTION__, __LINE__, 'Cannot load/register extension ' . $ext_name . '.');
633                 } // END - if
634         } // END - foreach
635 }
636
637 // Call-back function to write local configuration file
638 function doAjaxInstallerStepWriteLocalConfig () {
639         // Is all set?
640         if (!isSessionDataSet(array('base_path', 'base_url', 'main_title', 'slogan', 'webmaster', 'mysql_host', 'mysql_dbase', 'mysql_prefix', 'mysql_login', 'mysql_password1', 'mysql_password2', 'mysql_engine', 'output_mode', 'warn_no_pass', 'write_footer', 'enable_backlink'))) {
641                 // Some required session data is not set
642                 reportBug(__FUNCTION__, __LINE__, 'Required session data for this step not found.');
643         } // END - if
644
645         // Write config file
646         if (!doInstallWriteLocalConfigurationFile(
647                 getSession('base_path'),
648                 getSession('base_url'),
649                 getSession('main_title'),
650                 getSession('slogan'),
651                 getSession('webmaster'),
652                 getSession('warn_no_pass'),
653                 getSession('write_footer'),
654                 getSession('enable_backlink'),
655                 getSession('mysql_host'),
656                 getSession('mysql_dbase'),
657                 getSession('mysql_login'),
658                 getSession('mysql_password1'),
659                 getSession('mysql_prefix'),
660                 getSession('mysql_engine'),
661                 getSession('smtp_host'),
662                 getSession('smtp_user'),
663                 getSession('smtp_password1')
664         )) {
665                 // Something bad went wrong
666                 removeFile(getSession('base_path') . getCachePath() . 'config-local.php');
667                 reportBug(__FUNCTION__, __LINE__, 'Did not fully write config-local.php .');
668         }
669 }
670
671 // [EOF]
672 ?>