289 lines
8.0 KiB
PHP
289 lines
8.0 KiB
PHP
<?php
|
|
|
|
require_once APPDIR."/OpenAccessId/helper/rimo.php";
|
|
|
|
class OpenAccessIdController extends mfBaseController {
|
|
|
|
protected function init() {
|
|
$this->needlogin=true;
|
|
$me = new User();
|
|
$me->loadMe();
|
|
$this->me = $me;
|
|
$this->layout()->set("me",$me);
|
|
|
|
if(!$me->is(["Admin"])) {
|
|
$this->redirect("Dashboard");
|
|
}
|
|
}
|
|
|
|
protected function indexAction() {
|
|
$this->layout()->setTemplate("OpenAccessId/Index");
|
|
|
|
if($this->request->resetFilter) {
|
|
unset($_SESSION[MFAPPNAME.'-OpenAccessId-filter']);
|
|
}
|
|
|
|
$filter = [];
|
|
if(is_array($this->request->filter)) {
|
|
$filter = $this->request->filter;
|
|
$_SESSION[MFAPPNAME.'-OpenAccessId-filter'] = $filter;
|
|
} else {
|
|
if(array_key_exists(MFAPPNAME.'-OpenAccessId-filter', $_SESSION) && count($_SESSION[MFAPPNAME.'-OpenAccessId-filter'])) {
|
|
$filter = $_SESSION[MFAPPNAME.'-OpenAccessId-filter'];
|
|
}
|
|
}
|
|
|
|
$this->layout->set("filter", $filter);
|
|
$filter = $this->getPreparedFilter($filter);
|
|
|
|
// pagination defaults
|
|
$pagination = [];
|
|
$pagination['start'] = 0;
|
|
$pagination['count'] = 20;
|
|
$pagination['maxItems'] = 0;
|
|
|
|
if(is_numeric($this->request->s)) {
|
|
$pagination['start'] = intval($this->request->s);
|
|
}
|
|
|
|
$pagination['maxItems'] = OpenAccessIdModel::count($filter);
|
|
$oaids = OpenAccessIdModel::search($filter, $pagination);
|
|
$this->layout()->set("pagination", $pagination);
|
|
|
|
$this->layout()->set("oaids", $oaids);
|
|
|
|
$netowners = AddressModel::search(["addresstype" => ["netowner"]]);
|
|
$this->layout()->set("netowners", $netowners);
|
|
|
|
}
|
|
|
|
private function getPreparedFilter($filter) {
|
|
$new_filter = [];
|
|
|
|
if(array_key_exists("oaid", $filter) && $filter['oaid']) {
|
|
$new_filter["oaid"] = "%".$filter['oaid']."%";
|
|
unset($filter['oaid']);
|
|
}
|
|
|
|
if(array_key_exists("origin_id", $filter) && $filter['origin_id']) {
|
|
$new_filter["origin_id"] = "%".$filter['origin_id']."%";
|
|
unset($filter['origin_id']);
|
|
}
|
|
|
|
if(array_key_exists("assigned", $filter) && $filter['assigned']) {
|
|
if($filter['assigned'] == "yes") {
|
|
$new_filter['assigned'] = true;
|
|
} elseif($filter['assigned'] == "no") {
|
|
$new_filter['assigned'] = false;
|
|
}
|
|
unset($filter['assigned']);
|
|
|
|
}
|
|
|
|
foreach($filter as $name => $value) {
|
|
$new_filter[$name] = $value;
|
|
}
|
|
|
|
return $new_filter;
|
|
}
|
|
|
|
protected function releaseAction() {
|
|
$id = $this->request->id;
|
|
if(!$id || $id <1) {
|
|
$this->layout()->setFlash("Ungültige OAID", "error");
|
|
$this->redirect("OpenAccessId");
|
|
}
|
|
|
|
$oaid = new OpenAccessId($id);
|
|
if(!$oaid->id) {
|
|
$this->layout()->setFlash("Ungültige OAID", "error");
|
|
$this->redirect("OpenAccessId");
|
|
}
|
|
|
|
$oaid->startTransaction();
|
|
|
|
// remove from Preorders
|
|
foreach(PreorderModel::search(["oaid" => $oaid->oaid]) as $preorder) {
|
|
$preorder->oaid = null;
|
|
$preorder->save(["no_oaid_update" => true, "dont_cascade" => true]);
|
|
}
|
|
|
|
// remove from Wohneinheiten
|
|
foreach(ADBWohneinheitModel::search(["oaid" => $oaid->oaid]) as $unit) {
|
|
$unit->oaid = null;
|
|
$unit->save(["no_updates" => 1]);
|
|
|
|
$ftu_id = $unit->ftu_data["id"];
|
|
if($ftu_id) {
|
|
$this->log->debug(__METHOD__.": trying to unassign Oaid ".$oaid->oaid." from Rimo FTU ".$ftu_id);
|
|
Rimoapi::unassignOaid($oaid->oaid, $ftu_id);
|
|
}
|
|
}
|
|
|
|
|
|
$oaid->assigned = 0;
|
|
$oaid->adb_wohneinheit_id = null;
|
|
$oaid->exported = 0;
|
|
$oaid->exported_to = null;
|
|
$oaid->export_data = null;
|
|
$oaid->address = null;
|
|
$oaid->unit_string = null;
|
|
$oaid->save();
|
|
|
|
$oaid->commitTransaction();
|
|
|
|
$this->layout()->setFlash("OAID erfolgreich freigegeben");
|
|
$this->redirect("OpenAccessId");
|
|
}
|
|
|
|
protected function changeADBWohneinheitAction() {
|
|
$this->layout()->setTemplate("OpenAccessId/ChangeUnit");
|
|
$id = $this->request->id;
|
|
if(!$id || $id <1) {
|
|
$this->layout()->setFlash("Ungültige OAID", "error");
|
|
$this->redirect("OpenAccessId");
|
|
}
|
|
|
|
$oaid = new OpenAccessId($id);
|
|
if(!$oaid->id) {
|
|
$this->layout()->setFlash("Ungültige OAID", "error");
|
|
$this->redirect("OpenAccessId");
|
|
}
|
|
|
|
$this->layout()->set("oaid", $oaid);
|
|
|
|
if(!$this->request->new_unit_id) {
|
|
return true;
|
|
}
|
|
|
|
// get old and new unit_id
|
|
$old_unit = ADBWohneinheitModel::getFirst(["oaid" => $oaid->oaid]);
|
|
$new_unit = new ADBWohneinheit($this->request->new_unit_id);
|
|
if(!$new_unit->id) {
|
|
$new_unit = false;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if($old_unit) {
|
|
$old_preorder = PreorderModel::getFirst(["adb_wohneinheit_id" => $old_unit->id]);
|
|
if($old_preorder) {
|
|
// remove oaid from preorder
|
|
$old_preorder->oaid = null;
|
|
$old_preorder->save();
|
|
}
|
|
|
|
//$rimo = new OpenAccessId_Helper_Rimo($oaid->oaid);
|
|
|
|
// unassign oaid from rimo ftu
|
|
//$rimo->unassignOaid($oaid)
|
|
// get oaid from rimo
|
|
// unassign ftu from aoid
|
|
// remove oaid from old unit
|
|
|
|
// remove meta data from oaid
|
|
$oaid->assigned = 0;
|
|
$oaid->adb_wohneinheit_id = null;
|
|
$oaid->termination_id = null;
|
|
$oaid->exported = 0;
|
|
$oaid->exported_to = null;
|
|
$oaid->exported_data = null;
|
|
$oaid->address = null;
|
|
$oaid->unit_string = null;
|
|
$oaid->save();
|
|
}
|
|
|
|
if($new_unit) {
|
|
$new_preorder = PreorderModel::getFirst(["adb_wohneinheit_id" => $new_unit->id]);
|
|
// add oaid to new unit
|
|
// assign oaid to new ftu in rimo
|
|
if($new_preorder) {
|
|
// add oaid to preorder
|
|
$new_preorder->oaid = $oaid->oaid;
|
|
}
|
|
// save metadata to oaid
|
|
$oaid->assigned = date("U");
|
|
$oaid->adb_wohneinheit_id = $new_unit->id;
|
|
$oaid->termination_id = null;
|
|
$oaid->exported = date("U");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
protected function importerAction() {
|
|
$this->layout()->setTemplate("OpenAccessId/Importer");
|
|
|
|
$netowners = AddressModel::search(["addresstype" => ["netowner"]]);
|
|
$this->layout()->set("netowners", $netowners);
|
|
}
|
|
|
|
protected function import() {
|
|
//var_dump($this->request);exit;
|
|
$r = $this->request;
|
|
|
|
$origin = false;
|
|
|
|
switch($r->origin) {
|
|
case "ofaa":
|
|
$origin = "ofaa";
|
|
break;
|
|
case "thetool":
|
|
$origin = "thetool";
|
|
break;
|
|
default:
|
|
$this->layout()->setFlash("Unbekannte Herkunft!", "error");
|
|
$this->redirect("OpenAccessId", "Importer");
|
|
}
|
|
|
|
$origin_id = $r->origin_id;
|
|
|
|
$owner_id = $r->owner_id;
|
|
if(!$owner_id) {
|
|
$this->layout()->setFlash("Besitzer kann nicht leer sein!", "error");
|
|
$this->redirect("OpenAccessId", "Importer");
|
|
}
|
|
|
|
if($r->active == 1) {
|
|
$active = 1;
|
|
} else {
|
|
$active = 0;
|
|
}
|
|
|
|
// check for uploaded file
|
|
if(is_array($_FILES) && array_key_exists("oaidcsv", $_FILES) && !$_FILES['oaidcsv']['error']) {
|
|
// look for uploaded import file
|
|
try {
|
|
// returns File object or throws Exception on error
|
|
$file = mfUpload::handleFormUpload("oaidcsv");
|
|
} catch (Exception $ex) {
|
|
$this->layout()->setFlash("Fehler beim Dateiupload: ".$ex->getMessage(), "error");
|
|
$this->redirect("OpenAccessId", "Importer");
|
|
}
|
|
|
|
//var_dump($file);exit;
|
|
$oaid = new OpenAccessId();
|
|
$import_count = $oaid->importFromCSV($file, [
|
|
"active" => $active,
|
|
"origin" => $origin,
|
|
"origin_id" => ($origin_id) ? $origin_id : null,
|
|
"owner_id" => $owner_id,
|
|
]);
|
|
|
|
$file->delete();
|
|
|
|
$this->layout()->setFlash("$import_count OAIDs erfolgreich importiert!", "success");
|
|
$this->redirect("OpenAccessId");
|
|
|
|
} else {
|
|
var_dump($_FILES);exit;
|
|
$this->layout()->setFlash("Fehler beim Dateiupload: ".$ex->getMessage(), "error");
|
|
$this->redirect("OpenAccessId", "Importer");
|
|
}
|
|
|
|
}
|
|
} |