bewertung/export.php
2023-04-14 11:55:30 +02:00

83 lines
3.2 KiB
PHP
Executable File

<?php
include("kurs/datenbankanbindung.php"); // f&uuml;gt die Datenbankanbindung ein: Sys:\php\includes\zula\datenbankanbindung.php
$db = dbconnect();
$sql = "SELECT doz_funktion
, doz_anrede
, doz_titel
, doz_vorname
, doz_name
, doz_mail
, bezeichnung
, kuerzel
, replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(studiengang, '1Sem1' ,'1. Semester'), '1Sem2', '2. Semester'), '1Sem3', '3. Semester'), '1Sem4', '4. Semester'), '1Sem5', '5. Semester'), '1Sem6', '6. Semester'), '2GI', 'Fakultät 2: Grundstudium I'), '2GII', 'Fakultät 2: Grundstudium II'), '2GIII', 'Fakultät 2: Grundstudium III'), '2HS', 'Fakultät 2: Hauptstudium') studiengang
, replace(replace(replace(replace(replace(replace(lv_art, 1, 'Vorlesung'), 2, 'Seminar'), 3, 'Proseminar'), 4 , 'Übung'), 5, 'Praktikum'), 6, 'AG') art
, teilnehmer
, ag
, jahrgang
, lfd_nr prioritaet
FROM doz, bew_wunsch, bew_vorlesungen
WHERE doz.doz_uid = bew_wunsch.doz_uid
AND bew_wunsch.lv_name = bew_vorlesungen.vlid
ORDER BY doz_name, prioritaet
";
$result = @$db->query($sql)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
$now_date = date('d.m.Y-Hi');
//header info for browser
header('Content-Encoding: UTF-8');
header("Content-type: text/csv; charset=UTF-8");
#header("Content-Type: text/comma-separated-values;charset=UTF-8");
echo "\xEF\xBB\xBF";
header("Content-Disposition: attachment; filename=export_bewertung_$now_date.csv"); //header("Content-Disposition: attachment; filename=database_dump.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");
/*
if ($Use_Title == 1){
echo("$title\n");
}
*/
//define separator (defines columns in excel & tabs in word)
$sep = ";"; //tabbed character
//start of printing column names as names of MySQL fields
for ($i = 0; $i < mysqli_num_fields($result); $i++) {
echo mysqli_fetch_field_direct($result,$i)->name . ";";
}
print("\n");
//end of printing column names
//start while loop to get data
/*
note: the following while-loop was taken from phpMyAdmin 2.1.0.
--from the file "lib.inc.php".
*/
while($row = $result->fetch_array())
{
//set_time_limit(60); // HaRa
$schema_insert = "";
for($j=0; $j<mysqli_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
//following fix suggested by Josue (thanks, Josue!)
//this corrects output in excel when table fields contain \n or \r
//these two characters are now replaced with a space
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>