Files
thetool/application/Admin/AdminController.php
2023-05-05 15:08:41 +02:00

109 lines
3.2 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());
}
protected function ivtDownloadActiveProducts() {
$ivtproducts = IvtProductModel::getAll();
$products = [];
foreach($ivtproducts as $product) {
$active_count = IvtCustomerProductModel::count(['pid' => $product->id]);
if(!$active_count) continue;
$new_product = [];
$new_product["product"] = $product;
$new_product["count"] = $active_count;
$new_product["customer"] = false;
if($active_count == 1) {
$cp = IvtCustomerProductModel::getFirst(["pid" => $product->id]);
//var_dump($cp);exit;
$customer = $cp->customer;
//var_dump($customer);exit;
$new_product["customer"] = ($customer->company) ? $customer->company : $customer->firstname." ".$customer->surname;
}
$products[$product->id] = $new_product;
}
$this->layout()->setTemplate("Admin/ivt_active_products.csv");
$this->layout()->set("products", $products);
}
}