Tutorials/en/edit-Module-entries-via-Frontend

If a Module entry causes a crash of the backend area you can easily edit those entires via frontend with this script.

So you can restore the backend functionality very easy without digging in the database. This script can be used only when logged in as admin user (oxdefaultadmin) in the frontend.

Simply save the following code to a php file and place into the rootlevel of your shop. Call the script with www.your-domain/file.php

&lt;?php /** * $Id$ * * edit Database entries of Shop-modules * If the backend has crashed once again :-) * * # When using you need to be logged in as admin in frontend * # Place this file into Shop-Root * # http://www.my-domain.tld/this_file.php * * @TODO *    # Ausbauen um alle Konfigurationsschalter zu bearbeiten. * * @version 0.2.0 | 20110501 * @author Stefan Mayer | meniskus@gmx.net */

function getShopBasePath { return realpath( dirname(__FILE__) ). DIRECTORY_SEPARATOR; } require_once getShopBasePath. 'core/oxfunctions.php'; $shopConfig = oxConfig::getInstance;

/** * delete the following two lines if you want to access the tool without admin-logon */ if( oxSession::getVar('usr') === null || oxSession::getVar('usr') !== 'oxdefaultadmin' ) { exit( 'You need to login first.' ); } error_reporting( E_ALL | E_STRICT ); header('content-type:text/html; charset=utf-8');

class Hz_Modules {   public function __construct{} }

