Hier versuchs mal damit, als admin/kalendercsv.php
<?php
//Kalender CSV Import by Mairu
defined ('main') or die ( 'no direct access' );
defined ('admin') or die ( 'only admin access' );
//Irgendein Titel;Eine Beschreibung;04.08.2009;20:00;0
$design = new design ( 'Admins Area', 'Admins Area', 2 );
$design->header();
//Header
echo '<table cellpadding="0" cellspacing="0" border="0"><tr><td><img src="include/images/icons/admin/calendar.png" /></td><td width="30"></td><td valign="bottom"><h1>Kalender - CSS Import</h1></td></tr></table>
<hr style="width: 400px; margin: 0px;" >
<br /><br />';
if (!isset($_POST['addcsv'])) {
//Formular anzeigen
echo '<form method="post" enctype="multipart/form-data">
<input type="file" name="csvfile" />
<input type="submit" name="addcsv" value="einfügen" />
</form>';
} else {
//Formular auswerten
if (!empty($_FILES['csvfile']['name'])) {
$csv = file_get_contents($_FILES['csvfile']['tmp_name']);
if (!empty($csv)) {
$lines = explode("\n", $csv);
$sql_values = array();
$linesOut = array();
foreach ($lines as $line){
$tmp = explode(';', $line);
if (count($tmp) == 5) {
list($title, $text, $date, $time, $recht) = $tmp;
if (!empty($title) and !empty($text) and preg_match('%\d\d.\d\d.\d\d\d\d%', $date) == 1
and preg_match('%\d\d:\d\d%', $time)) {
$title = escape($title, 'string');
$text = escape($text, 'string');
$recht = escape($recht, 'integer');
$d = explode('.', $date);
$t = explode(':', $time);
$time = mktime($t[0], $t[1], 0, $d[1], $d[0], $d[2]);
$sql_values[] = '(0, '. $time . ', "' . $title . '", "' . $text . '", '. $recht . ')';
$linesOut[] = '<span style="color:green;">'.$line.'</span>';
} else {
$linesOut[] = '<span style="color:red;">'.$line.'</span>';
}
} else {
$linesOut[] = '<span style="color:red;">'.$line.'</span>';
}
}
if (!empty($sql_values)) {
$sql = 'INSERT INTO prefix_kalender (`gid`, `time`, `title`, `text`, `recht`) VALUE '.implode(', ', $sql_values);
db_query($sql);
echo mysql_error();
}
echo '<h2>Importierte Werte</h2>';
echo '<span style="color:green;">erfolgreich</span> - <span style="color:red;">nicht importiert</span><br /><br />';
echo implode('<br />', $linesOut);
} else {
echo 'Fehler aufgetreten.<br /><a href="admin.php?kalendercsv">zurück</a>';
}
} else {
echo 'Eine Datei auswählen<br /><a href="admin.php?kalendercsv">zurück</a>';
}
}
$design->footer();
?>
Zuletzt modifiziert von Mairu am 04.08.2009 - 19:47:09