added filter to Address
This commit is contained in:
@@ -27,16 +27,120 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<h4 class="header-title mb-3">Filter</h4>
|
||||
|
||||
<form method="get" action="<?=self::getUrl("Address")?>">
|
||||
<div class="row">
|
||||
<?php if($me->is("Admin")): ?>
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_addresstype">Rolle</label>
|
||||
<select name="filter[addresstype][]" id="filter_addresstype" class="select2 form-control select2-multiple" multiple="multiple">
|
||||
<option value="systemowner" <?=(in_array("systemowner", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("systemowner")?></option>
|
||||
<option value="netowner" <?=(in_array("netowner", $filter["addresstype"])) ? "selected='selected'" : "netowner"?>><?=__("netowner")?></option>
|
||||
<option value="salespartner" <?=(in_array("salespartner", $filter["addresstype"])) ? "selected='selected'" : "salespartner"?>><?=__("salespartner")?></option>
|
||||
<option value="pipeworker" <?=(in_array("pipeworker", $filter["addresstype"])) ? "selected='selected'" : "pipeworker"?>><?=__("pipeworker")?></option>
|
||||
<option value="lineworker" <?=(in_array("lineworker", $filter["addresstype"])) ? "selected='selected'" : "lineworker"?>><?=__("lineworker")?></option>
|
||||
<option value="pipeplanner" <?=(in_array("pipeplanner", $filter["addresstype"])) ? "selected='selected'" : "pipeplanner"?>><?=__("pipeplanner")?></option>
|
||||
<option value="lineplanner" <?=(in_array("lineplanner", $filter["addresstype"])) ? "selected='selected'" : "lineplanner"?>><?=__("lineplanner")?></option>
|
||||
<option value="netoperator" <?=(in_array("netoperator", $filter["addresstype"])) ? "selected='selected'" : "netoperator"?>><?=__("netoperator")?></option>
|
||||
<option value="support" <?=(in_array("support", $filter["addresstype"])) ? "selected='selected'" : "support"?>><?=__("support")?></option>
|
||||
<option value="billing" <?=(in_array("billing", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("billing")?></option>
|
||||
<option value="employee" <?=(in_array("employee", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("employee")?></option>
|
||||
<option value="customer" <?=(in_array("customer", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("customer")?></option>
|
||||
<option value="supplier" <?=(in_array("supplier", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("supplier")?></option>
|
||||
<option value="contact" <?=(in_array("contact", $filter["addresstype"])) ? "selected='selected'" : ""?>><?=__("contact")?></option>
|
||||
</select>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_customer_number">Kundennummer</label>
|
||||
<input type="text" class="form-control" name="filter[customer_number]" id="filter_customer_number" value="<?=$filter['customer_number']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_spin">Service PIN</label>
|
||||
<input type="text" class="form-control" name="filter[spin]" id="filter_spin" value="<?=$filter['spin']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_company">Firma</label>
|
||||
<input type="text" class="form-control" name="filter[company]" id="filter_company" value="<?=$filter['company']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_firstname">Vorname</label>
|
||||
<input type="text" class="form-control" name="filter[firstname]" id="filter_firstname" value="<?=$filter['firstname']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_lastname">Nachname</label>
|
||||
<input type="text" class="form-control" name="filter[lastname]" id="filter_lastname" value="<?=$filter['lastname']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-2">
|
||||
<label class="form-label" for="filter_street">Straße</label>
|
||||
<input type="text" class="form-control" name="filter[street]" id="filter_street" value="<?=$filter['street']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_zip">PLZ</label>
|
||||
<input type="text" class="form-control" name="filter[zip]" id="filter_zip" value="<?=$filter['zip']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_city">Ort</label>
|
||||
<input type="text" class="form-control" name="filter[city]" id="filter_city" value="<?=$filter['city']?>" />
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_country">Land</label>
|
||||
<input type="text" class="form-control" name="filter[country]" id="filter_country" value="<?=$filter['country']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_pfm">Telefon/Fax/Mobil</label>
|
||||
<input type="text" class="form-control" name="filter[pfm]" id="filter_pfm" value="<?=$filter['pfm']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_email">Email</label>
|
||||
<input type="text" class="form-control" name="filter[email]" id="filter_email" value="<?=$filter['email']?>" />
|
||||
</div>
|
||||
|
||||
<div class="col-1">
|
||||
<label class="form-label" for="filter_note">Notiz</label>
|
||||
<input type="text" class="form-control" name="filter[note]" id="filter_note" value="<?=$filter['note']?>" />
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
<div class="row mt-2">
|
||||
<div class="col">
|
||||
<button type="submit" class="btn btn-primary">Filter anwenden</button>
|
||||
<a class="btn btn-secondary" href="<?=self::getUrl("Address")?>">Filter zurücksetzen</a>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body mb-3">
|
||||
<div class="float-left">
|
||||
<h4 class="header-title">Liste aller Personen & Firmen</h4>
|
||||
<?php if(is_array($filter) && count($filter)): ?>
|
||||
<p class="sub-header">
|
||||
<?php if(array_key_exists("parents_only", $filter) && $filter['parents_only'] == 1): ?>
|
||||
Zeige nur Personen und Firmen ohne Zugehörigkeit an. <a href="<?=self::getUrl("Address", "Index", ['filter' => array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen</a><br />
|
||||
<?php else: ?>
|
||||
<?php if(array_key_exists("parents_only", $filter) && $filter['parents_only'] == 0): ?>
|
||||
Zeige alle Personen und Firmen<br />
|
||||
<?php else: ?>
|
||||
Zeige nur Personen und Firmen ohne Zugehörigkeit an. <a href="<?=self::getUrl("Address", "Index", ['filter' => array_merge($filter, ["parents_only" => 0])])?>">Alle anzeigen</a><br />
|
||||
<?php endif; ?>
|
||||
<?php if(is_array($filter['addresstype']) && count($filter['addresstype'])): ?>
|
||||
Gefiltert nach Rolle: <?=implode(", ", $types)?><br />
|
||||
@@ -48,6 +152,35 @@
|
||||
<a class="btn btn-primary" href="<?=self::getUrl("Address", "add")?>"><i class="fas fa-plus"></i> Neue Person/Firma anlegen</a>
|
||||
</div>
|
||||
|
||||
<?php if($pagination['maxItems'] > $pagination['count']): ?>
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center mb-1">
|
||||
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
|
||||
</li>
|
||||
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
|
||||
</li>
|
||||
<?php for($i = 0; $i < ($pagination['maxItems'] / $pagination['count']); $i++): ?>
|
||||
<li class="page-item <?=($pagination['start'] == $i*$pagination['count']) ? "disabled font-weight-bold" : ""?>"><a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $i*$pagination['count'], "filter" => $filter])?>"><?=$i+1?></a></li>
|
||||
<?php endfor; ?>
|
||||
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Vor</a>
|
||||
</li>
|
||||
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
<div class="pagination justify-content-center">
|
||||
<?php if($pagination['maxItems']): ?>
|
||||
Adressen <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
|
||||
<?php else: ?>
|
||||
Keine Adressen gefunden
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<table class="table table-striped table-hover">
|
||||
<tr>
|
||||
<th>Typ</th>
|
||||
@@ -93,10 +226,45 @@
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<?php if($pagination['maxItems'] > $pagination['count']): ?>
|
||||
<nav>
|
||||
<ul class="pagination justify-content-center mb-1">
|
||||
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod, "Index", ["filter" => $filter])?>" tabindex="-1">Erste</a>
|
||||
</li>
|
||||
<li class="page-item <?=($pagination['start'] - $pagination['count'] < 0) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] - $pagination['count'], "filter" => $filter])?>" tabindex="-1">Zurück</a>
|
||||
</li>
|
||||
<?php for($i = 0; $i < ($pagination['maxItems'] / $pagination['count']); $i++): ?>
|
||||
<li class="page-item <?=($pagination['start'] == $i*$pagination['count']) ? "disabled font-weight-bold" : ""?>"><a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $i*$pagination['count'], "filter" => $filter])?>"><?=$i+1?></a></li>
|
||||
<?php endfor; ?>
|
||||
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => $pagination['start'] + $pagination['count'], "filter" => $filter])?>">Vor</a>
|
||||
</li>
|
||||
<li class="page-item <?=($pagination['maxItems'] / ($pagination['start'] + $pagination['count']) < 1) ? "disabled" : ""?>">
|
||||
<a class="page-link" href="<?=$this->getUrl($Mod,"Index",['s' => ($pagination['maxItems'] - $pagination['maxItems'] % $pagination['count']), "filter" => $filter])?>">Letzte</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
<?php endif; ?>
|
||||
<div class="pagination justify-content-center">
|
||||
<?php if($pagination['maxItems']): ?>
|
||||
Adressen <?=$pagination['start']+1?> bis <?=($pagination['start'] + $pagination['count'] > $pagination['maxItems']) ? $pagination['maxItems'] : $pagination['start'] + $pagination['count']?> von <?=$pagination['maxItems']?>
|
||||
<?php else: ?>
|
||||
Keine Adressen gefunden
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
$("#filter_addresstype").select2({closeOnSelect: false});
|
||||
</script>
|
||||
|
||||
<?php include(realpath(dirname(__FILE__)."/../")."/footer.php"); ?>
|
||||
@@ -16,6 +16,39 @@ class AddressController extends mfBaseController {
|
||||
}
|
||||
|
||||
protected function indexAction() {
|
||||
$rfilter = $this->request->filter;
|
||||
iF(!is_array($rfilter)) {
|
||||
$rfilter = [];
|
||||
}
|
||||
if(!array_key_exists("addresstype", $rfilter)) {
|
||||
$rfilter["addresstype"] = [];
|
||||
}
|
||||
|
||||
$this->layout->set("filter", $rfilter);
|
||||
|
||||
$filter = $this->getPreparedFilter($rfilter);
|
||||
|
||||
// pagination defaults
|
||||
$pagination = [];
|
||||
$pagination['start'] = 0;
|
||||
$pagination['count'] = 25;
|
||||
$pagination['maxItems'] = 0;
|
||||
|
||||
if(is_numeric($this->request->s)) {
|
||||
$pagination['start'] = intval($this->request->s);
|
||||
}
|
||||
//var_dump($filter);exit;
|
||||
$pagination['maxItems'] = AddressModel::count($filter);
|
||||
$addresses = AddressModel::search($filter, $pagination);
|
||||
|
||||
$this->layout()->set("addresses", $addresses);
|
||||
$this->layout()->set("request", $this->request);
|
||||
$this->layout()->set("pagination", $pagination);
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
|
||||
//var_dump($this->request->filter);
|
||||
$default_filter = ['parents_only' => 1];
|
||||
if(is_array($this->request->filter) && count($this->request->filter)) {
|
||||
@@ -31,6 +64,23 @@ class AddressController extends mfBaseController {
|
||||
$this->layout()->set("request", $this->request);
|
||||
}
|
||||
|
||||
|
||||
private function getPreparedFilter($filter) {
|
||||
$new_filter = [];
|
||||
|
||||
if(is_array($filter) && count($filter)) {
|
||||
if(!array_key_exists("parents_only", $filter)) {
|
||||
$new_filter["parents_only"] = 1;
|
||||
}
|
||||
|
||||
foreach($filter as $name => $value) {
|
||||
$new_filter[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $new_filter;
|
||||
}
|
||||
|
||||
protected function addAction() {
|
||||
$this->layout()->setTemplate("Address/Form");
|
||||
|
||||
|
||||
@@ -119,25 +119,63 @@ class AddressModel {
|
||||
return $addresses;
|
||||
}
|
||||
|
||||
public static function search($filter) {
|
||||
public static function count($filter) {
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$sql = "SELECT COUNT(*) as cnt FROM (
|
||||
SELECT Address.id as address_id
|
||||
FROM Address
|
||||
LEFT JOIN Addresstype ON (Addresstype.address_id = Address.id)
|
||||
WHERE $where
|
||||
GROUP BY Address.id
|
||||
) as tbl";
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
$data = $db->fetch_object($res);
|
||||
return $data->cnt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static function search($filter, $limit = false) {
|
||||
//var_dump($filter);exit;
|
||||
$items = [];
|
||||
$db = FronkDB::singleton();
|
||||
|
||||
$where = self::getSqlFilter($filter);
|
||||
$have = [];
|
||||
$sql = "SELECT Address.* FROM Address, Addresstype
|
||||
/*$sql = "SELECT Address.* FROM Address, Addresstype
|
||||
WHERE Addresstype.address_id = Address.id
|
||||
AND $where
|
||||
GROUP BY Addresstype.address_id
|
||||
ORDER BY Address.id";
|
||||
ORDER BY Address.id";*/
|
||||
$sql = "SELECT Address.* FROM Address
|
||||
LEFT JOIN Addresstype ON (Addresstype.address_id = Address.id)
|
||||
WHERE $where
|
||||
GROUP BY Address.id
|
||||
ORDER BY company, lastname, firstname, zip, city, Address.id";
|
||||
|
||||
if(is_array($limit) && count($limit)) {
|
||||
if(is_numeric($limit['start']) && is_numeric($limit['count'])) {
|
||||
$sql .= " LIMIT ".$limit['start'].", ".$limit['count'];
|
||||
} elseif(is_numeric($count)) {
|
||||
$sql .= " LIMIT ".$limit['count'];
|
||||
}
|
||||
}
|
||||
|
||||
mfLoghandler::singleton()->debug($sql);
|
||||
|
||||
$res = $db->query($sql);
|
||||
if($db->num_rows($res)) {
|
||||
while($data = $db->fetch_object($res)) {
|
||||
$items[] = new Address($data);
|
||||
$have[] = $data->id;
|
||||
//$have[] = $data->id;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if(!array_key_exists("addresstype", $filter)) {
|
||||
if($have) {
|
||||
$res = $db->select("Address", "*", "$where AND id NOT IN (".implode(",", $have).")");
|
||||
@@ -149,7 +187,7 @@ class AddressModel {
|
||||
$items[] = new Address($data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
return $items;
|
||||
}
|
||||
@@ -157,7 +195,7 @@ class AddressModel {
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
|
||||
//var_dump($filter);exit;
|
||||
if(array_key_exists("customer_number", $filter)) {
|
||||
$cn = $filter["customer_number"];
|
||||
if(is_numeric($cn)) {
|
||||
@@ -171,6 +209,70 @@ class AddressModel {
|
||||
$where .= " AND spin='$spin'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("company", $filter)) {
|
||||
$company = FronkDB::singleton()->escape($filter["company"]);
|
||||
if($company) {
|
||||
$where .= " AND company like '%$company%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("firstname", $filter)) {
|
||||
$firstname = FronkDB::singleton()->escape($filter["firstname"]);
|
||||
if($firstname) {
|
||||
$where .= " AND firstname like '%$firstname%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("lastname", $filter)) {
|
||||
$lastname = FronkDB::singleton()->escape($filter["lastname"]);
|
||||
if($lastname) {
|
||||
$where .= " AND lastname like '%$lastname%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("street", $filter)) {
|
||||
$street = FronkDB::singleton()->escape($filter["street"]);
|
||||
if($street) {
|
||||
$where .= " AND street like '%$street%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("zip", $filter)) {
|
||||
$zip = FronkDB::singleton()->escape($filter["zip"]);
|
||||
if($zip) {
|
||||
$where .= " AND zip like '%$zip%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("city", $filter)) {
|
||||
$city = FronkDB::singleton()->escape($filter["city"]);
|
||||
if($city) {
|
||||
$where .= " AND city like '%$city%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("country", $filter)) {
|
||||
$country = FronkDB::singleton()->escape($filter["country"]);
|
||||
if($country) {
|
||||
$where .= " AND country like '%$country%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("email", $filter)) {
|
||||
$email = FronkDB::singleton()->escape($filter["email"]);
|
||||
if($email) {
|
||||
$where .= " AND email like '%$email%'";
|
||||
}
|
||||
}
|
||||
|
||||
if(array_key_exists("pfm", $filter)) {
|
||||
$pfm = FronkDB::singleton()->escape($filter["pfm"]);
|
||||
if($pfm) {
|
||||
$where .= " AND (phone like '%$pfm%' OR fax like '%$pfm%' OR mobile like '%$pfm%' )";
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Address Type
|
||||
*/
|
||||
@@ -211,7 +313,7 @@ class AddressModel {
|
||||
|
||||
if(array_key_exists("parents_only", $filter)) {
|
||||
$po = $filter['parents_only'];
|
||||
if($po == 1) {
|
||||
if($po) {
|
||||
$where .= " AND parent_id IS NULL";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ class BuildingModel {
|
||||
private function getSqlFilter($filter) {
|
||||
$where = "1=1 ";
|
||||
|
||||
|
||||
|
||||
if(array_key_exists("network_id", $filter)) {
|
||||
$network_id = $filter['network_id'];
|
||||
if(is_numeric($network_id)) {
|
||||
|
||||
Reference in New Issue
Block a user