$scriptConfig = (object) array(   'delimiter'   =&gt; PHP_EOL,    'separator'   =&gt; '=&gt;',    'str_pad'     =&gt; 30,    'session_key' =&gt; 'hz_modules',//basename(__FILE__)    'redirect'    =&gt; false,    'lang'        =&gt; ( $lang = oxLang::getInstance-&gt;getLanguageAbbr ) ? $lang : 'de',    'history'     =&gt; null,    'text'        =&gt; array( 'headline' =&gt; array(           'de' =&gt; 'Moduleinträge bearbeiten.',            'en' =&gt; 'Edit Module-Entries'        ), ) ); $sShopId = $shopConfig-&gt;getBaseShopId;

$scriptConfig-&gt;history = $shopConfig-&gt;getConfigParam('aModulesHistory');

/** * Delete entry from history */ if( isset( $_GET['v']['delete'] ) ) { $time = (int)$_GET['v']['delete']; if( isset( $scriptConfig-&gt;history[$time] ) ) { unset( $scriptConfig-&gt;history[$time] ); }   $scriptConfig-&gt;redirect = true; }

/** * save Module entries */ if( isset( $_POST['m']['save'] ) ) {   $_string  = trim( $_POST['m']['modules'] ); $_rows   = explode( $scriptConfig-&gt;delimiter, $_string ); $aModules = array; foreach( $_rows as $_row ) { if( strpos($_row, $scriptConfig-&gt;separator ) === false ) { continue; }       $_m = explode($scriptConfig-&gt;separator, $_row); if( !isset( $_m[0] ) || !isset( $_m[1] ) ) { continue; }       $class    = trim( $_m[0] ); $module  = trim( $_m[1] ); if( !empty( $class ) &amp;&amp; !empty( $module ) ) { $aModules[$class] = $module; }   }    $shopConfig-&gt;saveShopConfVar( 'aarr', 'aModules', $aModules, $sShopId, $sModule = '' ); $_aTmp = array; foreach( $aModules as $class =&gt; $module ) { $_aTmp[] = str_pad($class,$scriptConfig-&gt;str_pad,' '). str_pad( $scriptConfig-&gt;separator, ( strlen( $scriptConfig-&gt;separator ) + 2 ), ' ', STR_PAD_BOTH ). $module; }   $scriptConfig-&gt;history[time] = array(        'comment' =&gt; htmlspecialchars( $_POST['m']['comment'] ),        'modules'   =&gt; implode( PHP_EOL, $_aTmp )    ); krsort( $scriptConfig-&gt;history ); $scriptConfig-&gt;redirect = true; }

/** * after saving or deleting, redirect to avoid "reload" */ if( $scriptConfig-&gt;redirect === true ) { $shopConfig-&gt;saveShopConfVar( 'aarr', 'aModulesHistory', $scriptConfig-&gt;history, $sShopId, $sModule = '' ); header('location:http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ); }

/** * String for Textarea * set the first entry from history (last saved) if there is one. */ $sModules = ''; $sComment = ''; if( !empty( $scriptConfig-&gt;history ) ) { $_entry = reset( $scriptConfig-&gt;history ); $sModules = $_entry['modules']; $sComment = $_entry['comment']; } else { $_aModules = array; foreach( $shopConfig-&gt;getConfigParam( 'aModules' ) as $class =&gt; $module ) { $_aModules[] = str_pad($class,$scriptConfig-&gt;str_pad,' '). str_pad( $scriptConfig-&gt;separator, ( strlen( $scriptConfig-&gt;separator ) + 2 ), ' ', STR_PAD_BOTH). $module; }   $sModules = implode( PHP_EOL, $_aModules ); $sComment = 'Comment'; }

?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="de" xml:lang="en"&gt; &lt;head&gt; &lt;title&gt;OXID eSales - edit Modules&lt;/title&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;meta http-equiv="Content-Language" content="de" /&gt; &lt;meta http-equiv="Content-Script-Type" content="text/javascript" /&gt; &lt;meta http-equiv="Content-Style-Type" content="text/css" /&gt; &lt;meta name="language" content="de" /&gt; &lt;meta name="author" content="Stefan Mayer[meniskus@gmx.net]" /&gt; &lt;style type="text/css"&gt; body{ font-family: Arial, Helvetica, sans-serif; font-size: .9em; color: #333; padding:0px; } form{ background-color: #fff; padding-bottom:10px; z-index:10 } div#hz-modules-wrapper{ background-color: #fff; padding-bottom:10px; /* position:relative; */width:100%; z-index:10 } fieldset{ border-radius: 8px; background-color:#f9f9f9; border:1px solid #333 } textarea{ width: 99%; height: auto; background-color: #fff; white-space: pre; font-family: 'courier new'; font-size: 10pt; border-radius: 5px; padding:8px; border:1px solid #333; margin-bottom:1em; } form input.comment{ width: 99%; margin-bottom: 10px; border-radius: 5px; border:1px solid #333; padding: 8px; } dt, dd{ background-color: #f9f9f9; padding:8px; border:1px solid #333; } dt{ margin-bottom:0px; border-bottom:none; border-radius: 5px 5px 0 0; padding:5px 10px; padding-bottom:0; } dd{ border-top:none; margin-left: 0; margin-bottom:1em; border-radius: 0 0 5px 5px; } dt a{ color: inherit; padding: 2px 5px; border-radius:4px; } dt a.set:hover{ background-color: green; color: #fff; } dt a.delete:hover{ background-color: red; color: #fff; } dt textarea{ margin-bottom:0; } h1 + ul{ display:none; } h1:hover + ul, h1 + ul:hover{ display:block; }

.ok{ border:1px solid #55b05a; } .changed{ border:1px solid #d23d24; } input[type=submit]{ cursor:pointer; background-color:#d8d8d8; background-position: 4px center; background-repeat: no-repeat; padding: 4px; padding-left: 25px; border-radius:3px; } input[type=submit].ok{ box-shadow:0 0 2px 0 #55b05a; background-image:url('data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%02%00%00%00%90%91h6%00%00%00%19IDAT(%91c%0C%DD%10%C5%40%0A%60%22I%F5%A8%86Q%0DCJ%03%00dy%01%7F%0C%9F0%7D%00%00%00%00IEND%AEB%60%82'); }       input[type=submit].changed{ box-shadow:0 0 3px 0 #d23d24; background-image:url('data:image/png,%89PNG%0D%0A%1A%0A%00%00%00%0DIHDR%00%00%00%10%00%00%00%10%08%02%00%00%00%90%91h6%00%00%00%19IDAT(%91c%BCd%AB%C2%40%0A%60%22I%F5%A8%86Q%0DCJ%03%00%DE%B5%01S%07%88%8FG%00%00%00%00IEND%AEB%60%82'); } .hidden{ display:none; } .shown{ display:inline; } &lt;/style&gt; &lt;/head&gt; &lt;body&gt;

&lt;h1&gt;edit Modules&lt;/h1&gt; &lt;ul&gt; &lt;li&gt;You can deactivate entries like: "//oxorder =&amp;gt; ... "&lt;/li&gt; &lt;li&gt;Unix systems are case sensitive. "File.php" is not equal with "file.php". Please keep in mind.&lt;/li&gt; &lt;/ul&gt; &lt;form id="hz-modules-form" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;fieldset&gt;&lt;legend&gt;actual module entries:&lt;/legend&gt; &lt;textarea class="ok" id="hz-modules" name="m[modules]" rows="10" cols="50" style="line-height:1.25em;" onkeyup="Hz_Modules.onFieldEdit(event);return true;"&gt;&lt;?php echo $sModules; ?&gt;&lt;/textarea&gt; &lt;input class="comment" type="text" name="m[comment]" id="hz-modules-comment" value="&lt;?php echo $sComment; ?&gt;" /&gt; &lt;input class="ok" type="submit" name="m[save]" id="hz-modules-submit" value="Einträge speichern." /&gt; &lt;input class="ok hidden" type="submit" id="hz-modules-reset" onclick="Hz_Modules.resetValue;return false;" value="Reset to last saved version." /&gt; &lt;/fieldset&gt; &lt;/form&gt;

&lt;?php if( $history = $scriptConfig-&gt;history ) : ?&gt; &lt;h2 id="hz-history"&gt;Verlauf:&lt;/h2&gt; &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt; &lt;dl&gt; &lt;?php foreach( $history as $time =&gt; $data ) : ?&gt; &lt;dt&gt;&lt;?php echo date('d.m.Y H:i:s', $time ); ?&gt; ↔ &lt;a class="set" href="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" onclick="Hz_Modules.setHistoryValue('&lt;?php echo $time;?&gt;');return false;"&gt;copy to input field&lt;/a&gt;|&lt;a class="delete" href="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;?v[delete]=&lt;?php echo $time?&gt;"&gt;delete from history&lt;/a&gt;&lt;/dt&gt; &lt;dd&gt; &lt;input type="text" class="comment" name="h[comment]" id="hz-history-comment-&lt;?php echo $time;?&gt;" value="&lt;?php echo $data['comment']; ?&gt;" /&gt; &lt;textarea readonly="readonly" name="h[value]" rows="20" cols="50" style="line-height:1.25em" id="hz-history-&lt;?php echo $time;?&gt;"&gt;&lt;?php echo $data['modules']; ?&gt;&lt;/textarea&gt; &lt;/dd&gt; &lt;?php endforeach; ?&gt; &lt;/dl&gt; &lt;/form&gt; &lt;?php endif; ?&gt;

&lt;script type="text/javascript"&gt; //&lt;![CDATA[ var Hz_Modules = { 'form'   : document.getElementById('hz-modules-form'), 'history' : document.getElementById('hz-history'), 'field'  : document.getElementById('hz-modules'), 'field_comment' : document.getElementById('hz-modules-comment'), 'button' : document.getElementById('hz-modules-submit'), 'reset'  : document.getElementById('hz-modules-reset'), 'height' : 100, 'value'  : null, 'comment' : null, 'changed' : false, 'text'   : { 'ok'     : 'Entries unchanged.', 'changed' : 'Entries changed, save to use new ones.' },   init : function { if( this.field ) { this.value  = this.field.value; this.comment = this.field_comment.value; this.field.focus; this.setFieldHeight; }       if( this.history ) { this.addScroll; this.setHistoryFieldsHeight; }   },    setFieldHeight : function { this.calculateFieldHeight; this.field.style.height = this.height + 'em'; },   setHistoryValue : function( time ) { var $value  = this.value; var $comment = this.comment; var $source = document.getElementById('hz-history-' + time ); var $hcomment = document.getElementById('hz-history-comment-' + time ); if( $source ) { $value = $source.textContent; }       if( $hcomment ) { $comment = $hcomment.value; }       this.setFieldContent( $value, $comment ); },   setFieldContent : function( value, comment ) { this.field.value        = value; this.field_comment.value = comment; this.setFieldHeight; this.setUi; },   isChanged : function( value ) { var $value = ( value || this.field.value ) if( $value !== this.value ) { this.changed = true; } else { this.changed = false; }       return this.changed; },   setUi : function { if( this.isChanged ) { var $status = 'changed'; this.reset.setAttribute('class', 'ok shown'); } else { var $status = 'ok'; this.reset.setAttribute('class', 'ok hidden'); }       //Opera bug sumbit value:  http://webinterfacetricks.com/opera_submit_bug/ this.button.setAttribute('value', this.text[$status]); this.field.setAttribute('class', $status); this.button.setAttribute('class', $status); },   onFieldEdit : function(event){ this.setFieldHeight; this.setUi; },   resetValue : function { this.setFieldContent( this.value, this.comment ); },   calculateFieldHeight : function { var $rows  = this.field.value.split('\n'); this.height = (parseFloat(this.field.style.lineHeight)*$rows.length ); },   addScroll : function { var $form       = this.form; var $form_offset = this.form.offsetTop; var $form_width = this.form.clientWidth; var $padding_top = this.history.offsetTop; var $body       = document.getElementsByTagName('body')[0]; var $h1         = document.getElementsByTagName('h1')[0]; window.onscroll = function { if (document.documentElement.scrollTop &gt; $form_offset || self.pageYOffset &gt; $form_offset ) { $form.style.position  = 'fixed'; $form.style.top       = '0'; $form.style.width     = $form_width + 'px'; $body.style.paddingTop = $padding_top +'px'; $h1.style.display     = 'none'; } else if (document.documentElement.scrollTop &lt; $form_offset || self.pageYOffset &lt; $form_offset ) { $form.style.position  = 'relative'; $form.style.width     = 'auto'; $body.style.paddingTop = 0; $h1.style.display     = 'block'; }       }    },    setHistoryFieldsHeight : function { var $fields = document.getElementsByTagName('textarea'); for( i = 0; i &lt; $fields.length; i++ ) { var $rows  = $fields.item(i).value.split('\n'); $fields.item(i).style.height = (parseFloat($fields.item(i).style.lineHeight)*$rows.length ) + 'em'; }   } } Hz_Modules.init; //]]&gt; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; Thanks to Stefan / stefan2

http://www.oxid-esales.com/forum/member.php?u=8626