Tutorials/de/Moduleinträge-via-Frontend-bearbeiten

Wenn durch einen falschen / fehlerhaften Moduleintrag das Backend nicht mehr zugänglich ist, oder ein Modul einen Fehler verursacht, dann kann man durch dieses Script diese Einträge via Frontend bearbeiten und rückgängig machen.

Der Zugriff auf dieses Tool wird allerdings nur gestattet, wenn man im Frontend als Admin-User (oxdefaultadmin) angemeldet ist.

&lt;?php /** * $Id$ * * Datenbankeintrag der Module bearbeiten. * Falls das Backend mal wieder zerschossen ist :-) * * # Für die Benutzung muss man im Frontend als Admin-Benutzer (oxdefaultadmin) *  angemeldet sein. * # Datei ins Root-Verzeichnis * # http://meinedomäne.tld/hz_modules.php aufrufen. * * @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; if( oxSession::getVar('usr') === null || oxSession::getVar('usr') !== 'oxdefaultadmin' ) { exit( 'Anmeldung erforderlich.' ); } 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');

/** * Eintrag aus Verlauf löschen */ 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; }

/** * Module speichern */ 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; }

/** * Wenn gepeichert oder gelöscht, redirect um "reload" zu verhindern. */ if( $scriptConfig-&gt;redirect === true ) { $shopConfig-&gt;saveShopConfVar( 'aarr', 'aModulesHistory', $scriptConfig-&gt;history, $sShopId, $sModule = '' ); header('location:http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ); }

/** * Zeichenkette für die Textarea * Setze den ersten Eintrag aus dem Verlauf (Letzter gepeicherter) wenn es einen * gibt. */ $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 = 'Kommentar'; }

?&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 - Module bearbeiten&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;Module bearbeiten&lt;/h1&gt; &lt;ul&gt; &lt;li&gt;Man kann Einträge auch auskommentieren in dem man die Klasse "unkenntlich" macht. z.B.: "//oxorder =&amp;gt; ... "&lt;/li&gt; &lt;li&gt;Windowssystem akzeptieren "Datei.php = datei.php", Unix nicht. Schreibweise beachten.&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;Aktuelle Moduleinträge:&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="Auf letzten Stand zurücksetzen." /&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;In das Eingabefeld übernehmen&lt;/a&gt;|&lt;a class="delete" href="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;?v[delete]=&lt;?php echo $time?&gt;"&gt;aus Verlauf löschen&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'     : 'Einträge unverändert.', 'changed' : 'Einträge wurden geändert, speichern um diese zu übernehmen.' },   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; Danke an Stefan / stefan2 http://www.oxid-esales.com/forum/member.php?u=8626

Thread im Forum: http://www.oxid-esales.com/forum/showthread.php?t=9393&amp;page=3#post57389