location = $location;
$this->password = $password;
$this->username = $username;
$this->header = ''
. ''
. ''.$this->username .''
. ''.$this->password.''
. '';
}
//returns a xml with information of one lecture given as int parameter
public function getPlanelementForExportById($param)
{
$soap_request = $this->header.''
. ''.$param.''
. '';
return $this->__doRequest($soap_request,"getPlanelementForExportByID");
}
public function findUnit($roomID){
$termyear = date('Y');
$termtype = date('n');
if($termtype > 3 && termtype < 10){
$termtype = 2;
}
elseif ($termtype > 10) {
$termtype = 1;
$termyear = $termyear + 1;
}
else{
$termtype = 1;
}
$soap_request = $this->header.''
. ''
. ''
. ''.$termyear.''.$termtype.''
. ''
. ''.$roomID.'';
$respons1 = $this->__doRequest($soap_request, "findUnit");
$respons2 = $this->toArray($respons1);
$id = $respons2['soapenvBody']['hisfindUnitResponse']['hisunitIds']['hisid'];
return $id;
}
public function readUnit($unit) {
$soap_request = $this->header.''
. ''.$unit.''
. '';
$respons1 = $this->__doRequest($soap_request, "readUnit");
$respons2 = $this->toArray($respons1);
$id = $respons2['soapenvBody']['hisreadUnitResponse'];
return $id;
}
//Makes a SOAP-Request
function __doRequest($request, $action){
$header = array(
"Content-type: text/xml;charset=\"utf-8\"",
"SOAPAction: \"".$action."\"",
"Content-length: ".strlen($request),
);
$soap_do = curl_init();
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_URL => $this->location ,
CURLOPT_POSTFIELDS => $request ,
CURLOPT_HTTPHEADER => $header ,
);
curl_setopt_array($soap_do , $options);
$output = curl_exec($soap_do);
if( $output === false)
{
$err = 'Curl error: ' . curl_error($soap_do);
echo $err;
}
else
{
///Operation completed successfully
}
curl_close($soap_do);
return $output;
}
//Request for a timetable with roomid as int
public function getJson($param){
//get all eventIDs in a given room
$eventIDs = $this-> findUnit($param);
//get all information on each event
foreach ($eventIDs as $each_event) {
$events[] = $this->readUnit((int) $each_event);
}
$timetable = array();
$currentWeek = $this->getCurrentWeekDates();
//Here I go over the soapresponse
foreach ($events as $event){
$title = $event['hisunit']['hisplanelements']['hisplanelement'][0]['hisdefaulttext'];
foreach($event as $subject){
$units = $subject['hisplanelements']['hisplanelement'];
foreach($units as $unit){
$dates = $unit['hisplannedDates']['hisplannedDate']['hisindividualDates']['hisindividualDate'];
foreach($dates as $date){
$roomID = $date['hisroomId'];
$datum = $date['hisexecutiondate'];
if(intval($roomID) == $param && in_array($datum,$currentWeek)){
$startTime = $date['hisstarttime'];
$endTime = $date['hisendtime'];
$json = array(
'title' => $title,
'start' => $datum." ".$startTime,
'end' => $datum." ".$endTime
);
array_push($timetable,$json);
}
}
}
}
}
return json_encode($timetable);
}
public function toArray($response){
$response = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$xml = new SimpleXMLElement($response);
$array = json_decode(json_encode((array)$xml), TRUE);
return $array;
}
//Request for a timetable with roomids as array
public function getJsons($param){
//get all eventIDs in a given room
foreach ($param as $ID) {
$eventIDs = $this-> findUnit($ID);
}
$eventIDs = array_unique($eventIDs);
//get all information on each event
foreach ($eventIDs as $each_event) {
$events[] = $this->readUnit((int) $each_event);
}
$ttables = [];
$currentWeek = $this->getCurrentWeekDates();
foreach ($param as $room){
$timetable = array();
//Here I go over the soapresponse
foreach ($events as $event){
$title = $event['hisunit']['hisplanelements']['hisplanelement'][0]['hisdefaulttext'];
foreach($event as $subject){
$units = $subject['hisplanelements']['hisplanelement'];
foreach($units as $unit){
$dates = $unit['hisplannedDates']['hisplannedDate']['hisindividualDates']['hisindividualDate'];
foreach($dates as $date){
$roomID = $date['hisroomId'];
$datum = $date['hisexecutiondate'];
if(intval($roomID) == $room && in_array($datum,$currentWeek)){
$startTime = $date['hisstarttime'];
$endTime = $date['hisendtime'];
$json = array(
'title' => $title,
'start' => $datum." ".$startTime,
'end' => $datum." ".$endTime
);
$timetable[]= $json;
}
}
}
}
}
$ttables[$room] =json_encode($timetable);
}
return $ttables;
}
function getCurrentWeekDates()
{
$DateArray = array();
$startdate = strtotime('Now');
for($i=0 ;$i<=7; $i++) {
$DateArray[] = date('Y-m-d', strtotime("+ {$i} day", $startdate));
}
return $DateArray;
}
}
$params = array("planelementId"=>42);
try {
}
catch (Exception $ex) {
var_dump($ex);
}
?>