147 lines
4.0 KiB
PHP
147 lines
4.0 KiB
PHP
<?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");
|
|
|
|
$this->layout->set("filter", $this->request->filter);
|
|
if($this->request->filter) {
|
|
$filter = $this->getPreparedFilter($this->request->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 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");
|
|
}
|
|
|
|
}
|
|
} |