<?php
/**
* PASSWORT
*/
$pass = 'abc';
/**
* Ab hier nur ändern wenn man Ahnung hat!
*/
$whiteList = array('LOGIN', 'AUTH_LOGIN', 'LOGOUT');
$fPath = 'lauftext.csv';
$method = (isset($_GET['method'])?$_GET['method']:NULL);
function checkAuth()
{
global $_COOKIE, $pass;
if( isset( $_COOKIE['tAuth'] ) && $_COOKIE['tAuth'] == md5( $pass ) )
{
return true;
}
return false;
}
if( !checkAuth( ) && ( !in_array( strtoupper( $method ), $whiteList ) ) )
{
header('Location: '.$_SERVER['PHP_SELF'].'?method=login' );
exit;
}
switch( $method )
{
case 'login':
echo 'Bitte einloggen!<br/>'.PHP_EOL;
echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?method=auth_login">'.PHP_EOL;
echo '<input type="password" name="pass"/>'.PHP_EOL;
echo '<br /><input type="submit" name="login" value="login"/>'.PHP_EOL;
echo '</form>';
break;
case 'auth_login':
if( isset($_POST['pass']) && $_POST['pass'] == $pass )
{
setcookie( 'tAuth', md5($_POST['pass']), time()+7200 );
header( 'Location: '.$_SERVER['PHP_SELF'].'?method=main' );
exit;
}
header('Location: '.$_SERVER['PHP_SELF'].'?method=login' );
exit;
break;
case 'logout':
setcookie( 'tAuth', NULL, time()-7200 );
header('Location: '.$_SERVER['PHP_SELF'].'?method=login' );
exit;
break;
case 'main'; default:
if( isset($_GET['op']) && $_GET['op'] == 'put' )
{
if( isset( $_POST['name'] ) && isset($_POST['link'] ) )
{
$string = null;
for( $i = 0; $i < sizeof($_POST['name']); $i++ )
{
if( strlen($_POST['link'][$i])>0)
{
$string .= str_replace('"','""',$_POST['link'][$i]).';'.($_POST['name'][$i]?str_replace('"','""',$_POST['name'][$i]):str_replace('"','""',$_POST['link'][$i])).PHP_EOL;
}
}
if( @file_put_contents( $fPath, $string ) )
{
echo 'Daten erfolgreich gespeichert.';
}
else
{
echo 'Es trat ein Fehler während des Speicherns auf.';
}
}
else
{
file_put_contents( $fPath, NULL );
}
}
$fHandle = @fopen( $fPath, 'r' ) or die( "Konnte $fPath nicht öffnen." );
$cContent = array();
while( false!== ( $row = fgetcsv( $fHandle, 8192, ';', '"' ) ) )
{
$li = &$cContent[];
$li['link'] = $row[0];
$li['title'] = $row[1];
}
$js = <<<JS
<script type="text/JavaScript">
var d = document;
var c = d.getElementById('container');
function addRow( )
{
for( var i = 0; i<1; i++ )
{
var sp = d.createElement('span');
var t1 = d.createElement('input');
var t2 = d.createElement('input');
t1.type = 'text';
t1.name = 'link[]';
t2.type = 'text';
t2.name = 'name[]';
sp.appendChild(t1);
sp.innerHTML += ' ';
sp.appendChild(t2);
sp.appendChild(d.createElement('br'));
c.appendChild(sp);
}
}
function deleteRowContent( node )
{
var affected = node.parentNode;
var list = affected.getElementsByTagName('input');
for( var i = 0; i<list.length; i++ )
{
if( list[i].type == 'text' )
{
list[i].value = '';
}
}
}
function undelete( node )
{
var affected = node.parentNode;
var list = affected.getElementsByTagName('input');
for( var i = 0; i<list.length; i++ )
{
if( list[i].type == 'text' )
{
list[i].value = list[i].defaultValue;
}
}
}
</script>
JS;
echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?method=main&op=put">';
echo 'Inhalt der Datei:<br/><div id="container">';
foreach( $cContent as $data )
{
echo '<span>
<input type="text" name="link[]" value="'.$data['link'].'"/>
<input type="text" name="name[]" value="'.$data['title'].'"/>
<input type="button" onClick="deleteRowContent(this);" value="diese Zeile löschen"/>
<input type="button" onClick="undelete(this);" value="rückgängig"/>
<br/>
</span>';
}
echo '</div><br /><input type="submit" value="Änderung absenden"> <input type="button" onClick="addRow();" value="Neue Zeile" /></form>'.$js;
break;
}
?>