File: /home/centralexf/www/installation0/js/install.js
/**
* This code runs at page load
*/
$(document).ready(function() {
//addAccordion();
});
var abi_current_tmp = '';
var abi_current_log = '';
var abi_default_tmp = '';
var abi_default_log = '';
/**
* Adds the accordion effect
*/
function addAccordion()
{
$("#accordion").accordion({
header: 'h3'
});
}
/**
* Controls whether the Restoration Progress Dialog can be closed.
* It's only set to true when the restoration finishes normally or
* with an error.
*/
var canCloseDialog = false;
/**
* When it's true, the database dialogs auto-close
*/
var hasAutomation = false;
function parseResponse(msg)
{
var response = new Object;
response.status = true;
var junk = null;
var message = "";
// Get rid of junk before the data
var valid_pos = msg.indexOf('###<?xml');
if( valid_pos == -1 ) {
response.status = false;
response.error = 'Invalid AJAX data: ' + msg;
} else if( valid_pos != 0 ) {
// Data is prefixed with junk
response.junk = msg.substr(0, valid_pos);
message = msg.substr(valid_pos);
}
else
{
message = msg;
}
message = message.substr(3); // Remove triple hash in the beginning
// Get of rid of junk after the data
var valid_pos = message.lastIndexOf('###');
message = message.substr(0, valid_pos); // Remove triple hash in the end
// Is there more junk added after the </restoredata> and befere the triple hash?
// This is used to prune forced analytics
var valid_pos = message.lastIndexOf('</restoredata>');
var last_pos = valid_pos + 14;
if( last_pos < message.length )
{
message = message.substr(0, last_pos);
}
response.message = message;
if(response.status && ($.browser.msie) )
{
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(message);
response.message = xml;
}
return response;
}
/**
* Hijacks the click event of the Next button for use in the DB
* restoration page
*/
function hijackDBNext()
{
// Hijack Next button's click
$('#nextButton').click(dbnext_click);
// Setup progress dialog display
$("#dialog").dialog({
autoOpen: false,
closeOnEscape: false,
height: 200,
width: 600,
hide: 'slide',
modal: true,
position: 'center',
show: 'slide',
beforeclose: function(event, ui) {
return canCloseDialog;
}
});
// Create a progress bar
$("#progressbar").progressbar({
value: 0
});
$('#dberrorhelp').css('display','none');
// Handle warning dialog
$("#warndialog").dialog({
autoOpen: false,
closeOnEscape: false,
height: 300,
width: 600,
hide: 'slide',
modal: true,
position: 'center',
show: 'slide'
});
}
/**
* Callback function for the click event of the Next button in the
* DB restoration page
* @param event
* @return
*/
function dbnext_click(event)
{
event.preventDefault(); // Prevent default click handling
// Open a dialog box to render the progress
$('#progresstext').removeClass("error");
$('#progresstext').html('');
$('#progressbar').show();
$('#dberrorhelp').css('display','none');
$('#dialog').dialog('option', 'buttons', '');
$('#dialog').dialog('open');
// Run the restoration using jQuery-powered AJAX
stepThroughRestoration();
// Next click will not call this callback again
$('#nextButton').unbind('click', dbnext_click);
}
/**
* Callback function for the click event of the Delete link in the
* final page
* @param event
* @return
*/
function deleteself_click(event)
{
event.preventDefault(); // Prevent default click handling
// Open a dialog box to render the progress
$('#errortext').hide();
$('#oktext').hide();
$('#waittext').show();
$('#dialog2').dialog('option', 'buttons', '');
$('#dialog2').dialog('open');
$.ajax({
method: 'get',
url: 'index.php',
cache: false,
data: {
task: 'ajax',
act: 'deleteself'
},
dataType: 'text',
timeout: 120000,
success: function(datext, textStatus)
{
var response = parseResponse(datext);
if(!response.status)
{
// An AJAX error occured. Show the error message
$('#errortext').show();
$('#oktext').hide();
$('#waittext').hide();
$('#errortext').html('');
$('#errortext').append('<p><strong>AJAX error</strong>:<br/>');
$('#errortext').append('<tt>'+response.error+'</tt></p>');
$('#errortext').addClass("error");
canCloseDialog = true;
$('#dialog2').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog2').dialog('option', 'closeOnEscape', true);
}
else
{
var daxml = response.message;
}
var error = $('error', daxml).text();
if(error == '')
{
// Show "done" message
$('#errortext').hide();
$('#oktext').show();
$('#waittext').hide();
// Show an OK button which shuts down the window
$('#dialog2').dialog('option', 'buttons', {
"OK": function() {
$(this).dialog("close");
window.location = '../index.php';
}
});
}
else
{
// An error has occured. Show the message.
$('#errortext').show();
$('#oktext').hide();
$('#waittext').hide();
$('#errortext').html(error);
$('#errortext').show();
canCloseDialog = true;
$('#dialog2').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog2').dialog('option', 'closeOnEscape', true);
}
},
error: function(XHR, textStatus, errorThrown){
// An AJAX error occured. Show the error message
$('#errortext').show();
$('#oktext').hide();
$('#waittext').hide();
$('#errortext').html('');
$('#errortext').append('<p><strong>AJAX error</strong>:<br/>');
$('#errortext').append('<tt>'+textStatus+'</tt>('+errorThrown+')</p>');
$('#errortext').append('<p><strong>Raw Data</strong>:<pre>'+htmlentities(XHR.responseText)+'</pre></p>');
$('#errortext').addClass("error");
canCloseDialog = true;
$('#dialog2').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog2').dialog('option', 'closeOnEscape', true);
}
});
return false;
}
/**
* Automatically progresses through the restoration steps, using jQuery-powered
* AJAX calls.
*/
function stepThroughRestoration()
{
$.ajax({
method: 'get',
url: 'index.php',
cache: false,
data: {
task: 'restore',
dbtype: $('#dbtype').val(),
dbhost: $('#dbhost').val(),
dbuser: $('#dbuser').val(),
dbpass: $('#dbpass').val(),
dbname: $('#dbname').val(),
prefix: $('#prefix').val(),
existing: $("input[@name='existing']:checked").val(),
replacesql: $("#replacesql").is(':checked') ? 1 : 0,
forceutf8: $("#forceutf8").is(':checked') ? 1 : 0,
checkbox: $('#suppressfk').val(),
maxtime: $('#maxtime').val()
/* -- OBSOLETE --
maxchunk: $('#maxchunk').val(),
maxqueries: $('#maxqueries').val()
*/
},
dataType: 'text',
timeout: 120000,
success: function(datext, textStatus){
var response = parseResponse(datext);
if(!response.status)
{
// An error has occured. Hide the progress bar and show the message.
$('#progressbar').hide('fast');
$('#progresstext').html(response.error);
$('#progresstext').addClass("error");
$('#dberrorhelp').show('fast');
canCloseDialog = true;
$('#dialog').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog').dialog('option', 'closeOnEscape', true);
// Hijack Next button's click
$('#nextButton').click(dbnext_click);
}
else
{
var daxml = response.message;
}
// Check if we have an error
var error = '';
try {
var error = $('error', daxml).text();
} catch(e) {}
if(error == '')
{
// Update display when no error are present
var percent = $('percent', daxml).text();
var message = $('message', daxml).text();
$('#dberrorhelp').css('display','none');
$('#progresstext').html(message);
$('#progressbar').progressbar('option', 'value', percent);
if( $('done', daxml).text() == 0 )
{
// If we are not done, requery server
stepThroughRestoration();
}
else
{
// When we are done, allow user to close the dialog box. Closing the
// dialog box, auto-clicks the Next button. Nice, huh?
canCloseDialog = true;
$('#dialog').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog').bind('dialogclose', function(event, ui) {
// Get the HREF of the nextButton, remove the 'javascript:' part and execute the remaining stuff
var href = $('#nextButton').attr('href');
eval(href.replace('/javascript:/i', ''));
});
$('#dialog').dialog('option', 'closeOnEscape', true);
if(hasAutomation)
{
// Auto-close the dialog in automation cases
$('#dialog').dialog('close');
}
}
}
else
{
// An error has occured. Hide the progress bar and show the message.
$('#progressbar').hide('fast');
$('#progresstext').html(error);
$('#progresstext').addClass("error");
$('#dberrorhelp').show('fast');
canCloseDialog = true;
$('#dialog').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog').dialog('option', 'closeOnEscape', true);
// Hijack Next button's click
$('#nextButton').click(dbnext_click);
}
},
error: function(XHR, textStatus, errorThrown){
// An AJAX error occured. Show the error message
$('#progressbar').hide('fast');
$('#progresstext').html('');
$('#progresstext').append('<p><strong>AJAX error</strong>:<br/>');
$('#progresstext').append('<tt>'+textStatus+'</tt>('+errorThrown+')</p>');
$('#progresstext').append('<p><strong>Raw Data</strong>:<pre>'+htmlentities(XHR.responseText)+'</pre></p>');
$('#progresstext').addClass("error");
$('#dberrorhelp').show('fast');
canCloseDialog = true;
$('#dialog').dialog('option', 'buttons', { "OK": function() { $(this).dialog("close"); } });
$('#dialog').dialog('option', 'closeOnEscape', true);
// Hijack Next button's click
$('#nextButton').click(dbnext_click);
}
});
}
/**
* Submits the installForm to the server, using the specified task
* @param action string The task to pass to the form
*/
function submitForm(action)
{
frm = document.getElementById("installForm");
frm.task.value = action;
frm.submit();
}
/**
* Hijacks the click event of the Next button for use in the DB
* restoration page
*/
function hijackSetupNext()
{
// Hijack Next button's click
$('#nextButton').click(setupnext_click);
// Setup error dialog
$("#dialog").dialog({
autoOpen: false,
closeOnEscape: true,
show: 'slide',
hide: 'slide',
width: 400,
height: 130,
modal: true,
position: 'center'
});
// Setup success dialog
$("#okdialog").dialog({
autoOpen: false,
closeOnEscape: true,
show: 'slide',
hide: 'slide',
width: 400,
height: 130,
modal: true,
position: 'center'
});
}
function btnFindFTPRootClick()
{
//$.blockUI({ message: '<h1><img src="css/img/busy.gif" /> Loading...</h1>' });
$.ajax({
method: 'get',
url: 'index.php',
cache: false,
data: {
task: 'ajax',
act: 'findFtpRoot',
ftp_host: $('#ftp_host').val(),
ftp_port: $('#ftp_port').val(),
ftp_user: $('#ftp_user').val(),
ftp_pass: $('#ftp_pass').val()
},
dataType: 'text',
timeout: 120000,
success: function(datext, textStatus){
var response = parseResponse(datext);
if(!response.status)
{
// An error has occured. Hide the progress bar and show the message.
$('#progressbar').hide('fast');
$('#progresstext').html(response.error);
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
// Clear checkbox and FTP root textbox
$('#ftp_enable').removeAttr('checked');
$('#ftp_root').val('');
}
else
{
var daxml = response.message;
}
//$.unblockUI();
// Check if we have an error
var error = $('error', daxml).text();
if(error == '')
{
$('#ftp_root').val($('root', daxml).text());
$('#ftp_enable').attr('checked','checked');
}
else
{
// An error has occured. Show the message.
$('#progresstext').html('<p>'+error+'</p>');
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
// Clear checkbox and FTP root textbox
$('#ftp_enable').removeAttr('checked');
$('#ftp_root').val('');
}
},
error: function(XHR, textStatus, errorThrown){
//$.unblockUI();
// An AJAX error occured. Show the error message.
$('#progressbar').hide('fast');
$('#progresstext').html('');
$('#progresstext').append('<p><strong>AJAX error</strong>:<br/>');
$('#progresstext').append('<tt>'+textStatus+'</tt>('+errorThrown+')</p>');
$('#progresstext').append('<p><strong>Raw Data</strong>:<pre>'+htmlentities(XHR.responseText)+'</pre></p>');
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
// Clear checkbox and FTP root textbox
$('#ftp_enable').removeAttr('checked');
$('#ftp_root').val('');
}
});
}
function btnFTPCheckClick()
{
//$.blockUI({ message: '<h1><img src="css/img/busy.gif" /> Loading...</h1>' });
$.ajax({
method: 'get',
url: 'index.php',
cache: false,
data: {
task: 'ajax',
act: 'checkFtp',
ftp_host: $('#ftp_host').val(),
ftp_port: $('#ftp_port').val(),
ftp_user: $('#ftp_user').val(),
ftp_pass: $('#ftp_pass').val(),
ftp_root: $('#ftp_root').val()
},
dataType: 'text',
timeout: 120000,
success: function(datext, textStatus){
var response = parseResponse(datext);
if(!response.status)
{
// An error has occured. Hide the progress bar and show the message.
$('#progressbar').hide('fast');
$('#progresstext').html(response.error);
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
// Clear checkbox and FTP root textbox
$('#ftp_enable').removeAttr('checked');
$('#ftp_root').val('');
}
else
{
var daxml = response.message;
}
//$.unblockUI();
// Check if we have an error
var error = $('error', daxml).text();
if(error == '')
{
// Everything's fine. Notify user
$('#ftp_enable').attr('checked','checked');
$('#okdialog').dialog('open');
}
else
{
// An error has occured. Show the message.
$('#progresstext').html('<p>'+error+'</p>');
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
// Clear checkbox and FTP root textbox
$('#ftp_enable').removeAttr('checked');
}
},
error: function(XHR, textStatus, errorThrown){
//$.unblockUI();
// An AJAX error occured. Show the error message.
$('#progressbar').hide('fast');
$('#progresstext').html('');
$('#progresstext').append('<p><strong>AJAX error</strong>:<br/>');
$('#progresstext').append('<tt>'+textStatus+'</tt>('+errorThrown+')</p>');
$('#progresstext').append('<p><strong>Raw Data</strong>:<pre>'+htmlentities(XHR.responseText)+'</pre></p>');
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
// Clear checkbox and FTP root textbox
$('#ftp_enable').removeAttr('checked');
}
});
}
function setupnext_click(event)
{
var allChecks = true;
var errors = Array();
i = 0; // Counter used to add items to errors array
// Site name, email, sender must be non-blank
var emailaddress = $('#mailfrom').val();
if( $('#sitename').val().replace(/^\s*/, "").replace(/\s*$/, "") == '' )
{
allChecks = false;
errors[i++] = errorstrings['sitename'];
}
if(!echeck(emailaddress))
{
allChecks = false;
errors[i++] = errorstrings['siteemail'];
}
if( $('#fromname').val().replace(/^\s*/, "").replace(/\s*$/, "") == '' )
{
allChecks = false;
errors[i++] = errorstrings['fromname'];
}
// Super admin passwords must match (exactly) and email must be non-blank
var sapass1 = $('#sapass1').val();
var sapass2 = $('#sapass2').val();
if(sapass1 !== sapass2)
{
allChecks = false;
errors[i++] = errorstrings['sapass'];
}
emailaddress = $('#saemail').val();
if(!echeck(emailaddress))
{
allChecks = false;
errors[i++] = errorstrings['saemail'];
}
if(!allChecks) {
event.preventDefault();
// Show error dialog
var message = '';
for(msg in errors)
{
message += '<li>'+errors[msg]+'</li>'+"\n";
}
$('#progresstext').html('<ul>'+message+'</ul>');
$('#progresstext').addClass("error");
$('#dialog').dialog('open');
}
}
/**
* Event handler for the checkbox which automatically assigns the temp and log paths
* @return
*/
function onOverridePaths() {
var checked = !($('#overridepaths:checked').val() == null);
if(checked)
{
$('#tmp_path').val(abi_default_tmp);
$('#log_path').val(abi_default_log);
}
else
{
$('#tmp_path').val(abi_current_tmp);
$('#log_path').val(abi_current_log);
}
}
/**
* Checks the Live Site textbox for validity and automatically adjusts it
* @return
*/
function checkLiveSite()
{
var livesite = $('#live_site').val();
if(livesite == '') return;
if( (livesite.substr(0,7) != 'http://') && (livesite.substr(0,8) != 'https://') ) {
livesite = 'http://' + livesite;
}
if( livesite.substr(-1) == '/' ) {
livesite = livesite.substr(0, livesite.length - 1);
}
$('#live_site').val(livesite);
}
/* ======================================================================= *
* UTILITY FUNCTIONS *
* ======================================================================= */
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
var at="@";
var dot=".";
var lat=str.indexOf(at);
var lstr=str.length;
var ldot=str.indexOf(dot);
if (str.indexOf(at)==-1){
return false;
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
return false;
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
return false;
}
if (str.indexOf(at,(lat+1))!=-1){
return false;
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
return false;
}
if (str.indexOf(dot,(lat+2))==-1){
return false;
}
if (str.indexOf(" ")!=-1){
return false;
}
return true;
}
function get_html_translation_table(table, quote_style) {
// http://kevin.vanzonneveld.net
var entities = {}, histogram = {}, decimal = 0, symbol = '';
var constMappingTable = {}, constMappingQuoteStyle = {};
var useTable = {}, useQuoteStyle = {};
// Translate arguments
constMappingTable[0] = 'HTML_SPECIALCHARS';
constMappingTable[1] = 'HTML_ENTITIES';
constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
constMappingQuoteStyle[2] = 'ENT_COMPAT';
constMappingQuoteStyle[3] = 'ENT_QUOTES';
useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
throw Error("Table: "+useTable+' not supported');
// return false;
}
// ascii decimals for better compatibility
entities['38'] = '&';
if (useQuoteStyle !== 'ENT_NOQUOTES') {
entities['34'] = '"';
}
if (useQuoteStyle === 'ENT_QUOTES') {
entities['39'] = ''';
}
entities['60'] = '<';
entities['62'] = '>';
if (useTable === 'HTML_ENTITIES') {
entities['160'] = ' ';
entities['161'] = '¡';
entities['162'] = '¢';
entities['163'] = '£';
entities['164'] = '¤';
entities['165'] = '¥';
entities['166'] = '¦';
entities['167'] = '§';
entities['168'] = '¨';
entities['169'] = '©';
entities['170'] = 'ª';
entities['171'] = '«';
entities['172'] = '¬';
entities['173'] = '­';
entities['174'] = '®';
entities['175'] = '¯';
entities['176'] = '°';
entities['177'] = '±';
entities['178'] = '²';
entities['179'] = '³';
entities['180'] = '´';
entities['181'] = 'µ';
entities['182'] = '¶';
entities['183'] = '·';
entities['184'] = '¸';
entities['185'] = '¹';
entities['186'] = 'º';
entities['187'] = '»';
entities['188'] = '¼';
entities['189'] = '½';
entities['190'] = '¾';
entities['191'] = '¿';
entities['192'] = 'À';
entities['193'] = 'Á';
entities['194'] = 'Â';
entities['195'] = 'Ã';
entities['196'] = 'Ä';
entities['197'] = 'Å';
entities['198'] = 'Æ';
entities['199'] = 'Ç';
entities['200'] = 'È';
entities['201'] = 'É';
entities['202'] = 'Ê';
entities['203'] = 'Ë';
entities['204'] = 'Ì';
entities['205'] = 'Í';
entities['206'] = 'Î';
entities['207'] = 'Ï';
entities['208'] = 'Ð';
entities['209'] = 'Ñ';
entities['210'] = 'Ò';
entities['211'] = 'Ó';
entities['212'] = 'Ô';
entities['213'] = 'Õ';
entities['214'] = 'Ö';
entities['215'] = '×';
entities['216'] = 'Ø';
entities['217'] = 'Ù';
entities['218'] = 'Ú';
entities['219'] = 'Û';
entities['220'] = 'Ü';
entities['221'] = 'Ý';
entities['222'] = 'Þ';
entities['223'] = 'ß';
entities['224'] = 'à';
entities['225'] = 'á';
entities['226'] = 'â';
entities['227'] = 'ã';
entities['228'] = 'ä';
entities['229'] = 'å';
entities['230'] = 'æ';
entities['231'] = 'ç';
entities['232'] = 'è';
entities['233'] = 'é';
entities['234'] = 'ê';
entities['235'] = 'ë';
entities['236'] = 'ì';
entities['237'] = 'í';
entities['238'] = 'î';
entities['239'] = 'ï';
entities['240'] = 'ð';
entities['241'] = 'ñ';
entities['242'] = 'ò';
entities['243'] = 'ó';
entities['244'] = 'ô';
entities['245'] = 'õ';
entities['246'] = 'ö';
entities['247'] = '÷';
entities['248'] = 'ø';
entities['249'] = 'ù';
entities['250'] = 'ú';
entities['251'] = 'û';
entities['252'] = 'ü';
entities['253'] = 'ý';
entities['254'] = 'þ';
entities['255'] = 'ÿ';
}
// ascii decimals to real symbols
for (decimal in entities) {
symbol = String.fromCharCode(decimal);
histogram[symbol] = entities[decimal];
}
return histogram;
}
function htmlentities (string, quote_style) {
// http://kevin.vanzonneveld.net
var histogram = {}, symbol = '', tmp_str = '', entity = '';
tmp_str = string.toString();
if (false === (histogram = this.get_html_translation_table('HTML_ENTITIES', quote_style))) {
return false;
}
for (symbol in histogram) {
entity = histogram[symbol];
tmp_str = tmp_str.split(symbol).join(entity);
}
return tmp_str;
}