dvm/praxisstelle/export_bewerber.php
2022-11-28 10:27:30 +01:00

92 lines
3.1 KiB
PHP
Executable File

<?php
if(!isset($_SESSION)) { session_start(); }
require_once("../config.inc.php");
if($_SESSION["prx_dst_id"] == ''){
echo"<script type='text/javascript'>window.top.location.href = \"index.php\";</script>";
}
$dst_id = $_SESSION["prx_dst_id"];
$Use_Title = 0;
$now_date = date('m-d-Y H:i');
$title = "Dump For Table $DB_TBLName from Database $DB_DBName on $now_date";
$sql = "SELECT b.ka_id as Bewerbernr
, vorname as Vorname
, nachname as Nachname
, str 'Strasse'
, plz PLZ
, ort Ort
, mail as 'E-Mail'
, behinderung AS Schwerbehinderung
, replace(hzb,'.', ',') as 'HZB Note'
, replace(zeugnisschnitt,'.', ',') as 'Alternativ Zeugnisschnitt Note'
, replace(zeugnisschnitt_punkte,'.', ',') 'Alternativ Zeugnisschnitt Punkte'
,(SELECT summe FROM dvm_ergebnisse d WHERE a.ka_id= d.ka_id AND bestanden = '1' ORDER BY eg_id desc LIMIT 1) as Testergebnis
FROM dvm_dst_wunsch a, dvm_kandidat b, dvm_note c
WHERE a.ka_id = b.ka_id
AND a.ka_id = c.ka_id
AND a.dst_id = '$dst_id'
AND archiv_dat = '0000-00-00 00:00:00'
ORDER BY a.datum desc";
$result = @$db->query($sql)
or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
//header info for browser
#header("Content-Type: text/comma-separated-values");
header('Content-Encoding: UTF-8');
header("Content-type: text/csv; charset=UTF-8");
echo "\xEF\xBB\xBF";
header("Content-Disposition: attachment; filename=export_bewerber.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";
}
?>