Soap Schnittstelle fuer Personensuche

This commit is contained in:
Stefan Puraner
2013-09-11 13:23:12 +00:00
parent 16c7ef5c6a
commit 2b95b59e62
5 changed files with 495 additions and 2 deletions
+2 -2
View File
@@ -144,7 +144,7 @@ class person extends basis_db
return false;
}
}
/**
*
* Löscht den Datensatz mit der übergebenen person_id
@@ -790,5 +790,5 @@ class person extends basis_db
return true;
}
}
}
?>
+1
View File
@@ -8,6 +8,7 @@
<li><a href="soap_test_ort.php">Ort / Raum</a></li>
<li><a href="soap_test_student.php">Studierendendaten</a></li>
<li><a href="soap_test_lvplan.php">LV-Plan</a></li>
<li><a href="soap_test_person.php">Personen</a></li>
</ul>
<h2>Sonstiges</h2>
<ul>
+163
View File
@@ -0,0 +1,163 @@
<?php
/* Copyright (C) 2012 FH 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: Andreas Oesterreicher <oesi@technikum-wien.at>.
*/
/**
* Webservice fuer Mitarbeiter
*
*/
require_once('../config/vilesci.config.inc.php');
require_once('../include/basis_db.class.php');
require_once('../include/functions.inc.php');
require_once('../include/webservicerecht.class.php');
require_once('../include/person.class.php');
require_once('../include/benutzer.class.php');
ini_set("soap.wsdl_cache_enabled", "0");
$SOAPServer = new SoapServer(APP_ROOT."/soap/person.wsdl.php?".microtime(true));
$SOAPServer->addFunction("getPersonFromUID");
$SOAPServer->addFunction("searchPerson");
$SOAPServer->handle();
/**
*
* Funktion getPersonFromUID liefert eine Person zurück
* @param uid - uid der gesuchten Person
* @param authentifizierung - Array mit Username und Passwort
*
* Berechtigung:
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','vorname');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','nachname');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','titelpre');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','titelpost');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','uid');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','email');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','getPersonFromUID','status');
*/
function getPersonFromUID($uid, $authentifizierung)
{
$user = $authentifizierung->username;
$passwort = $authentifizierung->passwort;
// User authentifizieren
if(!check_user($user, $passwort))
return new SoapFault("Server", "Invalid Credentials");
// darf user überhaupt was von Methode sehen
$recht = new webservicerecht();
if(!$recht->isUserAuthorized($user, 'getPersonFromUID'))
return new SoapFault("Server", "No permission");
//Personendaten laden
$person = new benutzer();
if(!$person->load($uid))
return new SoapFault("Server", "Error loading Data");
class foo{};
$obj = new foo();
$obj->vorname = $person->vorname;
$obj->nachname = $person->nachname;
$obj->titelpre = $person->titelpre;
$obj->titelpost = $person->titelpost;
$obj->uid = $person->uid;
$obj->email = $person->uid.'@'.DOMAIN;
if(is_null($row->mitarbeiter_uid))
{
$obj->status = "Mitarbeiter";
}
else
{
$obj->status = "Student";
}
// lösche alle Attribute für die user keine Berechtigung hat
$obj = $recht->clearResponse($user, 'getPersonFromUID', $obj);
return $obj;
}
/**
*
* Funktion searchPerson liefert eine Person zurück
* @param searchItems - Array mit Suchbegriffen
* @param authentifizierung - Array mit Username und Passwort
*
* Berechtigung:
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','vorname');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','nachname');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','titelpre');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','titelpost');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','uid');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','email');
INSERT INTO system.tbl_webservicerecht(berechtigung_kurzbz, methode, attribut) VALUES('soap/person','searchPerson','status');
*/
function searchPerson($searchItems, $authentifizierung){
$user = $authentifizierung->username;
$passwort = $authentifizierung->passwort;
// User authentifizieren
if(!check_user($user, $passwort))
return new SoapFault("Server", "Invalid Credentials");
// darf user überhaupt was von Methode sehen
$recht = new webservicerecht();
if(!$recht->isUserAuthorized($user, 'searchPerson'))
return new SoapFault("Server", "No permission");
//nach Personen suchen
$person = new benutzer();
$search = explode(' ',TRIM($searchItems));
if(!$person->search($search))
return new SoapFault("Server", "Error loading Data");
class foo{};
$obj = new foo();
$return = array();
foreach($person->result as $row)
{
$obj = new foo();
$obj->vorname = $row->vorname;
$obj->nachname = $row->nachname;
$obj->titelpre = $row->titelpre;
$obj->titelpost = $row->titelpost;
$obj->uid = $row->uid;
$obj->email = $row->uid.'@'.DOMAIN;
if(is_null($row->mitarbeiter_uid))
{
$obj->status = "Mitarbeiter";
}
else
{
$obj->status = "Student";
}
// lösche alle Attribute für die user keine Berechtigung hat
$return[] = $recht->clearResponse($user, 'searchPerson', $obj);
}
return $return;
}
?>
+77
View File
@@ -0,0 +1,77 @@
<?php
require_once('../config/vilesci.config.inc.php');
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='utf-8' ?>";
?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://technikum-wien.at"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://technikum-wien.at"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:message name="GetPersonFromUIDRequest">
<wsdl:part minOccurs="1" maxOccurs="1" name="uid" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="authentifizierung" type="tns:GetAuthentifizierung"/>
</wsdl:message>
<wsdl:message name="GetPersonFromUIDResponse">
<wsdl:part minOccurs="0" maxOccurs="1" name="GetPersonFromUID" type="tns:Person"/>
</wsdl:message>
<wsdl:message name="SearchPersonRequest">
<wsdl:part minOccurs="1" maxOccurs="1" name="searchItems" type="s:string"/>
<wsdl:part minOccurs="0" maxOccurs="1" name="authentifizierung" type="tns:GetAuthentifizierung"/>
</wsdl:message>
<wsdl:message name="SearchPersonResponse">
<wsdl:part minOccurs="0" maxOccurs="1" name="Person" type="tns:ArrayOfPerson"/>
</wsdl:message>
<s:complexType name="GetAuthentifizierung">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="passwort" type="s:string"/>
</s:sequence>
</s:complexType>
<wsdl:portType name="ConfigPortType">
<wsdl:operation name="GetPersonFromUID">
<wsdl:input message="tns:GetPersonFromUIDRequest"/>
<wsdl:output message="tns:GetPersonFromUIDResponse"/>
</wsdl:operation>
<wsdl:operation name="SearchPerson">
<wsdl:input message="tns:SearchPersonRequest"/>
<wsdl:output message="tns:SearchPersonResponse"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ConfigBinding" type="tns:ConfigPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetPersonFromUID">
<soap:operation soapAction="<?php echo APP_ROOT."soap/getPersonFromUID";?>" />
<wsdl:input>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="SearchPerson">
<soap:operation soapAction="<?php echo APP_ROOT."soap/searchPerson";?>" />
<wsdl:input>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:input>
<wsdl:output>
<soap:body use="encoded" namespace="http://technikum-wien.at" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Person">
<wsdl:port name="ConfigWebservicePort" binding="tns:ConfigBinding">
<soap:address location="<?php echo APP_ROOT."soap/person.soap.php?".microtime();?>"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
+252
View File
@@ -0,0 +1,252 @@
<?php
/* Copyright (C) 2012 FH 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: Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
*/
/**
* Test Client fuer Person Webservice
*/
require_once('../config/vilesci.config.inc.php');
require_once('../include/functions.inc.php');
require_once('../include/basis_db.class.php');
$db = new basis_db();
$method = (isset($_GET['method'])?$_GET['method']:'getPersonFromUID');
$getuid = get_uid();
if(!check_lektor($getuid) && !check_student($getuid))
die('Sie haben keine Berechtigung für diese Seite');
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript" src="../include/js/jqSOAPClient.js"></script>
<script type="text/javascript" src="../include/js/jquery.js"></script>
<script type="text/javascript" src="../include/js/jqXMLUtils.js"></script>
<title>SOAP TestClient für Personen</title>
</head>
<body>
<h1>Person Webservice</h1>
Liefert Informationen über Personen
<h2>Funktionen</h2>
<ul>
<li><a href ="<?php echo $_SERVER['PHP_SELF'].'?method=getPersonFromUID'?>">getPersonFromUID</a> - Personendaten anhand der UID laden</li>
<li><a href ="<?php echo $_SERVER['PHP_SELF'].'?method=searchPerson'?>">searchPerson</a> - Personendaten anhand von Vorname, Nachname oder UID suchen</li>
</ul>
<br>
<a href ="<?php echo APP_ROOT.'soap/person.wsdl.php'?>">Show WSDL </a>
<br>
<h2>Testformular</h2>
<?php
if($method=='getPersonFromUID')
{
echo'
<form action="'.$_SERVER["PHP_SELF"].'?method=getPersonFromUID" method="post">
<table border="0" cellpadding="5" cellspacing="0" bgcolor="#E0E0E0">
<tr>
<td align="right">Username* :</td>
<td><input id="username" name="username" type="text" size="30" maxlength="255" value="'.$db->convert_html_chars((isset($_REQUEST['username']) ? $_REQUEST['username'] : "")).'"></td>
</tr>
<tr>
<td align="right">Passwort* :</td>
<td><input id="passwort" name="passwort" type="password" size="30" maxlength="255" value="'.$db->convert_html_chars((isset($_REQUEST['passwort']) ? $_REQUEST['passwort'] : "")).'"></td>
</tr>
<tr>
<td align="right">UID* :</td>
<td><input id="uid" name="uid" type="text" size="30" maxlength="10" value="'.$db->convert_html_chars((isset($_REQUEST['uid']) ? $_REQUEST['uid'] : "")).'"></td>
</tr>
<tr>
<td align="right"></td>
<td>
<input type="submit" value="Absenden (PHP)" name="submit">
<input type="button" onclick="sendSoap();" value="Absenden (JS)">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function gettimestamp()
{
var now = new Date();
var ret = now.getHours()*60*60*60;
ret = ret + now.getMinutes()*60*60;
ret = ret + now.getSeconds()*60;
ret = ret + now.getMilliseconds();
return ret;
}
function sendSoap()
{
user = document.getElementById("username").value;
passwort = document.getElementById("passwort").value;
uid = document.getElementById("uid").value;
var soapBody = new SOAPObject("getPersonFromUID");
var authentifizierung = new SOAPObject("authentifizierung");
authentifizierung.appendChild(new SOAPObject("username")).val(user);
authentifizierung.appendChild(new SOAPObject("passwort")).val(passwort);
soapBody.appendChild(new SOAPObject("uid")).val(uid);
soapBody.appendChild(authentifizierung);
var sr = new SOAPRequest("getPersonFromUID",soapBody);
SOAPClient.Proxy="'.APP_ROOT.'/soap/person.soap.php?"+gettimestamp();
SOAPClient.SendRequest(sr, clb_save);
}
function clb_save(respObj)
{
try
{
data = JSON.stringify(respObj.Body[0]);
document.getElementById("output").innerHTML="<pre>"+data+"<pre>";
alert("ok");
}
catch(e)
{
alert(e);
var fehler = respObj.Body[0].Fault[0].faultstring[0].Text;
alert("Fehler: "+fehler);
}
}
</script>
';
}
elseif($method=='searchPerson')
{
echo'
<form action="'.$_SERVER["PHP_SELF"].'?method=searchPerson" method="post">
<table border="0" cellpadding="5" cellspacing="0" bgcolor="#E0E0E0">
<tr>
<td align="right">Username* :</td>
<td><input id="username" name="username" type="text" size="30" maxlength="255" value="'.$db->convert_html_chars((isset($_REQUEST['username']) ? $_REQUEST['username'] : "")).'"></td>
</tr>
<tr>
<td align="right">Passwort* :</td>
<td><input id="passwort" name="passwort" type="password" size="30" maxlength="255" value="'.$db->convert_html_chars((isset($_REQUEST['passwort']) ? $_REQUEST['passwort'] : "")).'"></td>
</tr>
<tr>
<td align="right">Suchbegriff* :</td>
<td><input id="searchItems" name="searchItems" type="text" size="30" maxlength="255" value="'.$db->convert_html_chars((isset($_REQUEST['searchItems']) ? $_REQUEST['searchItems'] : "")).'"></td>
</tr>
<tr>
<td align="right"></td>
<td>
<input type="submit" value="Absenden (PHP)" name="submit">
<input type="button" onclick="sendSoap();" value="Absenden (JS)">
</td>
</tr>
</table>
</form>';
echo '
<script type="text/javascript">
function gettimestamp()
{
var now = new Date();
var ret = now.getHours()*60*60*60;
ret = ret + now.getMinutes()*60*60;
ret = ret + now.getSeconds()*60;
ret = ret + now.getMilliseconds();
return ret;
}
function sendSoap()
{
user = document.getElementById("username").value;
passwort = document.getElementById("passwort").value;
var soapBody = new SOAPObject("searchPerson");
var authentifizierung = new SOAPObject("authentifizierung");
authentifizierung.appendChild(new SOAPObject("username")).val(user);
authentifizierung.appendChild(new SOAPObject("passwort")).val(passwort);
soapBody.appendChild(authentifizierung);
var sr = new SOAPRequest("searchPerson",soapBody);
SOAPClient.Proxy="'.APP_ROOT.'/soap/person.soap.php?"+gettimestamp();
SOAPClient.SendRequest(sr, clb_save);
}
function clb_save(respObj)
{
try
{
data = JSON.stringify(respObj.Body[0]);
document.getElementById("output").innerHTML="<pre>"+data+"<pre>";
alert("ok");
}
catch(e)
{
alert(e);
var fehler = respObj.Body[0].Fault[0].faultstring[0].Text;
alert("Fehler: "+fehler);
}
}
</script>
';
}
echo '<a href="index.html">Zurück zur Übersicht</a><br>';
echo '<div id="output">';
class foo {};
if(isset($_REQUEST['submit']) && $_GET['method']=='getPersonFromUID')
{
$client = new SoapClient(APP_ROOT."/soap/person.wsdl.php?".microtime(true));
try
{
$authentifizierung = new foo();
$authentifizierung->username=$_REQUEST['username'];
$authentifizierung->passwort=$_REQUEST['passwort'];
$response = $client->getPersonFromUID($_REQUEST['uid'], $authentifizierung);
var_dump($response);
}
catch(SoapFault $fault)
{
echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR;
}
}
if(isset($_REQUEST['submit']) && $_GET['method']=='searchPerson')
{
$client = new SoapClient(APP_ROOT."/soap/person.wsdl.php?".microtime(true));
try
{
$authentifizierung = new foo();
$authentifizierung->username=$_REQUEST['username'];
$authentifizierung->passwort=$_REQUEST['passwort'];
$response = $client->searchPerson($_REQUEST['searchItems'],$authentifizierung);
var_dump($response);
}
catch(SoapFault $fault)
{
echo "SOAP Fault: (faultcode: {$fault->faultcode}, faultstring: {$fault->faultstring})", E_USER_ERROR;
}
}
echo '</div>';
?>