Risoluzione di alcuni bug

Risoluzione di alcuni bug individuati e miglioramento della performance dell'aggiornamento.
This commit is contained in:
Thomas Zilio 2017-09-01 12:55:48 +02:00
parent fad9f7c783
commit b11f641f24
10 changed files with 151 additions and 140 deletions

View File

@ -48,6 +48,8 @@ class Database extends Util\Singleton
*/
protected function __construct($server, $username, $password, $database_name, $charset = null, $option = [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION])
{
global $debug;
if (is_array($server)) {
$host = $server['host'];
$port = !empty($server['port']) ? $server['port'] : null;
@ -71,15 +73,21 @@ class Database extends Util\Singleton
if (!empty($this->host) && !empty($this->database_name)) {
try {
$this->pdo = new \DebugBar\DataCollector\PDO\TraceablePDO(new PDO(
$pdo = new PDO(
'mysql:host='.$this->host.(!empty($this->port) ? ';port='.$this->port : '').';dbname='.$this->database_name,
$this->username,
$this->password,
$this->option
));
);
if (empty($this->charset) && version_compare($this->getMySQLVersion(), '5.5.3') >= 0) {
$this->charset = 'utf8mb4';
if (!empty($debug)) {
$pdo = new \DebugBar\DataCollector\PDO\TraceablePDO($pdo);
}
$this->pdo = $pdo;
if (empty($this->charset)) {
$this->charset = version_compare($this->getMySQLVersion(), '5.5.3') >= 0 ? 'utf8mb4' : 'utf8';
}
// Fix per problemi di compatibilità delle password MySQL 4.1+ (da versione precedente)

View File

@ -3,6 +3,7 @@
namespace HTMLBuilder\Wrapper;
/**
* Interfaccia di base per la gestione della struttura HTML contenente gli input effettivi (generati dai tag di input).
*
* @since 2.3
*/

View File

@ -443,6 +443,7 @@ function start_datatables() {
order: [],
lengthChange: false,
scrollY: "50vh",
stateSave: true,
});
}
});
@ -468,6 +469,11 @@ function start_datatables() {
}
})
// Fix per l'URL encoding
search.forEach(function (value, index, array) {
search[array[index]] = decodeURIComponent(array[value]);
})
var res = [];
$this.find("th").each(function () {
var id = $(this).attr('id').replace("th_", "");
@ -495,15 +501,13 @@ function start_datatables() {
scrollY: "60vh",
scrollX: '100%',
retrieve: true,
stateSave: true,
columnDefs: [{
searchable: false,
orderable: false,
width: '1%',
className: 'select-checkbox',
targets: 0
}, {
'max-width': '20%',
targets: '_all'
}],
select: {
style: 'multi',

View File

@ -12,7 +12,12 @@ switch (get('op')) {
$start = get('start');
$end = get('end');
$query = "SELECT in_interventi_tecnici.idintervento, colore, in_interventi_tecnici.id, idtecnico, orario_inizio, orario_fine, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS nome_tecnico, (SELECT colore FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS colore_tecnico, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=in_interventi.idanagrafica) AS cliente FROM in_interventi_tecnici INNER JOIN (in_interventi LEFT OUTER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento) ON in_interventi_tecnici.idintervento=in_interventi.id WHERE in_interventi_tecnici.orario_inizio >= ".prepare($startend)." AND in_interventi_tecnici.orario_fine <= ".prepare($end)." AND idtecnico IN(".implode(',', $_SESSION['dashboard']['idtecnici']).') AND (in_interventi.idstatointervento IN('.implode(',', $_SESSION['dashboard']['idstatiintervento']).") OR in_interventi.idstatointervento='') AND in_interventi_tecnici.idtipointervento IN(".implode(',', $_SESSION['dashboard']['idtipiintervento']).') '.Modules::getAdditionalsQuery('Interventi');
$stati = (array) $_SESSION['dashboard']['idstatiintervento'];
$stati[] = prepare('');
$tipi = (array) $_SESSION['dashboard']['idtipiintervento'];
$query = 'SELECT in_interventi_tecnici.idintervento, colore, in_interventi_tecnici.id, idtecnico, orario_inizio, orario_fine, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS nome_tecnico, (SELECT colore FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS colore_tecnico, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=in_interventi.idanagrafica) AS cliente FROM in_interventi_tecnici INNER JOIN (in_interventi LEFT OUTER JOIN in_statiintervento ON in_interventi.idstatointervento=in_statiintervento.idstatointervento) ON in_interventi_tecnici.idintervento=in_interventi.id WHERE in_interventi_tecnici.orario_inizio >= '.prepare($start).' AND in_interventi_tecnici.orario_fine <= '.prepare($end).' AND idtecnico IN('.implode(',', $_SESSION['dashboard']['idtecnici']).') AND in_interventi.idstatointervento IN('.implode(',', $stati).') AND in_interventi_tecnici.idtipointervento IN('.implode(',', $tipi).') '.Modules::getAdditionalsQuery('Interventi');
$rs = $dbo->fetchArray($query);
$n = count($rs);
@ -29,10 +34,9 @@ switch (get('op')) {
{
"id": "'.$rs[$i]['idintervento'].'",
"idtecnico":"'.$rs[$i]['idtecnico'].'",
"orario":"1",
"title":"<b>Int. '.$rs[$i]['idintervento'].'</b>\\n'.addslashes($rs[$i]['cliente']).'<br>\\n<b>'._('Tecnici').': </b>'.addslashes($rs[$i]['nome_tecnico']).'",
"start": "'.date('Y-m-d H:i', strtotime($rs[$i]['orario_inizio'])).'",
"end": "'.date('Y-m-d H:i', strtotime($rs[$i]['orario_fine'])).'",
"title":"<b>Int. '.$rs[$i]['idintervento'].'</b>'.addslashes($rs[$i]['cliente']).'<br><b>'._('Tecnici').':</b> '.addslashes($rs[$i]['nome_tecnico']).'",
"start": "'.$rs[$i]['orario_inizio'].'",
"end": "'.$rs[$i]['orario_fine'].'",
"url":"'.$rootdir.'/editor.php?id_module='.Modules::getModule('Interventi')['id'].'&id_record='.$rs[$i]['idintervento'].'",
"backgroundColor":"'.$rs[$i]['colore'].'",
"textColor":"'.color_inverse($rs[$i]['colore']).'",
@ -81,6 +85,7 @@ switch (get('op')) {
$query = 'SELECT in_interventi_tecnici.idintervento, in_interventi.id, idtecnico, orario_inizio, orario_fine, (SELECT ragione_sociale FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS nome_tecnico, (SELECT colore FROM an_anagrafiche WHERE idanagrafica=idtecnico) AS colore FROM in_interventi_tecnici INNER JOIN in_interventi ON in_interventi_tecnici.idintervento=in_interventi.id WHERE in_interventi.id='.prepare($id).' '.Modules::getAdditionalsQuery('Interventi');
$rs = $dbo->fetchArray($query);
if (!empty($rs)) {
$tecnici = [];
foreach ($rs as $r) {
$tecnici[] = $r['nome_tecnico'].' ('.Translator::timestampToLocale($r['orario_inizio']).' - '.Translator::timeToLocale($r['orario_fine']).')';
@ -130,6 +135,7 @@ switch (get('op')) {
}
echo $tooltip_text;
}
break;
}

View File

@ -423,7 +423,7 @@ if ($vista == 'mese') {
var calendar = $('#calendar').fullCalendar({
locale: globals.locale,
<?php
if (!get_var('Visualizzare la domenica sul calendario')) {
if (!empty(get_var('Visualizzare la domenica sul calendario'))) {
echo '
hiddenDays: [ 0 ],';
}
@ -438,31 +438,27 @@ if (!get_var('Visualizzare la domenica sul calendario')) {
slotDuration: '00:15:00',
defaultView: '<?php echo $def; ?>',
<?php
if (get_var('Abilitare orario lavorativo') == '1') {
if (!empty(get_var('Abilitare orario lavorativo'))) {
echo "
minTime: '08:00:00',
maxTime: '20:00:00',";
}
?>
selectable: true,
lazyFetching: true,
selectHelper: true,
editable: true,
eventLimit: false, // allow "more" link when too many events
allDaySlot: false,
droppable: true,
loading: function(isLoading, view) {
if(isLoading) {
//setTimeout("$('#tiny-loader').show()", 10);
$('#tiny-loader').fadeIn();
} else {
//setTimeout("$('#tiny-loader').hide()", 10);
$('#tiny-loader').hide();
}
},
<?php
if (Modules::getPermission($id_module) == 'rw') {
?>
droppable: true,
drop: function(date, jsEvent, ui, resourceId) {
data = moment(date).format("YYYY-MM-DD");
ora_dal = moment(date).format("HH:mm");
@ -478,32 +474,33 @@ if (Modules::getPermission($id_module) == 'rw') {
$('#calendar').fullCalendar('refetchEvents');
});
},
<?php
}
?>
selectable: true,
select: function(start, end, allDay) {
data = moment(start).format("YYYY-MM-DD");
ora_dal = moment(start).format("HH:mm");
ora_al = moment(end).format("HH:mm");
<?php
if (Modules::getPermission($id_module) == 'rw') {
?>
launch_modal('<?php echo _('Aggiungi intervento'); ?>', globals.rootdir + '/add.php?id_module=<?php echo Modules::getModule('Interventi')['id'] ?>&ref=dashboard&data='+data+'&orario_inizio='+ora_dal+'&orario_fine='+ora_al, 1 );
<?php
}
?>
$('#calendar').fullCalendar('unselect');
},
events: {
url: globals.rootdir + "/modules/dashboard/ajaxreq.php?op=get_current_month",
type: 'GET',
error: function() {
alert('<?php echo _('Errore durante la creazione degli eventi'); ?>');
editable: true,
eventDrop: function(event,dayDelta,minuteDelta,revertFunc) {
$.get(globals.rootdir + "/modules/dashboard/ajaxreq.php?op=update_intervento&id="+event.id+"&timeStart="+moment(event.start).format("YYYY-MM-DD HH:mm")+"&timeEnd="+moment(event.end).format("YYYY-MM-DD HH:mm"), function(data,response){
if( response=="success" ){
data = $.trim(data);
if( data!="ok" ){
alert(data);
$('#calendar').fullCalendar('refetchEvents');
revertFunc();
}
else{
return false;
}
}
});
},
eventResize: function(event,dayDelta,minuteDelta,revertFunc) {
$.get(globals.rootdir + "/modules/dashboard/ajaxreq.php?op=update_intervento&id="+event.id+"&timeStart="+moment(event.start).format("YYYY-MM-DD HH:mm")+"&timeEnd="+moment(event.end).format("YYYY-MM-DD HH:mm"), function(data,response){
@ -520,26 +517,16 @@ if (Modules::getPermission($id_module) == 'rw') {
}
});
},
eventDrop: function(event,dayDelta,minuteDelta,revertFunc) {
$.get(globals.rootdir + "/modules/dashboard/ajaxreq.php?op=update_intervento&id="+event.id+"&timeStart="+moment(event.start).format("YYYY-MM-DD HH:mm")+"&timeEnd="+moment(event.end).format("YYYY-MM-DD HH:mm"), function(data,response){
if( response=="success" ){
data = $.trim(data);
if( data!="ok" ){
alert(data);
$('#calendar').fullCalendar('refetchEvents');
revertFunc();
}
else{
return false;
}
}
});
},
<?php
}
if (get_var('Utilizzare i tooltip sul calendario') == '1') {
?>
eventAfterRender: function(event, element) {
//alert(element.find('.fc-event-title').html();
element.find('.fc-title').html(event.title);
<?php if (get_var('Utilizzare i tooltip sul calendario') == '1') {
?>
$.get(globals.rootdir + "/modules/dashboard/ajaxreq.php?op=get_more_info&id="+event.id+"&timeStart="+moment(event.start).format("YYYY-MM-DD HH:mm")+"&timeEnd="+moment(event.end).format("YYYY-MM-DD HH:mm"), function(data,response){
if( response=="success" ){
data = $.trim(data);
@ -565,9 +552,20 @@ if (Modules::getPermission($id_module) == 'rw') {
}
}
});
},
<?php
} ?>
}
?>
events: {
url: globals.rootdir + "/modules/dashboard/ajaxreq.php?op=get_current_month",
type: 'GET',
success: function(data) {
console.log(data);
},
error: function() {
alert('<?php echo _('Errore durante la creazione degli eventi'); ?>');
}
}
});
}

View File

@ -182,6 +182,7 @@ switch (post('op')) {
break;
case 'add':
/*
$codice = post('codice');
// Controlli sul codice
@ -196,8 +197,11 @@ switch (post('op')) {
$_SESSION['warnings'][] = str_replace('_NUM_', "'".$codice."'", _('Numero intervento _NUM_ saltato perchè già esistente!'));
$_SESSION['warnings'][] = str_replace('_NUM_', "'".$new_codice."'", _('Nuovo numero intervento calcolato _NUM_'));
}
*/
$formato = get_var('Formato codice intervento');
$codice = $new_codice;
$rs = $dbo->fetchArray('SELECT codice FROM in_interventi WHERE concat("", codice * 1) = codice AND LENGTH(codice) = '.strlen($formato).' ORDER BY CAST(codice AS SIGNED) DESC LIMIT 1');
$codice = get_next_code($rs[0]['codice'], 1, $formato);
// Informazioni di base
$idpreventivo = post('idpreventivo');

View File

@ -97,7 +97,6 @@ if (empty($new_codice)) {
<form action="editor.php?id_module=$id_module$" method="post" id="add-form" onsubmit="if($(this).parsley().validate()) { return add_intervento(); }">
<input type="hidden" name="op" value="add">
<input type="hidden" name="id_module" value="<?php echo $id_module ?>">
<input type="hidden" name="ref" value="<?php echo $_GET['ref']; ?>">
<input type="hidden" name="backto" value="record-edit">
@ -156,19 +155,19 @@ if (empty($new_codice)) {
<div class="panel-body">
<!-- RIGA 3 -->
<div class="row">
<div class="col-md-3">
<!--div class="col-md-3">
{[ "type": "text", "label": "<?php echo _('Codice intervento'); ?>", "name": "codice", "required": 1, "class": "text-center", "value": "<?php echo $new_codice ?>" ]}
</div>
</div-->
<div class="col-md-3">
<div class="col-md-4">
{[ "type": "date", "label": "<?php echo _('Data richiesta'); ?>", "name": "data_richiesta", "required": 1, "value": "-now-" ]}
</div>
<div class="col-md-3">
<div class="col-md-4">
{[ "type": "date", "label": "<?php echo _('Data intervento'); ?>", "name": "data", "required": 1, "value": "<?php echo $data ?>" ]}
</div>
<div class="col-md-3">
<div class="col-md-4">
{[ "type": "select", "label": "<?php echo _('Zona'); ?>", "name": "idzona", "values": "query=SELECT id, nome AS descrizione FROM an_zone ORDER BY nome", "value": "<?php echo $idzona ?>" ]}
</div>
</div>

View File

@ -159,7 +159,7 @@ $dirs = [
'zone',
];
$pieces = array_chunk($tables, 5);
$pieces = array_chunk($dirs, 5);
foreach ($pieces as $piece) {
$files = glob($docroot.'/modules/{'.implode(',', $piece).'}/*.html', GLOB_BRACE);

View File

@ -952,5 +952,9 @@ ALTER TABLE `or_righe_ordini` CHANGE `data_evasione` `data_evasione` date;
-- ALTER TABLE `my_componenti_interventi` ADD PRIMARY KEY (`id_intervento`, `id_componente`);
-- ALTER TABLE `my_impianti_interventi` ADD PRIMARY KEY (`idintervento`, `idimpianto`);
-- Fix di alcuni problemi con le query dei widget
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE(FORMAT(SUM(qta),2), ",", "#"), ".", ","), "#", "."), "unit&agrave;") AS dato FROM mg_articoli WHERE qta>0' WHERE `name` = 'Articoli in magazzino';
UPDATE `zz_widgets` SET `query` = 'SELECT CONCAT_WS(" ", REPLACE(REPLACE(REPLACE(FORMAT(SUM(prezzo_acquisto*qta),2), ",", "#"), ".", ","), "#", "."), "&euro;") AS dato FROM mg_articoli WHERE qta>0' WHERE `name` = 'Valore magazzino';
-- Fix per le sessioni di lavoro dei tecnici precedenti
UPDATE `in_interventi_tecnici` SET `idtipointervento` = (SELECT `idtipointervento` FROM `in_interventi` WHERE `idintervento` = `in_interventi`.`id`) WHERE `idtipointervento` = '';

View File

@ -90,33 +90,20 @@ $tables = [
'zz_semaphores',
];
$pieces = array_chunk($tables, 10);
foreach ($pieces as $piece) {
$implode = [];
foreach ($piece as $table) {
$implode[] = prepare($table);
}
$query = 'SELECT table_name FROM INFORMATION_SCHEMA.TABLES T WHERE T.TABLE_SCHEMA = '.prepare($database->getDatabaseName()).' AND
T.TABLE_NAME IN('.implode(',', $implode).") AND
NOT EXISTS (
SELECT table_name
FROM INFORMATION_SCHEMA.COLUMNS C
WHERE
C.TABLE_SCHEMA = T.TABLE_SCHEMA AND
C.TABLE_NAME = T.TABLE_NAME AND
C.COLUMN_NAME = '|field|')";
foreach ($tables as $table) {
if ($database->fetchNum('SHOW TABLES WHERE `Tables_in_'.$database->getDatabaseName().'` = '.prepare($table))) {
$query = 'SHOW COLUMNS FROM '.$table.' FROM '.$database->getDatabaseName()." WHERE Field='|field|'";
$created_at = $database->fetchArray(str_replace('|field|', 'created_at', $query));
foreach ($created_at as $table) {
$database->query('ALTER TABLE `'.$table['table_name'].'` ADD `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP');
if (empty($created_at)) {
$database->query('ALTER TABLE `'.$table.'` ADD `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP');
}
if (API::isCompatible()) {
$updated_at = $database->fetchArray(str_replace('|field|', 'updated_at', $query));
foreach ($updated_at as $table) {
$database->query('ALTER TABLE `'.$table['table_name'].'` `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
if (empty($updated_at)) {
$database->query('ALTER TABLE `'.$table.'` ADD `updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP');
}
}
}
}