Enabled in Visible per zz_views

Aggiunto supporto ai formati delle date nelle query.
This commit is contained in:
Thomas Zilio 2018-07-19 09:58:28 +02:00
parent f04f2a99da
commit 1418a08b4d
18 changed files with 143 additions and 78 deletions

View File

@ -156,6 +156,8 @@ include App::filepath($directory.'|custom|', 'init.php');
// Retrocompatibilità
if (!isset($record) && isset($records[0])) {
$record = $records[0];
} elseif (!isset($records[0]) && isset($record)) {
$records = [$record];
}
// Registrazione del record

View File

@ -212,9 +212,9 @@ if (!API::isAPIRequest()) {
$pageTitle = $module['title'];
// Segmenti
if (!isset($_SESSION['m'.$id_module]['id_segment'])) {
if (!isset($_SESSION['module_'.$id_module]['id_segment'])) {
$segments = Modules::getSegments($id_module);
$_SESSION['m'.$id_module]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_module]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
}
Permissions::addModule($id_module);

View File

@ -40,9 +40,6 @@ if (empty($record)) {
echo '
<p>'.tr('Record non trovato').'.</p>';
} else {
/*
* Lettura eventuali plugins modulo da inserire come tab
*/
echo '
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right" id="tabs" role="tablist">

View File

@ -39,8 +39,6 @@ if (!empty($id_plugin)) {
</h4>';
}
$total = App::readQuery($element);
$type = $element['option'];
// Caricamento helper modulo (verifico se ci sono helper personalizzati)
@ -56,11 +54,13 @@ include App::filepath($directory.'|custom|', 'controller_before.php');
* Datatables con record
*/
if (!empty($type) && $type != 'menu' && $type != 'custom') {
$total = App::readQuery($element);
if (empty($id_plugin) && count(Modules::getSegments($id_module)) > 1) {
echo '
<div class="row">
<div class="col-md-4 pull-right">
{[ "type": "select", "name": "id_segment_", "required": 0, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module = '.prepare($id_module).'", "value": "'.$_SESSION['m'.$id_module]['id_segment'].'" ]}
{[ "type": "select", "name": "id_segment_", "required": 0, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module = '.prepare($id_module).'", "value": "'.$_SESSION['module_'.$id_module]['id_segment'].'" ]}
</div>
</div>
<br>';

View File

@ -40,7 +40,7 @@ if (Auth::check()) {
foreach ($_SESSION as $idx1 => $arr2) {
if ($idx1 == 'module_'.$id_module) {
foreach ($arr2 as $field => $value) {
if ($value != '') {
if (!empty($value) && starts_with($field, 'search_')) {
$field_name = str_replace('search_', '', $field);
echo '
search.push("search_'.$field_name.'");

View File

@ -437,3 +437,18 @@ if (!function_exists('readSQLFile')) {
return $queryLine;
}
}
if (!function_exists('replace')) {
/**
* Sostituisce gli elementi dell'array all'interno della stringa.
*
* @param string $string
* @param array $array
*
* @return string
*/
function replace($string, $array)
{
return str_replace(array_keys($array), array_values($array), $string);
}
}

View File

@ -32,7 +32,7 @@ echo '
// Sezionale
echo '
<div class="col-md-4">
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.Modules::get('Fatture di vendita')['id'].' ORDER BY name", "value":"'.$_SESSION['m'.Modules::get('Fatture di vendita')['id']]['id_segment'].'" ]}
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.Modules::get('Fatture di vendita')['id'].' ORDER BY name", "value":"'.$_SESSION['module_'.Modules::get('Fatture di vendita')['id']]['id_segment'].'" ]}
</div>
</div>';

View File

@ -17,9 +17,9 @@ switch (post('op')) {
// Segmenti
$id_fatture = Modules::get('Fatture di vendita')['id'];
if (!isset($_SESSION['m'.$id_fatture]['id_segment'])) {
if (!isset($_SESSION['module_'.$id_fatture]['id_segment'])) {
$segments = Modules::getSegments($id_fatture);
$_SESSION['m'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
$_SESSION['module_'.$id_fatture]['id_segment'] = isset($segments[0]['id']) ? $segments[0]['id'] : null;
}
$id_segment = $_SESSION['m'.$id_fatture]['id_segment'];

View File

@ -36,7 +36,7 @@ $id_anagrafica = !empty(get('idanagrafica')) ? get('idanagrafica') : $user['idan
{[ "type": "select", "label": "<?php echo tr('Tipo fattura'); ?>", "name": "idtipodocumento", "required": 1, "values": "query=SELECT id, descrizione FROM co_tipidocumento WHERE dir='<?php echo $dir; ?>'" ]}
</div>
<div class="col-md-6">
{[ "type": "select", "label": "<?php echo tr('Sezionale'); ?>", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='<?php echo $id_module; ?>' ORDER BY name", "value": "<?php echo $_SESSION['m'.$id_module]['id_segment']; ?>" ]}
{[ "type": "select", "label": "<?php echo tr('Sezionale'); ?>", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='<?php echo $id_module; ?>' ORDER BY name", "value": "<?php echo $_SESSION['module_'.$id_module]['id_segment']; ?>" ]}
</div>
</div>

View File

@ -117,7 +117,7 @@ if (!empty($rs)) {
if ($module_name == 'Fatture di vendita' || $module_name == 'Fatture di acquisto') {
echo '
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare(Modules::get($module_name)['id']).' ORDER BY name", "value": "'.$_SESSION['m'.Modules::get($module_name)['id']]['id_segment'].'" ]}
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.prepare(Modules::get($module_name)['id']).' ORDER BY name", "value": "'.$_SESSION['module_'.Modules::get($module_name)['id']]['id_segment'].'" ]}
</div>';
}

View File

@ -63,12 +63,12 @@ switch (post('op')) {
$dir = 'entrata';
$idtipodocumento = '2';
if (empty($_SESSION['m'.Modules::get('Fatture di vendita')['id']]['id_segment'])) {
if (empty($_SESSION['module_'.Modules::get('Fatture di vendita')['id']]['id_segment'])) {
$rs = $dbo->fetchArray('SELECT id FROM zz_segments WHERE predefined = 1 AND id_module = '.prepare(Modules::get('Fatture di vendita')['id']).'LIMIT 0,1');
$_SESSION['m'.Modules::get('Fatture di vendita')['id']]['id_segment'] = $rs[0]['id'];
$_SESSION['module_'.Modules::get('Fatture di vendita')['id']]['id_segment'] = $rs[0]['id'];
}
$id_segment = $_SESSION['m'.Modules::get('Fatture di vendita')['id']]['id_segment'];
$id_segment = $_SESSION['module_'.Modules::get('Fatture di vendita')['id']]['id_segment'];
$numero = get_new_numerofattura($data);

View File

@ -47,7 +47,7 @@ switch (filter('op')) {
$array = [
'name' => $post['name'][$c],
'query' => $post['query'][$c],
'enabled' => $post['enabled'][$c],
'visible' => $post['visible'][$c],
'search' => $post['search'][$c],
'slow' => $post['slow'][$c],
'format' => $post['format'][$c],

View File

@ -99,8 +99,8 @@ if (!empty($options) && $options != 'custom') {
$editable = !($field['default'] && $enable_readonly);
echo '
<div class="box ';
if ($field['enabled']) {
<div class="box ';
if ($field['visible']) {
echo 'box-success';
} else {
echo 'box-danger';
@ -153,7 +153,7 @@ if (!empty($options) && $options != 'custom') {
</div>
<div class="col-xs-12 col-md-6">
{[ "type": "select", "label": "'.tr('Visibilità').'", "name": "enabled['.$key.']", "values": "list=\"0\":\"'.tr('Nascosto (variabili di stato)').'\",\"1\": \"'.tr('Visibile nella sezione').'\"", "value": "'.$field['enabled'].'", "help": "'.tr('Stato del campo: visibile nella tabella oppure nascosto').'" ]}
{[ "type": "select", "label": "'.tr('Visibilità').'", "name": "visible['.$key.']", "values": "list=\"0\":\"'.tr('Nascosto (variabili di stato)').'\",\"1\": \"'.tr('Visibile nella sezione').'\"", "value": "'.$field['visible'].'", "help": "'.tr('Stato del campo: visibile nella tabella oppure nascosto').'" ]}
</div>
</div>
@ -227,7 +227,7 @@ if (!empty($options) && $options != 'custom') {
<p data-id="'.$field['id'].'">
<i class="fa fa-sort"></i>
';
if ($field['enabled']) {
if ($field['visible']) {
echo '<strong class="text-success">'.$field['name'].'</strong>';
} else {
echo '<span class="text-danger">'.$field['name'].'</span>';
@ -254,7 +254,8 @@ if (!empty($options) && $options != 'custom') {
<div class="col-md-12">
{[ "type": "text", "label": "'.tr('Nome').'", "name": "name[-id-]" ]}
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
{[ "type": "textarea", "label": "'.tr('Query prevista').'", "name": "query[-id-]" ]}
@ -267,7 +268,7 @@ if (!empty($options) && $options != 'custom') {
</div>
<div class="col-md-6">
{[ "type": "select", "label": "'.tr('Visibilità').'", "name": "enabled[-id-]", "values": "list=\"0\":\"'.tr('Nascosto (variabili di stato)').'\",\"1\": \"'.tr('Visibile nella sezione').'\"" ]}
{[ "type": "select", "label": "'.tr('Visibilità').'", "name": "visible[-id-]", "values": "list=\"0\":\"'.tr('Nascosto (variabili di stato)').'\",\"1\": \"'.tr('Visibile nella sezione').'\"" ]}
</div>
</div>
@ -297,7 +298,8 @@ if (!empty($options) && $options != 'custom') {
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Ordina tramite').'", "name": "order_by[-id-]" ]}
</div>
</div>
</div>
</div>
</div>
</form>';
@ -329,64 +331,64 @@ if (!empty($options) && $options != 'custom') {
echo 'box-danger';
}
echo '">
<div class="box-header with-border">
<h3 class="box-title">
<a data-toggle="collapse" href="#additional-'.$additional['id'].'">'.tr('Filtro: _NAME_', [
'_NAME_' => $additional['name'],
]).'</a>
</h3>';
<div class="box-header with-border">
<h3 class="box-title">
<a data-toggle="collapse" href="#additional-'.$additional['id'].'">'.tr('Filtro: _NAME_', [
'_NAME_' => $additional['name'],
]).'</a>
</h3>';
if ($editable) {
echo '
<a class="btn btn-danger ask pull-right" data-backto="record-edit" data-op="delete_filter" data-id="'.$additional['id'].'">
<i class="fa fa-trash"></i> '.tr('Elimina').'
</a>';
<a class="btn btn-danger ask pull-right" data-backto="record-edit" data-op="delete_filter" data-id="'.$additional['id'].'">
<i class="fa fa-trash"></i> '.tr('Elimina').'
</a>';
}
echo '
<a class="btn btn-warning ask pull-right" data-backto="record-edit" data-msg="'.($additional['enabled'] ? tr('Disabilitare questo elemento?') : tr('Abilitare questo elemento?')).'" data-op="change" data-id="'.$additional['id'].'" data-class="btn btn-lg btn-warning" data-button="'.($additional['enabled'] ? tr('Disabilita') : tr('Abilita')).'">
<i class="fa fa-eye-slash"></i> '.($additional['enabled'] ? tr('Disabilita') : tr('Abilita')).'
</a>';
<a class="btn btn-warning ask pull-right" data-backto="record-edit" data-msg="'.($additional['enabled'] ? tr('Disabilitare questo elemento?') : tr('Abilitare questo elemento?')).'" data-op="change" data-id="'.$additional['id'].'" data-class="btn btn-lg btn-warning" data-button="'.($additional['enabled'] ? tr('Disabilita') : tr('Abilita')).'">
<i class="fa fa-eye-slash"></i> '.($additional['enabled'] ? tr('Disabilita') : tr('Abilita')).'
</a>';
echo '
</div>
<div id="additional-'.$additional['id'].'" class="box-body collapse">
</div>
<div id="additional-'.$additional['id'].'" class="box-body collapse">
<div class="row">
<div class="col-md-12">
{[ "type": "textarea", "label": "'.tr('Query').'", "name": "query['.$num.']", "value": "'.prepareToField($additional['clause']).'"';
<div class="row">
<div class="col-md-12">
{[ "type": "textarea", "label": "'.tr('Query').'", "name": "query['.$num.']", "value": "'.prepareToField($additional['clause']).'"';
if (!$editable) {
echo ', "readonly": "1"';
}
echo ' ]}
</div>
</div>
<div class="row">
<input type="hidden" value="'.$additional['id'].'" name="id['.$num.']">
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Name').'", "name": "name['.$num.']", "value": "'.$additional['name'].'" ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Gruppo').'", "name": "gruppo['.$num.']", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC", "value": "'.$additional['idgruppo'].'"';
if (!$editable) {
echo ', "readonly": "1"';
}
echo ' ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Posizione').'", "name": "position['.$num.']", "values": "list=\"0\":\"'.tr('WHERE').'\",\"1\": \"'.tr('HAVING').'\"", "value": "'.$additional['position'].'"';
if (!$editable) {
echo ', "readonly": "1"';
}
echo ' ]}
</div>
</div>
</div>
</div>';
<div class="row">
<input type="hidden" value="'.$additional['id'].'" name="id['.$num.']">
<div class="col-md-6">
{[ "type": "text", "label": "'.tr('Name').'", "name": "name['.$num.']", "value": "'.$additional['name'].'" ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Gruppo').'", "name": "gruppo['.$num.']", "values": "query=SELECT id, nome AS descrizione FROM zz_groups ORDER BY id ASC", "value": "'.$additional['idgruppo'].'"';
if (!$editable) {
echo ', "readonly": "1"';
}
echo ' ]}
</div>
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Posizione').'", "name": "position['.$num.']", "values": "list=\"0\":\"'.tr('WHERE').'\",\"1\": \"'.tr('HAVING').'\"", "value": "'.$additional['position'].'"';
if (!$editable) {
echo ', "readonly": "1"';
}
echo ' ]}
</div>
</div>
</div>
</div>';
}
echo '
</div>
@ -401,6 +403,7 @@ if (!empty($options) && $options != 'custom') {
</button>
</div>
</div>
</div>
</div>
</div>
@ -434,8 +437,9 @@ if (!empty($options) && $options != 'custom') {
<div class="col-md-3">
{[ "type": "select", "label": "'.tr('Posizione').'", "name": "position[-id-]", "values": "list=\"0\":\"'.tr('WHERE').'\",\"1\": \"'.tr('HAVING').'\"" ]}
</div>
</div>
</div>
</div>
</div>
</div>
</form>';
echo '
@ -514,3 +518,6 @@ $(document).ready(function(){
});
</script>';
}
// Fix apertura non corrisposta di un tag div
echo '</div>';

View File

@ -146,7 +146,8 @@ class App
public static function flash()
{
if (empty(self::$flash)) {
self::$flash = new \Util\Messages();
$storage = null;
self::$flash = new \Util\Messages($storage, 'messages');
}
return self::$flash;
@ -286,7 +287,7 @@ class App
foreach ($views as $view) {
$select[] = $view['query'].(!empty($view['name']) ? " AS '".$view['name']."'" : '');
if ($view['enabled']) {
if (!empty($view['visible'])) {
$view['name'] = trim($view['name']);
$view['search_inside'] = trim($view['search_inside']);
$view['order_by'] = trim($view['order_by']);
@ -410,7 +411,17 @@ class App
$query = str_replace(['|period_start|', '|period_end|'], [$_SESSION['period_start'], $_SESSION['period_end']], $query);
// Sostituzione dei segmenti
$query = str_replace('|segment|', !empty($_SESSION['m'.$id_module]['id_segment']) ? ' AND id_segment = '.prepare($_SESSION['m'.$id_module]['id_segment']) : '', $query);
$query = str_replace('|segment|', !empty($_SESSION['module_'.$id_module]['id_segment']) ? ' AND id_segment = '.prepare($_SESSION['module_'.$id_module]['id_segment']) : '', $query);
// Sostituzione dei formati
$patterns = formatter()->getSQLPatterns();
$replace = [];
foreach ($patterns as $key => $value) {
$replace['|'.$key.'_format|'] = "'".$value."'";
}
$query = replace($query, $replace);
return $query;
}

View File

@ -33,6 +33,9 @@ class Formatter
/** @var string Pattern per gli orari */
protected $timePattern;
/** @var array Pattern per SQL */
protected $sql = [];
public function __construct($locale, $timestamp = null, $date = null, $time = null, $number = [])
{
if (class_exists('NumberFormatter')) {
@ -554,4 +557,31 @@ class Formatter
{
return $this->timePattern = $pattern;
}
public function getSQLPatterns()
{
if (empty($this->sql)) {
$formats = [
'd' => '%d',
'm' => '%m',
'Y' => '%Y',
'H' => '%H',
'i' => '%i',
];
$result = [
'timestamp' => $this->getTimestampPattern(),
'date' => $this->getDatePattern(),
'time' => $this->getTimePattern(),
];
foreach ($result as $key => $value) {
$result[$key] = replace($value, $formats);
}
$this->sql = $result;
}
return $this->sql;
}
}

View File

@ -147,7 +147,7 @@ class Modules
// Aggiunta dei segmenti
$segments = self::getSegments($module['id']);
foreach ($segments as $result) {
if (!empty($result['clause']) && $result['id'] == $_SESSION['m'.$module['id']]['id_segment']) {
if (!empty($result['clause']) && $result['id'] == $_SESSION['module_'.$module['id']]['id_segment']) {
$result['clause'] = App::replacePlaceholder($result['clause']);
$additionals[$result['position']][] = $result['clause'];

View File

@ -13,8 +13,8 @@ $module_query = $total['query'];
$search_filters = [];
if (is_array($_SESSION['module_'.$id_module])) {
foreach ($_SESSION['module_'.$id_module] as $field_name => $field_value) {
if ($field_value != '') {
foreach ($_SESSION['module_'.$id_module] as $field => $value) {
if (!empty($value) && starts_with($field, 'search_')) {
$field_name = str_replace('search_', '', $field_name);
$field_name = str_replace('__', ' ', $field_name);
$field_name = str_replace('-', ' ', $field_name);

View File

@ -241,3 +241,6 @@ ALTER TABLE `zz_smtp` RENAME `zz_smtps`;
-- Aggiorno tabella zz_smtp in zz_smtps per il modulo Account email
UPDATE `zz_modules` SET `options` = 'SELECT |select| FROM zz_smtps WHERE 1=1 AND deleted_at IS NULL HAVING 2=2 ORDER BY `name`' WHERE `zz_modules`.`name` = 'Account email';
-- Ridenominazione enabled in visible su zz_views
ALTER TABLE `zz_views` CHANGE `enabled` `visible` BOOLEAN NOT NULL DEFAULT 1;