0)
{
if( $file_overrides_handle )
{
fclose( $file_overrides_handle );
}
break;
}
if( strpos( $old_content, $file_section_start ) !== false && strpos( $old_content, $file_section_end ) !== false )
{ // File contains correct section to edit
$old_content_start = substr( $old_content, 0, strpos( $old_content, $file_section_start ) + strlen( $file_section_start ) );
$old_content_end = substr( $old_content, strpos( $old_content, $file_section_end ) );
}
else
{ // Config editable start or end sections don't exist in the file, we should create them
$is_php_tag_opened = strpos( $old_content, '' ) !== false;
$is_php_tag_closed = strpos( $old_content, '?>' ) !== false;
if( $is_php_tag_opened && $is_php_tag_closed )
{ // File contains the open and close tags
$old_content_start = substr( $old_content, 0, strpos( $old_content, '?>' ) );
$old_content_end = substr( $old_content, strpos( $old_content, '?>' ) );
}
elseif( !$is_php_tag_opened && !$is_php_tag_closed )
{ // File doesn't contain the open and close php tags, Add this at the file end
$old_content_start = $old_content.'';
}
elseif( !$is_php_tag_closed )
{ // File doesn't contain only the close php tag, Insert new config text at the end
$old_content_start = $old_content;
$old_content_end = '';
}
$old_content_start = $old_content_start."\n".$file_section_start;
$old_content_end = $file_section_end."\n".$old_content_end;
}
// Write new content into config
ftruncate( $file_overrides_handle, 0 );
fseek( $file_overrides_handle, 0 );
fwrite( $file_overrides_handle, $old_content_start."\n".$file_overrides_content."\n".$old_content_end );
fclose( $file_overrides_handle );
$message = T_('Debug config has been changed');
break;
default:
if( file_exists( $file_overrides_name ) )
{ // Display a form to log in if file already exists
$action = 'password_form';
}
break;
}
switch( $action )
{
case 'password_form':
$title = T_('Check password');
break;
case 'config_form':
$title = T_('Update debug config');
break;
default:
$title = '';
break;
}
// Form params
$booststrap_install_form_params = array(
'formstart' => '',
'formend' => '',
'fieldstart' => '
'."\n",
'fieldend' => "
\n\n",
'labelclass' => 'control-label col-sm-4',
'labelstart' => '',
'labelend' => "\n",
'labelempty' => '',
'inputstart' => '',
'inputend' => "
\n",
'buttonsstart' => '\n\n",
'note_format' => ' %s',
'bottom_note_format' => ' %s
',
);
header('Content-Type: text/html; charset='.$evo_charset);
header('Cache-Control: no-cache'); // no request to this page should get cached!
?>
'.T_('Debug tool').'';
display_install_messages( sprintf( T_('This tool allows you to configure some debug variables in the file %s'), $file_overrides_name ), 'info' );
switch( $action )
{
case 'password_form':
/*
* -----------------------------------------------------------------------------------
* Form to log in
* -----------------------------------------------------------------------------------
*/
block_open( T_('Log in to edit the config of debug') );
$Form = new Form( $_SERVER['PHP_SELF'] );
$Form->switch_template_parts( $booststrap_install_form_params );
$Form->begin_form( 'form-horizontal' );
$Form->hidden( 'action', 'login' );
$Form->text( 'password', '', 16, T_('Password'), T_('Debug password'), 120, '', 'password' );
$Form->end_form( array( array( 'name' => 'submit', 'value' => T_('Log in'), 'class' => 'btn-primary btn-lg' ) ) );
block_close();
break;
case 'config_form':
/*
* -----------------------------------------------------------------------------------
* Form to change the debug config
* -----------------------------------------------------------------------------------
*/
block_open( T_('Debug config') );
$Form = new Form( $_SERVER['PHP_SELF'] );
$Form->switch_template_parts( $booststrap_install_form_params );
$Form->begin_form( 'form-horizontal' );
$Form->hidden( 'action', 'update_config' );
$Form->hidden( 'password', $password );
$Form->textarea_input( 'content', $file_overrides_content, 20, T_('Config'), array(
'cols' => 50,
'note' => 'A few possible settings:
$debug = 1;
$debug_jslog = 1;
$allow_po_extraction = 1;
$allow_install_test_features = true;
$db_config[\'debug_dump_rows\'] = 20;
$db_config[\'debug_explain_joins\'] = false;
$display_errors_on_production = false;'
) );
$Form->end_form( array( array( 'name' => 'submit', 'value' => T_('Save Changes!'), 'class' => 'btn-primary btn-lg' ) ) );
block_close();
break;
default:
/*
* -----------------------------------------------------------------------------------
* Default config
* -----------------------------------------------------------------------------------
*/
echo T_( 'To enable this tool, create a file called /conf/_overrides_TEST.php with the following contents:' );
echo '
<?php
$debug_pwd = \'set a password here\';
// @@BEGIN debug.php section
// @@END debug.php section
?>
';
break;
}
?>