Files
thetool/application/Admin/AdminController.php
2023-05-05 13:53:30 +02:00

80 lines
2.3 KiB
PHP

<?php
class AdminController 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("Admin/Index");
}
protected function createNetworkAddressForNetowner() {
$i = 0;
foreach(NetworkModel::getAll() as $network) {
$netaddress = NetworkAddressModel::getFirst(["network_id" => $network->id, "address_id" => $network->owner_id, "addresstype" => "netowner"]);
if(!$netaddress) {
$netaddress = NetworkAddressModel::create([
'network_id' => $network->id,
'address_id' => $network->owner_id,
'type' => "netowner"
]);
$netaddress->save();
$i++;
}
}
$this->layout()->setFlash("$i NetworkAddress Objekte angelegt.", "success");
$this->redirect("Admin");
}
protected function ivtImportMatchProductsAction() {
$this->layout()->setTemplate("Admin/ivtimport_product_match");
$filter_name = MFAPPNAME.'-Admin-ivtimport_product-filter';
if($this->request->resetFilter) {
unset($_SESSION[$filter_name]);
}
$filter = [];
if(is_array($this->request->filter)) {
$filter = $this->request->filter;
$_SESSION[$filter_name] = $filter;
} else {
if(array_key_exists($filter_name, $_SESSION) && count($_SESSION[$filter_name])) {
$filter = $_SESSION[$filter_name];
}
}
$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);
}
//var_dump($filter);exit;
$pagination['maxItems'] = IvtProductModel::count($filter);
$ivtproducts = IvtProductModel::search($filter, $pagination);
$this->layout()->set("pagination", $pagination);
$this->layout()->set("ivtproducts", $ivtproducts);
$this->layout()->set("products", ProductModel::getActive());
}
}