-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrapport_odt.php
More file actions
768 lines (620 loc) · 34.2 KB
/
Copy pathrapport_odt.php
File metadata and controls
768 lines (620 loc) · 34.2 KB
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
<?php
$res=0;
if (! $res && file_exists("../../main.inc.php")) $res=@include("../../main.inc.php"); // For root directory
if (! $res && file_exists("../../../main.inc.php")) $res=@include("../../../main.inc.php"); // For "custom"
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
dol_include_once('/interventionplus/lib/interventionplus.lib.php');
dol_include_once('/interventionplus/class/interventionplustype.class.php');
dol_include_once('/interventionplus/class/interventionplus_anomalies.class.php');
dol_include_once('/interventionplus/class/interventionplus_priorite_anomalies.class.php');
dol_include_once('/interventionplus/class/interventionplus_equipemnts.class.php');
if (empty($conf->interventionplus->enabled) || !$user->rights->interventionplus->lire) accessforbidden();
// if(!$user->admin && !isset($conf->global->DOLIBARR_PLATEFORME_DEMO_MODULES)) accessforbidden();
// Load translation files required by the page
$langs->loadLangs(array('users', 'other', 'hrm', 'projects'));
$langs->load('interventionplus@interventionplus');
// Protection if external user
if ($user->socid > 0) {
accessforbidden();
}
$usercancreate = $user->rights->interventionplus->creer;
$usercandelete = $user->rights->interventionplus->supprimer;
$action = GETPOST('action', 'aZ09'); // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'interventionplustype'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
$fk_priorite = GETPOST('fk_priorite', 'int');
// Security check
if ($user->socid > 0) { // Protection if external user
//$socid = $user->socid;
accessforbidden();
}
// ini_set('display_startup_errors', 1);
// ini_set('display_errors', 1);
// error_reporting(-1);
$diroutputmassaction = $conf->interventionplus->dir_output.'/temp/massgeneration/'.$user->id;
// Load variable for pagination
$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
$page = 0;
} // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
$sortorder = "ASC";
}
if (!$sortfield) {
$sortfield = "o.rowid";
}
$id_line = GETPOST('id_line', 'int');
$search_rowid = GETPOST('search_rowid', 'alphanohtml');
$search_label = GETPOST('search_label', 'alphanohtml');
$search_equipement = GETPOST('search_equipement', 'int');
$search_priorite = (GETPOST('search_priorite')>0) ? GETPOST('search_priorite') : '';
$search_dateconst_startday = GETPOST('search_dateconst_startday', 'int');
$search_dateconst_startyear = GETPOST('search_dateconst_startyear', 'int');
$search_dateconst_startmonth = GETPOST('search_dateconst_startmonth', 'int');
$search_dateconst_endday = GETPOST('search_dateconst_endday', 'int');
$search_dateconst_endyear = GETPOST('search_dateconst_endyear', 'int');
$search_dateconst_endmonth = GETPOST('search_dateconst_endmonth', 'int');
$search_dateconst_start = dol_mktime(0, 0, 0, $search_dateconst_startmonth, $search_dateconst_startday, $search_dateconst_startyear);
$search_dateconst_end = dol_mktime(23, 59, 59, $search_dateconst_endmonth, $search_dateconst_endday, $search_dateconst_endyear);
$search_dateconst_startday = GETPOST('search_dateconst_startday', 'int');
$search_dateconst_startyear = GETPOST('search_dateconst_startyear', 'int');
$search_dateconst_startmonth = GETPOST('search_dateconst_startmonth', 'int');
$search_daterepr_endday = GETPOST('search_daterepr_endday', 'int');
$search_daterepr_endyear = GETPOST('search_daterepr_endyear', 'int');
$search_daterepr_endmonth = GETPOST('search_daterepr_endmonth', 'int');
$search_daterepr_start = dol_mktime(0, 0, 0, $search_daterepr_startmonth, $search_daterepr_startday, $search_daterepr_startyear);
$search_daterepr_end = dol_mktime(23, 59, 59, $search_daterepr_endmonth, $search_daterepr_endday, $search_daterepr_endyear);
// Initialize technical objects
$form = new Form($db);
$fuser = new User($db);
$object = new Fichinter($db);
$formfile = new FormFile($db);
$formother = new FormOther($db);
$interventionplus = new interventionplus($db);
$anomalie = new interventionplus_anomalies($db);
$anomalies = new interventionplus_anomalies($db);
$equipemnt = new interventionplus_equipemnts($db);
$equipemntstatic = new interventionplus_equipemnts($db);
$priorite = new interventionplus_priorite_anomalies($db);
$arrayfields = array(
'o.rowid'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
'o.label'=>array('label'=>$langs->trans("Label"), 'checked'=>1, 'position'=>20),
'o.dateconst'=>array('label'=>$langs->trans("DateConst"), 'checked'=>1, 'position'=>20),
'o.daterepr'=>array('label'=>$langs->trans("DateRepr"), 'checked'=>1, 'position'=>20),
'o.priorite'=>array('label'=>$langs->trans("Priorite"), 'checked'=>1, 'position'=>20),
'o.photo'=>array('label'=>$langs->trans("Photo"), 'checked'=>1, 'position'=>20),
);
if($id>0 || empty($ref)){
$result = $object->fetch($id, $ref);
if ($id && !$result) {
print 'Record not found';
exit;
}else{
$id = $object->id;
$ref = $object->ref;
}
}
$socid = $object->socid;
$typesequipemnt = array();
$fk_typeequipemnt=0;
$checkdisabled = $user->admin ? '' : 'disabled';
if($id>0) {
$idtypes = !empty($object->array_options['options_interventionplustype']) ? explode(',', $object->array_options['options_interventionplustype']) : array();
foreach ($idtypes as $key => $fk_type) {
$type = new interventionplustype($db);
$type->fetch($fk_type);
if($type->fk_typeequipemnt>0)
$typesequipemnt[$type->fk_typeequipemnt] = $type->fk_typeequipemnt;
}
$typesequipemnt = $typesequipemnt ? implode(',', $typesequipemnt) : '';
$checkdisabled = $interventionplus->noaccesstointervention($object);
}
$extrafields_intervention = new ExtraFields($db);
$extrafields_intervention->fetch_name_optionals_label($object->table_element);
$diroutputmassaction = $conf->interventionplus->dir_output.'/temp/massgeneration/'.$user->id;
/*
* Actions
*/
if (GETPOST('cancel', 'alpha')) {
$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'predelete') {
$massaction = '';
}
// Purge search criteria
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
// All tests are required to be compatible with all browsers
$search_rowid = "";
$search_label = "";
$search_priorite = "";
$search_equipement = "";
$toselect = '';
$search_dateconst_start = "";
$search_dateconst_startday = "";
$search_dateconst_startmonth = "";
$search_dateconst_startyear = "";
$search_dateconst_end = "";
$search_dateconst_endday = "";
$search_dateconst_endmonth = "";
$search_dateconst_endyear = "";
$search_daterepr_start = "";
$search_daterepr_startday = "";
$search_daterepr_startmonth = "";
$search_daterepr_startyear = "";
$search_daterepr_end = "";
$search_daterepr_endday = "";
$search_daterepr_endmonth = "";
$search_daterepr_endyear = "";
}
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
}
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
$param='';
$param = $id ? '&id='.$id : '';
// $param .= $fk_priorite ? '&fk_priorite='.$fk_priorite : '';
$param .= $search_label ? '&search_label='.urlencode($search_label) : '';
$param .= $search_priorite ? '&search_priorite='.urlencode($search_priorite) : '';
$param .= $sortfield ? '&sortfield='.urlencode($sortfield) : '';
$param .= $sortorder ? '&sortorder='.urlencode($sortorder) : '';
$param .= (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) ? '&contextpage='.urlencode($contextpage) : '';
$param .= $limit ? '&limit='.urlencode($limit) : '';
$param .= $optioncss ? '&optioncss='.urlencode($optioncss) : '';
$param .= $search_dateconst_startday ? '&search_dateconst_startday='.urlencode($search_dateconst_startday) : '';
$param .= $search_dateconst_startyear ? '&search_dateconst_startyear='.urlencode($search_dateconst_startyear) : '';
$param .= $search_dateconst_startmonth ? '&search_dateconst_startmonth='.urlencode($search_dateconst_startmonth) : '';
$param .= $search_dateconst_endday ? '&search_dateconst_endday='.urlencode($search_dateconst_endday) : '';
$param .= $search_dateconst_endyear ? '&search_dateconst_endyear='.urlencode($search_dateconst_endyear) : '';
$param .= $search_dateconst_endmonth ? '&search_dateconst_endmonth='.urlencode($search_dateconst_endmonth) : '';
$param .= $search_daterepr_startday ? '&search_daterepr_startday='.urlencode($search_daterepr_startday) : '';
$param .= $search_daterepr_startyear ? '&search_daterepr_startyear='.urlencode($search_daterepr_startyear) : '';
$param .= $search_daterepr_startmonth ? '&search_daterepr_startmonth='.urlencode($search_daterepr_startmonth) : '';
$param .= $search_daterepr_endday ? '&search_daterepr_endday='.urlencode($search_daterepr_endday) : '';
$param .= $search_daterepr_endyear ? '&search_daterepr_endyear='.urlencode($search_daterepr_endyear) : '';
$param .= $search_daterepr_endmonth ? '&search_daterepr_endmonth='.urlencode($search_daterepr_endmonth) : '';
if(GETPOST('save') && GETPOST('anomalies', 'array')){
$newanomalies = GETPOST('anomalies', 'array');
if(count($newanomalies)>0){
$nbanomalies = 0;
$dirforimage = $conf->interventionplus->dir_output.'/anomalies';
foreach ($newanomalies as $key => $value) {
$fk_priorite = GETPOST('fk_priorite'.$key, 'int');
$fk_equipement = GETPOST('fk_equipement'.$key);
$dateconst = dol_mktime(0, 0, 0, GETPOST('dateconst'.$key.'month'), GETPOST('dateconst'.$key.'day'), GETPOST('dateconst'.$key.'year'));
$daterepr = dol_mktime(0, 0, 0, GETPOST('daterepr'.$key.'month'), GETPOST('daterepr'.$key.'day'), GETPOST('daterepr'.$key.'year'));
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'interventionplus_anomalies (label, fk_priorite, fk_equipement, fk_intervention, dateconst, daterepr, fk_user_author, datec, entity) VALUES ';
$sql .= '(';
$sql .= '"'.$value['label'].'"';
$sql .= ', '.($fk_priorite>0 ? (int)$fk_priorite : 'null');
$sql .= ', '.($fk_equipement>0 ? (int)$fk_equipement : 'null');
$sql .= ', '.$id;
$sql .= ', '.(!empty($dateconst) ? '"'.$db->idate($dateconst).'"' : 'null');
$sql .= ', '.(!empty($daterepr) ? '"'.$db->idate($daterepr).'"' : 'null');
// $sql .= ', "'.$photo.'"';
$sql .= ', '.$user->id;
$sql .= ', "'.$db->idate(dol_now()).'"';
$sql .= ', '.$conf->entity;
$sql .= ') ';
$res = $db->query($sql);
if($res){
$idanomalie = $db->last_insert_id(MAIN_DB_PREFIX.'interventionplus_anomalies');
$nbanomalies++;
if($_FILES['photo'.$key]["name"]){
if (!preg_match('/(\.jpeg|\.jpg|\.png)$/i', $_FILES['photo'.$key]["name"])) { // Logo can be used on a lot of different places. Only jpg and png can be supported.
$langs->load("errors");
setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
}
// Remove to check file size to large
/*if ($_FILES['photo'.$key]["tmp_name"]) {*/
$reg = array();
if (preg_match('/([^\\/:]+)$/i', $_FILES['photo'.$key]["name"], $reg)) {
$original_file = $reg[1];
$isimage = image_format_supported($original_file);
if ($isimage >= 0) {
dol_syslog("Move file ".$_FILES['photo'.$key]["tmp_name"]." to ".$dirforimage.'/'.$idanomalie.'/'.$original_file);
if (!is_dir($dirforimage.'/'.$idanomalie.'/')) {
dol_mkdir($dirforimage.'/'.$idanomalie.'/');
}
$result = dol_move_uploaded_file($_FILES['photo'.$key]["tmp_name"], $dirforimage.'/'.$idanomalie.'/'.$original_file, 1, 0, $_FILES['photo'.$key]['error']);
if ($result > 0) {
$anomalie->fetch($idanomalie);
$anomalie->photo = $original_file;
$anomalie->update($idanomalie);
} elseif (preg_match('/^ErrorFileIsInfectedWithAVirus/', $result)) {
$error++;
$langs->load("errors");
$tmparray = explode(':', $result);
setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors');
} elseif (preg_match('/^ErrorFileSizeTooLarge/', $result)) {
$error++;
setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors');
} else {
$error++;
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
}
} else {
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
}
}
}
}else{
}
}
if ($res) {
setEventMessages($langs->trans("RecordsGenerated", $nbanomalies), null, 'mesgs');
$db->commit();
} else {
setEventMessages('Error '.get_class($anomalies).' '. $db->lasterror(), null, 'errors');
$db->rollback();
}
}
header('Location: '.$_SERVER['PHP_SELF'].'?page='.$page.$param);
exit();
}
if($action == 'update' && $id_line>0){
$label = GETPOST('label');
$fk_priorite = GETPOST('fk_priorite');
$fk_equipement = GETPOST('fk_equipement');
$daterepr = dol_mktime(0, 0, 0, GETPOST('datereprmonth'), GETPOST('datereprday'), GETPOST('daterepryear'));
$dateconst = dol_mktime(0, 0, 0, GETPOST('dateconstmonth'), GETPOST('dateconstday'), GETPOST('dateconstyear'));
$anomalie = new interventionplus_anomalies($db);
$anomalie->fetch($id_line);
$anomalie->label = $label;
$anomalie->fk_priorite = $fk_priorite;
$anomalie->fk_equipement = $fk_equipement;
$anomalie->dateconst = $dateconst;
$anomalie->daterepr = $daterepr;
$res = $anomalie->update($id_line);
if($res>0){
$actiontable == '';
$id_ligne = '';
if($_FILES['photo']["name"]){
$dirforimage = $conf->interventionplus->dir_output.'/anomalies/'.$id_line;
if (!preg_match('/(\.jpeg|\.jpg|\.png)$/i', $_FILES['photo']["name"])) { // Logo can be used on a lot of different places. Only jpg and png can be supported.
$langs->load("errors");
setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
}
// Remove to check file size to large
/*if ($_FILES['photo']["tmp_name"]) {*/
$reg = array();
if (preg_match('/([^\\/:]+)$/i', $_FILES['photo']["name"], $reg)) {
$original_file = $reg[1];
$isimage = image_format_supported($original_file);
if ($isimage >= 0) {
dol_syslog("Move file ".$_FILES['photo']["tmp_name"]." to ".$dirforimage.'/'.$original_file);
if (!is_dir($dirforimage)) {
dol_mkdir($dirforimage);
}
$result = dol_move_uploaded_file($_FILES['photo']["tmp_name"], $dirforimage.'/'.$original_file, 1, 0, $_FILES['photo']['error']);
if ($result > 0) {
$anomalie->fetch($id_line);
$photofilename = $anomalie->photo;
$phototodelete = $dirforimage.'/'.$id_line.'/'.$photofilename;
if ($photofilename != '') {
dol_delete_file($phototodelete);
}
$anomalie->photo = $original_file;
$anomalie->update($id_line);
} elseif (preg_match('/^ErrorFileIsInfectedWithAVirus/', $result)) {
$error++;
$langs->load("errors");
$tmparray = explode(':', $result);
setEventMessages($langs->trans('ErrorFileIsInfectedWithAVirus', $tmparray[1]), null, 'errors');
} elseif (preg_match('/^ErrorFileSizeTooLarge/', $result)) {
$error++;
setEventMessages($langs->trans("ErrorFileSizeTooLarge"), null, 'errors');
} else {
$error++;
setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
}
} else {
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
}
}
}
setEventMessages($langs->trans("RecordModifiedSuccessfully"), null, 'mesgs');
}else
setEventMessages('Error '.get_class($object).' '. $anomalie->errors, null, 'errors');
header('Location: ./list.php?page='.$page.$param);
exit();
}
if ($action == 'removeimg' && $id_line>0) {
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
$anomalie->fetch($id_line);
$photofilename = $anomalie->photo;
$dirforimage = $conf->interventionplus->dir_output.'/anomalies/'.$id_line.'/'.$photofilename;
if ($photofilename != '') {
dol_delete_file($dirforimage);
}
header('Location: ./list.php?page='.$page.$param);
exit;
}
// Delete recu en masse
if ($massaction == 'predelete' && $usercandelete) {
$error = 0;
$nbchanged = 0;
$ttr = 0;
$ids = '';
$db->begin();
$nbchanged = count($toselect);
foreach ($toselect as $recuid) {
$ids = ($ids != '') ? $ids.','.$recuid : $recuid;
}
if($ids != '') {
$result = $db->query("DELETE FROM ".MAIN_DB_PREFIX.$anomalies->table_element." WHERE rowid IN (".$ids.") ");
if (!$result) setEventMessages($db->lasterror(), null, 'errors');
}
if (!$error) {
setEventMessages($langs->trans("RecordsDeleted", $nbchanged), null, 'mesgs');
$db->commit();
} else {
$db->rollback();
}
header('Location: '.$_SERVER['PHP_SELF'].'?page='.$page.$param);
exit();
}
// Mass actions
/*
* View
*/
$title = $langs->trans('Anomalies');
$arrayofjs = array('interventionplus/js/script.js.php');
llxHeader('', $title, $help_url = '', $target = '', $disablejs = 0, $disablehead = 0, $arrayofjs);
$sql = "SELECT";
$sql .= " o.rowid, o.label, o.fk_priorite, o.dateconst, o.daterepr, o.fk_equipement, o.datec, o.photo";
$sql .= ", t.label as priorite, t.color";
$sql .= ", eq.code, eq.nom";
$sql .= ", u.login as login, u.lastname as lastname, u.firstname as firstname, CONCAT(u.firstname, ' ', u.lastname) as full_name, u.email as user_email, u.statut as user_status, u.entity as user_entity, u.office_phone as office_phone, u.office_fax as office_fax, u.user_mobile as user_mobile, u.job as job, u.gender as gender";
$sql .= " FROM ".MAIN_DB_PREFIX."interventionplus_anomalies as o";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'interventionplus_priorite_anomalies as t ON o.fk_priorite = t.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'interventionplus_equipemnts as eq ON o.fk_equipement = eq.rowid';
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON o.fk_user_author = u.rowid';
$sql .= " WHERE fk_intervention=".$id;
// Label
if (!empty($search_label)) {
$sql .= natural_search("o.label", $search_label);
}
$sql .= $search_priorite>0 ? ' AND o.fk_priorite='.$search_priorite : '';
$sql .= $search_equipement>0 ? ' AND o.fk_equipement='.$search_equipement : '';
if ($search_dateconst_start) $sql .= " AND CAST(o.dateconst as date) >= '".$db->idate($search_dateconst_start)."'";
if ($search_dateconst_end) $sql .= " AND CAST(o.dateconst as date) <= '".$db->idate($search_dateconst_end)."'";
if ($search_daterepr_start) $sql .= " AND CAST(o.daterepr as date) >= '".$db->idate($search_daterepr_start)."'";
if ($search_daterepr_end) $sql .= " AND CAST(o.daterepr as date) <= '".$db->idate($search_daterepr_end)."'";
$sql .= ' GROUP BY o.rowid';
$sql .= $db->order($sortfield, $sortorder);
// Count total nb of records
$nbtotalofrecords = '';
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST) || 1>0) {
$result = $db->query($sql);
$nbtotalofrecords = $db->num_rows($result);
if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
$page = 0;
$offset = 0;
}
}
$sql .= $db->plimit($limit + 1, $offset);
$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("Configurationinterventionplus"), $linkback, 'title_setup');
$head = interventionplusAdminPrepareHead();
print dol_get_fiche_head($head, 'rapportodt', $langs->trans("RapportOdt"), -1, 'generic');
print '<div class="underbanner clearboth"></div>';
//print $sql;
$resql = $db->query($sql);
if ($resql) {
$num = $db->num_rows($resql);
$arrayofselected = is_array($toselect) ? $toselect : array();
// List of mass actions available
$arrayofmassactions = array();
if (!empty($usercandelete) || $user->admin) {
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
// Lines of title fields
print '<form id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" method="POST" enctype="multipart/form-data">'."\n";
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="'.(($action == 'edit' && $id_line) ? 'update' : 'list').'">';
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
print '<input type="hidden" name="id" value="'.$id.'">';
print '<input type="hidden" name="socid" value="'.$socid.'">';
print '<input type="hidden" name="lastline" id="lastline" value="'.($num ? $num : 0).'">';
if($id_line && $action == 'edit')
print '<input type="hidden" name="id_line" value="'.$id_line.'">';
$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', '', 'add_task', $usercancreate, array('attr'=>['onclick'=>'add_anomalie()']));
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $task->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
// $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
// $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields = (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
print '<div class="div-table-responsive">';
print '<table class="tagtable liste">'."\n";
// Filters
print '<tr class="liste_titre_filter">';
// print '<td width="200px" class="width100 liste_titre">';
// // print '<input class="flat maxwidth50" type="text" name="search_rowid" value="'.dol_escape_htmltag($search_rowid).'">';
// print '</td>';
print '<td class="liste_titre">';
print '<input class="flat maxwidth100" type="text" name="search_label" value="'.dol_escape_htmltag($search_label).'">';
print '</td>';
print '<td class="select2js">';
print $anomalies->select_priorite('search_priorite', $search_priorite, 1, 'width200');
print '</td>';
print '<td class="center">';
print '<div class="nowrap">';
print $form->selectDate($search_dateconst_start, 'search_dateconst_start', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
print '</div>';
print '<div class="nowrap">';
print $form->selectDate($search_dateconst_end, 'search_dateconst_end', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
print '</div>';
print '</td>';
print '<td class="center">';
print '<div class="nowrap">';
print $form->selectDate($search_daterepr_start, 'search_daterepr_start', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
print '</div>';
print '<div class="nowrap">';
print $form->selectDate($search_daterepr_end, 'search_daterepr_end', 0, 0, 1, "search_form", 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
print '</div>';
print '</td>';
print '<td class="select2js">';
print $equipemnt->selectEquipements($socid, 'search_equipement', $search_equipement, 'width150', '', '', $disabled, $morefilter, 0);
print '</td>';
print '<td>';
print '</td>';
// Action column
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
print $searchpicto;
print '</td>';
print "</tr>\n";
print '<tr class="liste_titre">';
// print_liste_field_titre($langs->trans('Ref'), $_SERVER["PHP_SELF"], "o.rowid", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans('Anomalie'), $_SERVER["PHP_SELF"], "o.label", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans('Priorite'), $_SERVER["PHP_SELF"], "o.fk_priorite", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans('DateConst'), $_SERVER["PHP_SELF"], "o.dateconst", "", $param, '', $sortfield, $sortorder, ' center ');
print_liste_field_titre($langs->trans('DateRepr'), $_SERVER["PHP_SELF"], "o.daterepr", "", $param, '', $sortfield, $sortorder, ' center ');
print_liste_field_titre($langs->trans('Equipement'), $_SERVER["PHP_SELF"], "o.fk_priorite", "", $param, '', $sortfield, $sortorder);
print_liste_field_titre($langs->trans('Photo'), $_SERVER["PHP_SELF"], "o.photo", "", $param, '', $sortfield, $sortorder, ' right ');
print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
print "</tr>\n";
print '<tbody class="list_lines">';
// If we ask a dedicated card and not allow to see it, we force on user.
if ($num > 0) {
// Lines
$i = 0;
$totalarray = array();
$totalarray['nbfield'] = 0;
$totalduration = 0;
while ($i < min($num, $limit)) {
$obj = $db->fetch_object($resql);
print '<tr class="oddeven tr_line" data-id="'.$obj->rowid.'">';
// print '<td class="nowrap">';
// print img_picto('', $task->picto, 'class="pictofixedwidth"').' '.$obj->rowid;
// print '</td>';
print '<td class="">';
if($action == 'edit' && $id_line == $obj->rowid){
print '<input name="label" value="'.$obj->label.'" class="width80p">';
}else
print $obj->label;
print '</td>';
print '<td class="select2js">';
if($action == 'edit' && $id_line == $obj->rowid){
print $anomalies->select_priorite('fk_priorite', ($obj->fk_priorite ? $obj->fk_priorite : $fk_priorite));
}else{
print !empty($obj->priorite) ? '<span class="badge" style="color:#fff ;background:'.($obj->color ? $obj->color : '#aaa').'">'.$obj->priorite.'</span>' : '';
}
print '</td>';
print '<td class="center">';
if($action == 'edit' && $id_line == $obj->rowid){
print $form->selectDate($obj->dateconst, 'dateconst', 0, 0, 1);
}else{
print $obj->dateconst ?dol_print_date($obj->dateconst, 'day') : '';
}
print '</td>';
print '<td class="center">';
if($action == 'edit' && $id_line == $obj->rowid){
print $form->selectDate($obj->daterepr, 'daterepr', 0, 0, 1);
}else{
print $obj->daterepr ? dol_print_date($obj->daterepr, 'day') : '';
}
print '</td>';
print '<td>';
if($action == 'edit' && $id_line == $obj->rowid){
// print $equipemnt->selectEquipements($socid, 'fk_equipement', $obj->fk_equipement, 'width150', '', '', $disabled, $morefilter, 0, 1, $langs->trans('Intervention'));
print $equipemnt->selectEquipements($fk_client = $socid, $name = "fk_equipement", $value=$obj->fk_equipement, $morecss = 'width200 maxwidth200', $idfils='', $checklevel=0, $moreparam='', $morefilter='', $showclient=1, $addjscombo=1, $showempty=$langs->trans('AnomaliIntervention'));
}else{
$equipemntstatic->id = $obj->fk_equipement;
$equipemntstatic->code = $obj->code;
$equipemntstatic->nom = $obj->nom;
print $equipemntstatic->getNomUrl(1);
}
print '</td>';
print '<td class="right">';
if($action == 'edit' && $id_line == $obj->rowid){
print '<input type="file" name="photo" id="photo">';
} else {
if ($obj->photo && file_exists($conf->interventionplus->dir_output.'/anomalies/'.$obj->rowid.'/'.$obj->photo)) {
print '<div class="inline-block valignmiddle">';
print '<img style="max-height: 80px" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=interventionplus&file='.urlencode('anomalies/'.$obj->rowid.'/'.$obj->photo).'">';
print '</div>';
print '<div class="inline-block valignmiddle marginrightonly"><a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$id.'&id_line='.$obj->rowid.'&action=removeimg&token='.$_SESSION['newtoken'].'">'.img_delete($langs->trans("Delete"), '', 'marginleftonly').'</a></div>';
}
}
print '</td>';
// Action column
print '<td class="nowrap center">';
if($action == 'edit' && $obj->rowid == $id_line){
print '<input type="submit" name="save" class="button badge-status4" value="'.$langs->trans('Save').'">';
print '<input type="submit" name="cancel" class="button" value="'.$langs->trans('Cancel').'">';
}else{
print '<a href="list.php?action=edit&id_line='.$obj->rowid.'&id='.$id.$param.'">';
print img_picto($langs->trans("Edit"), 'edit', 'class="valignmiddle marginleftonly paddingrightonly"');
print '</a>';
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
if (in_array($obj->rowid, $arrayofselected)) {
$selected = 1;
}
print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
}
}
print '</td>';
print '</tr>'."\n";
$i++;
}
}
print '</tbody>';
// Si il n'y a pas d'enregistrement suite à une recherche
if ($num == 0) {
$colspan = 6;
print '<tr><td colspan="'.$colspan.'" class="opacitymedium tr_noresult">'.$langs->trans("NoRecordFound").'</td></tr>';
}
print '</table>';
print '<div class="center hidden btnsave" id="save_newlines" class="hidden">';
if($usercancreate){
print '<input type="submit" class="butAction badge-status4" name="save" value="'.$langs->trans('Save').'">';
}
else{
print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans('Save').'</span>';
}
print '<input type="submit" class="butAction" name="cancel" value="'.$langs->trans('Cancel').'"></div>';
print '</div>';
print '</form>';
} else {
dol_print_error($db);
}
// End of page
llxFooter();
$db->close();