forked from devcode-it/openstamanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.php
executable file
·382 lines (300 loc) · 12.8 KB
/
editor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<?php
include_once __DIR__.'/core.php';
if (empty($id_record) && !empty($id_module)) {
redirect(ROOTDIR.'/controller.php?id_module='.$id_module);
} elseif (empty($id_record) && empty($id_module)) {
redirect(ROOTDIR.'/index.php');
}
include_once App::filepath('include|custom|', 'top.php');
// Inclusione gli elementi fondamentali
include_once $docroot.'/actions.php';
// Widget in alto
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top", "place": "editor" )}';
$advanced_sessions = setting('Attiva notifica di presenza utenti sul record');
if (!empty($advanced_sessions)) {
$dbo->query('DELETE FROM zz_semaphores WHERE id_utente='.prepare(Auth::user()['id']).' AND posizione='.prepare($id_module.', '.$id_record));
$dbo->query('INSERT INTO zz_semaphores (id_utente, posizione, updated) VALUES ('.prepare(Auth::user()['id']).', '.prepare($id_module.', '.$id_record).', NOW())');
echo '
<div class="box box-warning box-solid text-center info-active hide">
<div class="box-header with-border">
<h3 class="box-title"><i class="fa fa-warning"></i> '.tr('Attenzione!').'</h3>
</div>
<div class="box-body">
<p>'.tr('I seguenti utenti stanno visualizzando questa pagina').':</p>
<ul class="list">
</ul>
<p>'.tr('Prestare attenzione prima di effettuare modifiche, poichè queste potrebbero essere perse a causa di multipli salvataggi contemporanei').'.</p>
</div>
</div>';
}
if (empty($record)) {
echo '
<p>'.tr('Record non trovato').'.</p>';
} else {
echo '
<div class="nav-tabs-custom">
<ul class="nav nav-tabs pull-right" id="tabs" role="tablist">
<li class="pull-left active header">
<a data-toggle="tab" href="#tab_0">
<i class="'.$structure['icon'].'"></i> '.$structure['title'];
// Pulsante "Aggiungi" solo se il modulo è di tipo "table" e se esiste il template per la popup
if ($structure->hasAddFile() && $structure->permission == 'rw') {
echo '
<button type="button" class="btn btn-primary" data-toggle="modal" data-title="'.tr('Aggiungi').'..." data-target="#bs-popup" data-href="add.php?id_module='.$id_module.'&id_plugin='.$id_plugin.'"><i class="fa fa-plus"></i></button>';
}
echo '
</a>
</li>';
// Tab per le informazioni sulle operazioni
if (Auth::admin()) {
echo '
<li class="bg-warning">
<a data-toggle="tab" href="#tab_info" id="link-tab_info">'.tr('Info').'</a>
</li>';
}
$plugins = $dbo->fetchArray('SELECT id, title FROM zz_plugins WHERE idmodule_to='.prepare($id_module)." AND position='tab' AND enabled = 1 ORDER BY zz_plugins.order DESC");
// Tab dei plugin
foreach ($plugins as $plugin) {
echo '
<li>
<a data-toggle="tab" href="#tab_'.$plugin['id'].'" id="link-tab_'.$plugin['id'].'">'.$plugin['title'].'</a>
</li>';
}
echo '
</ul>
<div class="tab-content">
<div id="tab_0" class="tab-pane active">';
// Pulsanti di default
echo '
<div id="pulsanti">
<a class="btn btn-warning" href="'.ROOTDIR.'/controller.php?id_module='.$id_module.'">
<i class="fa fa-chevron-left"></i> '.tr("Torna all'elenco").'
</a>
<div class="pull-right">
{( "name": "button", "type": "print", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
{( "name": "button", "type": "email", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
<a class="btn btn-success" id="save">
<i class="fa fa-check"></i> '.tr('Salva').'
</a>
</div>
</div>
<script>
$(document).ready(function(){
var form = $("#module-edit").find("form").first();
// Aggiunta del submit
form.prepend(\'<button type="submit" id="submit" class="hide"></button>\');
$("#save").click(function(){
$("#submit").trigger("click");
});';
// Pulsanti dinamici
if (!isMobile()) {
echo '
$("#pulsanti").affix({
offset: {
top: 200
}
});
if ($("#pulsanti").hasClass("affix")) {
$("#pulsanti").css("width", $("#tab_0").css("width"));
}
$("#pulsanti").on("affix.bs.affix", function(){
$("#pulsanti").css("width", $("#tab_0").css("width"));
});
$("#pulsanti").on("affix-top.bs.affix", function(){
$("#pulsanti").css("width", "100%");
});';
}
echo '
});
</script>
<div class="clearfix"></div>
<br>';
// Pulsanti personalizzati
$buttons = $structure->filepath('buttons.php');
if (!empty($buttons)) {
ob_start();
include $buttons;
$buttons = ob_get_clean();
echo '
<div class="pull-right" id="pulsanti-modulo">
'.$buttons.'
</div>
<div class="clearfix"></div>
<br>';
}
// Contenuti del modulo
echo '
<div id="module-edit">';
include $structure->getEditFile();
echo '
</div>
</div>';
// Campi personalizzati
echo '
<div class="hide" id="custom_fields_top-edit">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "top" )}
</div>
<div class="hide" id="custom_fields_bottom-edit">
{( "name": "custom_fields", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'" )}
</div>
<script>
$(document).ready(function(){
var form = $("#custom_fields_top-edit").parent().find("form").first();
// Campi a inizio form
form.prepend($("#custom_fields_top-edit").html());
// Campi a fine form
var last = form.find(".panel").last();
if (!last.length) {
last = form.find(".row").eq(-2);
}
last.after($("#custom_fields_bottom-edit").html());
});
</script>';
// Informazioni sulle operazioni
if (Auth::admin()) {
echo '
<div id="tab_info" class="tab-pane">
<ul class="timeline">';
$operations = $dbo->fetchArray('SELECT `zz_operations`.*, `zz_users`.`username` FROM `zz_operations` JOIN `zz_users` ON `zz_operations`.`id_utente` = `zz_users`.`id` WHERE id_module = '.prepare($id_module).' AND id_record = '.prepare($id_record).' ORDER BY `created_at` ASC LIMIT 200');
foreach ($operations as $operation) {
$description = $operation['op'];
$icon = 'pencil-square-o';
$color = null;
$timeline = null;
switch ($operation['op']) {
case 'add':
$description = tr('Creazione');
$icon = 'plus';
$color = 'success';
break;
case 'update':
$description = tr('Modifica');
$icon = 'pencil';
$color = 'info';
break;
case 'delete':
$description = tr('Eliminazione');
$icon = 'times';
$color = 'danger';
break;
default:
$timeline = ' class="timeline-inverted"';
break;
}
echo '
<li'.$timeline.'>
<div class="timeline-badge '.$color.'"><i class="fa fa-'.$icon.'"></i></div>
<div class="timeline-panel">
<div class="timeline-heading">
<h4 class="timeline-title">'.$description.'</h4>
<p><small class="text-muted"><i class="fa fa-clock-o"></i> '.Translator::timestampToLocale($operation['created_at']).'</small></p>
</div>
<div class="timeline-body">
<p>'.tr('Utente: _USER_', [
'_USER_' => $operation['username'],
]).'</p>
</div>
</div>
</li>';
}
echo '
</ul>
</div>';
}
// Plugin
$module_record = $record;
foreach ($plugins as $plugin) {
$record = $module_record;
echo '
<div id="tab_'.$plugin['id'].'" class="tab-pane">';
$id_plugin = $plugin['id'];
include $docroot.'/include/manager.php';
echo '
</div>';
}
$record = $module_record;
echo '
</div>
</div>';
}
redirectOperation($id_module, isset($id_parent) ? $id_parent : $id_record);
// Widget in basso
echo '{( "name": "widgets", "id_module": "'.$id_module.'", "id_record": "'.$id_record.'", "position": "right", "place": "editor" )}';
echo '
<hr>
<a href="'.ROOTDIR.'/controller.php?id_module='.$id_module.'">
<i class="fa fa-chevron-left"></i> '.tr('Indietro').'
</a>';
echo '
<script>';
// Se l'utente ha i permessi in sola lettura per il modulo, converto tutti i campi di testo in span
$read_only = $structure->permission == 'r';
if ($read_only || !empty($block_edit)) {
$not = $read_only ? '' : '.not(".unblockable")';
echo '
$(document).ready(function(){
$("input, textarea, select", "section.content")'.$not.'.attr("readonly", "true");
$("select, input[type=checkbox]", "section.content")'.$not.'.prop("disabled", true);';
if ($read_only) {
echo '
$("a.btn, button, input[type=button], input[type=submit]", "section.content").hide();
$("a.btn-info, a.btn-warning, button.btn-info, button.btn-warning, input[type=button].btn-info", "section.content").show();';
}
echo '
});';
}
?>
var content_was_modified = false;
//controllo se digito qualche valore o cambio qualche select
$("input, textarea, select").bind("change paste keyup", function(event) {
if( event.keyCode >= 32 ){
content_was_modified = true;
}
});
//tolgo il controllo se sto salvando
$(".btn-success, button[type=submit]").bind("click", function() {
content_was_modified = false;
});
$( "form" ).bind( "submit", function() {
content_was_modified = false;
})
// questo controllo blocca il modulo vendita al banco, dopo la lettura con barcode, appare il messaggio di conferma
window.onbeforeunload = function(e){
if(content_was_modified) {
var dialogText = "Uscire senza salvare?";
e.returnValue = dialogText;
$("#main_loading").fadeOut();
return dialogText;
}
};
window.addEventListener("unload", function(e) {
//console.log(e);
$("#main_loading").show();
});
<?php
if (!empty($advanced_sessions)) {
?>
function getActiveUsers(){
$.getJSON('<?php echo ROOTDIR; ?>/ajax.php?op=active_users', {
id_module: <?php echo $id_module; ?>,
id_record: <?php echo $id_record; ?>
},
function(data) {
if (data.length != 0) {
$(".info-active").removeClass("hide");
$(".info-active .list").html("");
$.each( data, function( key, val ) {
$(".info-active .list").append("<li>"+val.username+"</li>");
});
}
else $(".info-active").addClass("hide");
});
}
getActiveUsers();
setInterval(getActiveUsers, <?php echo setting('Timeout notifica di presenza (minuti)') * 60 * 1000; ?>);
<?php
}
?>
</script>
<?php
include_once App::filepath('include|custom|', 'bottom.php');