mirror of
https://github.com/devcode-it/openstamanager.git
synced 2024-12-29 17:21:54 +01:00
77 lines
2.9 KiB
PHP
Executable File
77 lines
2.9 KiB
PHP
Executable File
<?php
|
|
|
|
include_once __DIR__.'/../../../core.php';
|
|
|
|
switch ($resource) {
|
|
case 'anagrafiche_newsletter':
|
|
$query = "SELECT an_anagrafiche.idanagrafica AS id, CONCAT(ragione_sociale, IF(citta != '' OR provincia != '', CONCAT(' (', citta, IF(provincia != '', provincia, ''), ')'), ''), ' [', email, ']') AS descrizione, `an_tipianagrafiche`.`descrizione` AS optgroup FROM an_anagrafiche INNER JOIN (an_tipianagrafiche_anagrafiche INNER JOIN an_tipianagrafiche ON an_tipianagrafiche_anagrafiche.idtipoanagrafica=an_tipianagrafiche.idtipoanagrafica) ON an_anagrafiche.idanagrafica=an_tipianagrafiche_anagrafiche.idanagrafica |where| ORDER BY `optgroup` ASC, ragione_sociale ASC";
|
|
|
|
foreach ($elements as $element) {
|
|
$filter[] = 'an_anagrafiche.idanagrafica='.prepare($element);
|
|
}
|
|
|
|
if (empty($filter)) {
|
|
$where[] = 'deleted_at IS NULL';
|
|
$where[] = 'enable_newsletter = 1';
|
|
}
|
|
|
|
if (!empty($search)) {
|
|
$search_fields[] = 'ragione_sociale LIKE '.prepare('%'.$search.'%');
|
|
$search_fields[] = 'citta LIKE '.prepare('%'.$search.'%');
|
|
$search_fields[] = 'provincia LIKE '.prepare('%'.$search.'%');
|
|
$search_fields[] = 'email LIKE '.prepare('%'.$search.'%');
|
|
}
|
|
|
|
// Aggiunta filtri di ricerca
|
|
if (!empty($search_fields)) {
|
|
$where[] = '('.implode(' OR ', $search_fields).')';
|
|
}
|
|
|
|
if (!empty($filter)) {
|
|
$where[] = '('.implode(' OR ', $filter).')';
|
|
}
|
|
|
|
$query = str_replace('|where|', !empty($where) ? 'WHERE '.implode(' AND ', $where) : '', $query);
|
|
|
|
$rs = $dbo->fetchArray($query);
|
|
foreach ($rs as $r) {
|
|
if ($prev != $r['optgroup']) {
|
|
$results[] = ['text' => $r['optgroup'], 'children' => []];
|
|
$prev = $r['optgroup'];
|
|
}
|
|
|
|
$results[count($results) - 1]['children'][] = [
|
|
'id' => $r['id'],
|
|
'text' => $r['descrizione'],
|
|
'descrizione' => $r['descrizione'],
|
|
];
|
|
}
|
|
break;
|
|
|
|
case 'liste_newsletter':
|
|
$query = "SELECT id, CONCAT(name, ' (', (SELECT COUNT(*) FROM em_list_anagrafica WHERE em_lists.id = em_list_anagrafica.id_list), ' destinatari)') AS descrizione FROM em_lists |where| ORDER BY `name` ASC";
|
|
|
|
foreach ($elements as $element) {
|
|
$filter[] = 'id='.prepare($element);
|
|
}
|
|
|
|
if (empty($filter)) {
|
|
$where[] = 'deleted_at IS NULL';
|
|
}
|
|
|
|
if (!empty($search)) {
|
|
$search_fields[] = 'name LIKE '.prepare('%'.$search.'%');
|
|
}
|
|
|
|
// Aggiunta filtri di ricerca
|
|
if (!empty($search_fields)) {
|
|
$where[] = '('.implode(' OR ', $search_fields).')';
|
|
}
|
|
|
|
if (!empty($filter)) {
|
|
$where[] = '('.implode(' OR ', $filter).')';
|
|
}
|
|
|
|
break;
|
|
}
|