openstamanager/modules/newsletter/ajax/select.php

77 lines
2.9 KiB
PHP
Raw Normal View History

2019-08-29 15:09:01 +02:00
<?php
include_once __DIR__.'/../../../core.php';
switch ($resource) {
case 'anagrafiche_newsletter':
2019-09-24 10:09:29 +02:00
$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";
2019-08-29 15:09:01 +02:00
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.'%');
2019-09-24 10:09:29 +02:00
$search_fields[] = 'email LIKE '.prepare('%'.$search.'%');
2019-08-29 15:09:01 +02:00
}
// 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;
2019-09-24 10:09:29 +02:00
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;
2019-08-29 15:09:01 +02:00
}