mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-07 15:19:31 +00:00
- Anpassungen Syncs
- Kreuzerltool Gruppe zur LE-Auswahl hinzugefügt - sync_fas_std.php an neue DB angepasst
This commit is contained in:
+149
-67
@@ -1,10 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* FAS-Synchronisation
|
||||
*/
|
||||
|
||||
include ('../../vilesci/config.inc.php');
|
||||
$adress='fas_sync@technikum-wien.at';
|
||||
/* Copyright (C) 2006 Technikum-Wien
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
|
||||
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
|
||||
* Rudolf Hangl <rudolf.hangl@technikum-wien.at>.
|
||||
*/
|
||||
require_once('../../vilesci/config.inc.php');
|
||||
$adress='tw_tester@technikum-wien.at';
|
||||
|
||||
function clean_string($string)
|
||||
{
|
||||
@@ -37,22 +53,23 @@
|
||||
$conn_fas=pg_connect(CONN_STRING_FAS);
|
||||
|
||||
// Anzahl der Studenten in VileSci
|
||||
$sql_query="SELECT count(*) AS anz FROM tbl_student";
|
||||
$sql_query="SELECT count(*) AS anz FROM public.tbl_student";
|
||||
//echo $sql_query."<br>";
|
||||
$result=pg_exec($conn, $sql_query);
|
||||
$vilesci_anz_std=pg_fetch_result($result,0,'anz');
|
||||
$result=pg_query($conn, $sql_query);
|
||||
$row=pg_fetch_object($result);
|
||||
$vilesci_anz_std = $row->anz;
|
||||
|
||||
// Start Studenten Synchro
|
||||
$sql_query="SELECT DISTINCT * FROM fas_view_student_vilesci WHERE semester >0 AND semester <9 AND";
|
||||
$sql_query.=" verband IS NOT NULL AND uid IS NOT NULL AND uid NOT LIKE ''"; // LIMIT 5";
|
||||
echo $sql_query."<br>";
|
||||
$sql_query.=" verband IS NOT NULL AND uid IS NOT NULL AND uid NOT LIKE ''";
|
||||
//echo $sql_query."<br>";
|
||||
flush();
|
||||
$result=pg_exec($conn_fas, $sql_query);
|
||||
$num_rows=pg_numrows($result);
|
||||
$result=pg_query($conn_fas, $sql_query);
|
||||
$num_rows=pg_num_rows($result);
|
||||
$text="Dies ist eine automatische eMail!\r\r";
|
||||
$text.="Es wurde eine Synchronisation mit FAS durchgeführt.\r";
|
||||
$text.="Anzahl der Studenten vom FAS-Import: $num_rows \r";
|
||||
$text.="Anzahl der Studenten in VileSci: $vilesci_anz_std \r\r";
|
||||
$text.="Anzahl der Studenten in Portal: $vilesci_anz_std \r\r";
|
||||
echo $text.'<BR>';
|
||||
flush();
|
||||
$plausi_error=0;
|
||||
@@ -73,68 +90,131 @@
|
||||
if ($row->verband>='A' && $row->verband<='D' && $row->semester<=8 && $row->gruppe>'0' && $row->gruppe<='2')
|
||||
{
|
||||
// SQL vorbereiten (jeden Studenten vom FAS im VileSci suchen
|
||||
$sql_query="SELECT uid,titel,vornamen,nachname,gebdatum,gebort,";
|
||||
$sql_query="SELECT tbl_person.person_id, uid,titelpre,vorname,nachname,gebdatum,gebort,";
|
||||
$sql_query.="trim(both ' ' from matrikelnr) AS matrikelnr,";
|
||||
$sql_query.=" studiengang_kz,semester,verband,gruppe";
|
||||
$sql_query.=" FROM tbl_person NATURAL JOIN tbl_student WHERE uid LIKE '$uid'";
|
||||
$sql_query.=" FROM public.tbl_person, public.tbl_benutzer, public.tbl_student WHERE
|
||||
tbl_person.person_id=tbl_benutzer.person_id AND tbl_benutzer.uid=tbl_student.student_uid
|
||||
AND tbl_benutzer.uid='$uid'";
|
||||
// echo $sql_query;
|
||||
$res_std=pg_exec($conn, $sql_query);
|
||||
$num_rows_std=pg_numrows($res_std);
|
||||
$res_std=pg_query($conn, $sql_query);
|
||||
$num_rows_std=pg_num_rows($res_std);
|
||||
|
||||
// neue Studenten
|
||||
if ($num_rows_std==0)
|
||||
{
|
||||
|
||||
$text.="Der Student $row->vornamen $row->nachname ($row->uid) wird neu angelegt.\r";
|
||||
// tbl_person
|
||||
$sql_query="INSERT INTO tbl_person(uid,titel,vornamen, nachname, gebdatum, gebort) ".
|
||||
"VALUES('$row->uid','$row->titel','$row->vornamen','$row->nachname','$row->gebdatum','$row->gebort')";
|
||||
echo $sql_query.'<BR>';
|
||||
flush();
|
||||
|
||||
//Alias erstellen
|
||||
$vn = split('[- .,]',strtolower($row->vornamen));
|
||||
$vn = clean_string($vn[0]);
|
||||
|
||||
$nn = split('[- .,]',strtolower($row->nachname));
|
||||
$nn = clean_string($nn[0]);
|
||||
$alias = $vn.".".$nn;
|
||||
$qry = "UPDATE tbl_person set alias='$alias' where uid='$row->uid'";
|
||||
if(!$res_insert=pg_exec($conn, $qry))
|
||||
{
|
||||
$text.=$qry;
|
||||
$text.="\rFehler: Alias existiert bereits: $alias";
|
||||
$insert_error++;
|
||||
}
|
||||
pg_query($conn, "BEGIN");
|
||||
|
||||
// tbl_student
|
||||
if(!$res_insert=pg_exec($conn, $sql_query))
|
||||
// person
|
||||
if(!$len=strpos($row->vornamen,' '))
|
||||
{
|
||||
$text.=$qry;
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
$insert_error++;
|
||||
}
|
||||
$sql_query="INSERT INTO tbl_student (uid,matrikelnr, studiengang_kz, semester, verband, gruppe) ".
|
||||
"VALUES('$row->uid','$row->perskz',$row->kennzahl,$row->semester,'$row->verband','$row->gruppe')";
|
||||
echo $sql_query.'<BR>';
|
||||
if(!$res_insert=pg_exec($conn, $sql_query))
|
||||
{
|
||||
$text.=$sql_query;
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
$insert_error++;
|
||||
$vorname=$row->vornamen;
|
||||
$vornamen='';
|
||||
}
|
||||
else
|
||||
$anz_insert++;
|
||||
{
|
||||
$vorname=substr($row->vornamen,0,$len);
|
||||
$vornamen=substr($row->vornamen,$len+1,strlen($row->vornamen));
|
||||
}
|
||||
|
||||
// tbl_person
|
||||
$sql_query="INSERT INTO tbl_person(titelpre,vorname,vornamen, nachname, gebdatum, gebort, aktiv) ".
|
||||
"VALUES('$row->titelpre','$row->vorname','$row->vornamen','$row->nachname','$row->gebdatum','$row->gebort', true)";
|
||||
//echo $sql_query.'<BR>';
|
||||
flush();
|
||||
|
||||
if(!$res_insert=pg_query($conn, $qry))
|
||||
{
|
||||
$text.=$qry;
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
$insert_error++;
|
||||
pg_query($conn, 'ROLLBACK');
|
||||
}
|
||||
else
|
||||
{
|
||||
$qry = "SELECT currval('tbl_person_person_id_seq') AS id;";
|
||||
|
||||
if(!$row_seq=pg_fetch_object(pg_query($this->conn,$qry)))
|
||||
{
|
||||
pg_query($conn, 'ROLLBACK');
|
||||
$text = 'Sequence konnte nicht ausgelesen werden\n';
|
||||
$insert_error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$person_id = $row_seq->id;
|
||||
|
||||
//Benutzer Datensatzt anlegen
|
||||
$qry = "INSERT INTO public.tbl_benutzer(uid, person_id, aktiv, insertamum, insertvon, updateamum, updatevon)
|
||||
VALUES('$row->uid','$person_id','true',now(),'auto',now(),'auto');";
|
||||
|
||||
if(!pg_query($conn, $qry))
|
||||
{
|
||||
pg_query($conn, 'ROLLBACK');
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
$insert_error++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Alias erstellen
|
||||
$vn = split('[- .,]',strtolower($row->vornamen));
|
||||
$vn = clean_string($vn[0]);
|
||||
|
||||
$nn = split('[- .,]',strtolower($row->nachname));
|
||||
$nn = clean_string($nn[0]);
|
||||
$alias = $vn.".".$nn;
|
||||
$qry = "UPDATE public.tbl_benutzer set alias='$alias' WHERE uid='$uid'";
|
||||
if(!$res_insert=pg_query($conn, $qry))
|
||||
{
|
||||
$text.=$qry;
|
||||
$text.="\rFehler: Alias existiert bereits: $alias";
|
||||
$insert_error++;
|
||||
pg_query($conn, 'ROLLBACK');
|
||||
}
|
||||
|
||||
// tbl_student
|
||||
$sql_query="INSERT INTO public.tbl_student (student_uid,matrikelnr, studiengang_kz, semester, verband, gruppe) ".
|
||||
"VALUES('$row->uid','$row->perskz',$row->kennzahl,$row->semester,'$row->verband','$row->gruppe')";
|
||||
echo $sql_query.'<BR>';
|
||||
if(!$res_insert=pg_query($conn, $sql_query))
|
||||
{
|
||||
$text.=$sql_query;
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
$insert_error++;
|
||||
pg_query($conn, 'ROLLBACK');
|
||||
}
|
||||
else
|
||||
{
|
||||
$anz_insert++;
|
||||
pg_query($conn, 'COMMIT');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// bestehende Studenten
|
||||
elseif ($num_rows_std==1)
|
||||
{
|
||||
$update=0;
|
||||
$row_std=pg_fetch_object($res_std,0);
|
||||
$row_std=pg_fetch_object($res_std);
|
||||
if(!$len=strpos($row->vornamen,' '))
|
||||
{
|
||||
$vorname=$row->vornamen;
|
||||
$vornamen='';
|
||||
}
|
||||
else
|
||||
{
|
||||
$vorname=substr($row->vornamen,0,$len);
|
||||
$vornamen=substr($row->vornamen,$len+1,strlen($row->vornamen));
|
||||
}
|
||||
if ($row->gruppe==NULL)
|
||||
$row->gruppe=1;
|
||||
if ($row->titel!=$row_std->titel)
|
||||
if ($row->titel!=$row_std->titelpre)
|
||||
$update=1;
|
||||
elseif ($row->vornamen!=$row_std->vornamen)
|
||||
elseif ($vorname!=$vorname)
|
||||
$update=2;
|
||||
elseif ($row->nachname!=$row_std->nachname)
|
||||
$update=3;
|
||||
@@ -154,20 +234,21 @@
|
||||
$update=10;
|
||||
if ($update)
|
||||
{
|
||||
$text.="Der Student $row->vornamen $row->nachname ($row->uid) wird upgedatet.\r";
|
||||
$text.="Der Student $row->vornamen $row->nachname ($row->uid) [$update] wird upgedatet.\r";
|
||||
|
||||
// person
|
||||
$sql_query="UPDATE tbl_person SET titel='$row->titel', vornamen='$row->vornamen', ".
|
||||
$sql_query="UPDATE public.tbl_person SET titelpre='$row->titel', vornamen='$vornamen', vorname='$vorname', ".
|
||||
" nachname='$row->nachname', gebdatum='$row->gebdatum', gebort='$row->gebort'".
|
||||
" WHERE uid LIKE '$uid'";
|
||||
echo $sql_query.'<BR>';
|
||||
if(!$res_update=pg_exec($conn, $sql_query))
|
||||
" WHERE person_id ='$row_std->person_id'";
|
||||
//echo $sql_query.'<BR>';
|
||||
if(!$res_update=pg_query($conn, $sql_query))
|
||||
{
|
||||
$text.=$sql_query;
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
$update_error++;
|
||||
}
|
||||
// student
|
||||
$sql_query="UPDATE tbl_student SET matrikelnr='$row->perskz', semester=$row->semester";
|
||||
$sql_query="UPDATE public.tbl_student SET matrikelnr='$row->perskz', semester=$row->semester";
|
||||
if ($row->verband==NULL)
|
||||
$sql_query.=", verband=NULL";
|
||||
else
|
||||
@@ -177,9 +258,9 @@
|
||||
else
|
||||
$sql_query.=", gruppe='$row->gruppe'";
|
||||
$sql_query.=", studiengang_kz=".$row->kennzahl;
|
||||
$sql_query.=", updateamum=now(), updatevon='auto' WHERE uid LIKE '$uid'";
|
||||
echo $sql_query.'<BR>';
|
||||
if(!$res_update=pg_exec($conn, $sql_query))
|
||||
$sql_query.=", updateamum=now(), updatevon='auto' WHERE student_uid = '$uid'";
|
||||
//echo $sql_query.'<BR>';
|
||||
if(!$res_update=pg_query($conn, $sql_query))
|
||||
{
|
||||
$text.=$sql_query;
|
||||
$text.="\rFehler: ".pg_errormessage($conn)."\r";
|
||||
@@ -187,6 +268,7 @@
|
||||
}
|
||||
else
|
||||
$anz_update++;
|
||||
|
||||
}
|
||||
}
|
||||
// Student kommt mehrmals vor ->Warnung
|
||||
@@ -209,7 +291,7 @@
|
||||
$text.="$anz_update Studenten wurden upgedatet.\r";
|
||||
$text.="$anz_insert Studenten wurden neu angelegt.\r\r";
|
||||
$text.="\rEND OF SYNCHRONISATION\r";
|
||||
if (mail($adress,"FAS Synchro mit VileSci (Studenten)",$text,"From: vilesci@technikum-wien.at"))
|
||||
if (mail($adress,"FAS Synchro mit PORTAL (Studenten)",$text,"From: vilesci@technikum-wien.at"))
|
||||
$sendmail=true;
|
||||
else
|
||||
$sendmail=false;
|
||||
@@ -217,7 +299,7 @@
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>FAS-Synchro mit VileSci (Studenten)</title>
|
||||
<title>FAS-Synchro mit Portal (Studenten)</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
<body>
|
||||
@@ -226,7 +308,7 @@ if ($sendmail)
|
||||
echo 'Mail wurde verschickt an '.$adress.'!<br>';
|
||||
else
|
||||
echo "Mail konnte nicht verschickt werden!<br>";
|
||||
echo $text;
|
||||
echo nl2br($text);
|
||||
|
||||
?>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user