-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_card.php
801 lines (724 loc) · 25.1 KB
/
plot_card.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
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
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
<?php
/*
* Copyright (C) 2016 Bruno Généré <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file plot_card.php
* \ingroup plot
* \brief The plot card displays the main attributes of the plot.
* Attributes are in view mode first.
* The user could use the form to update, create or delete an object.
* Top of the form is standardised to display the object identity and navigate the object list.
*/
@include './tpl/maindolibarr.inc.php';
@include './tpl/plot.inc.php';
// Current Plot id and/or Ref
$id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha');
// Page parameters
$action = GETPOST('action', 'alpha');
$confirm = GETPOST('confirm', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$tab = GETPOST('tab', 'alpha');
// Security check
if (! $user->rights->vignoble->plot->read)
accessforbidden();
// Plot classes for C R U D operations
$object = new plot($db);
// Load Extrafields array in object
$extrafields = new ExtraFields($db);
$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
if (($id > 0 || ! empty($ref))) { // R U D operation
if ($object->fetch($id, $ref) >= 0) {
// card actions
if ($tab == 'card') {
if ($action == 'update' && ! $cancel) {
$action = updatePlot($object, $extrafields);
} elseif ($cancel)
$action = 'view';
if ($action == 'confirm_delete') {
deletePlot($object);
}
if ($action == 'builddoc') {
buildPlotDocument($object);
}
if ($action == 'remove_file') {
removePlotFile($object);
}
}
// notes actions
if ($tab == 'notes') {
$permissionnote = $user->rights->vignoble->plot->create;
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php';
}
// View
llxHeader('', $langs->trans('PlotCardTitle'), '');
if ($action == 'edit') {
displayPlotEditForm($object, $extrafields);
} else {
displayPlotTab($action, $object, $extrafields);
}
llxFooter();
}
} else { // We assume create operation
// Security check
if (! $user->rights->vignoble->plot->create)
accessforbidden();
// actions
if ($action == 'add' && ! $cancel) {
$action = addPlot($object, $extrafields, $extralabels);
} elseif ($cancel) {
header("Location: " . dol_buildpath('/vignoble/plot_list.php', 1));
exit();
}
// view
llxHeader('', $langs->trans('PlotCardTitle'), '');
print load_fiche_titre($langs->trans("NewPlot"), '', 'object_plot@vignoble');
if ($action == 'create') {
displayAddPlotForm($object, $extrafields);
}
llxFooter();
}
$db->close();
/**
* Add plot entered in Add Plot Form to the database
*
* @param plot $object
* @param ExtraFields $extrafields
* @return string
*/
function addPlot(plot $object, ExtraFields $extrafields, $extralabels)
{
Global $db, $conf, $user, $langs;
$error = 0;
$object->entity = $conf->entity;
$object->ref = GETPOST('newref', 'alpha');
if (empty($object->ref)) {
$error ++;
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
}
$object->label = GETPOST('label', 'alpha');
$object->description = dol_htmlcleanlastbr(GETPOST('description'));
// Get extrafields values
$ret = $extrafields->setOptionalsFromPost($extrafields->attribute_label, $object);
if ($ret < 0)
$error ++;
$object->fk_user_author = $user->id;
$object->fk_user_modif = $user->id;
if (! $error) {
$id = $object->create($user);
if ($id > 0) {
header("Location: " . dol_buildpath('/vignoble/plot_card.php?tab=card&id=' . $id, 1));
exit();
} else {
setEventMessages($object->error, $object->errors, 'errors');
}
}
return $action = 'create';
}
/**
* Display the form to enter a new plot
*
* @param plot $object
* @param ExtraFields $extrafields
*/
function displayAddPlotForm(plot $object, ExtraFields $extrafields)
{
Global $db, $conf, $user, $langs;
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?tab=card">';
print '<input type="hidden" name="action" value="add">';
dol_fiche_head();
print '<table class="border centpercent">';
// reference
print '<tr><td class="fieldrequired">' . $langs->trans("Fieldref") . '</td><td>';
print '<input class="flat" type="text" name="newref" value="' . GETPOST('newref') . '" >';
print '</td></tr>';
// label
print '<tr><td>' . $langs->trans("Fieldlabel") . '</td><td>';
print '<input class="flat" type="text" name="label" value="' . GETPOST('label') . '" >';
print '</td></tr>';
// description (with editor)
print '<tr><td class="tdtop" width="25%">' . $langs->trans("Description") . '</td><td>';
$doleditor = new DolEditor('description', GETPOST('description'), '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_4, '99%');
$doleditor->Create();
print "</td></tr>";
// extrafields
print $object->showOptionals($extrafields, 'edit');
print '</table>';
dol_fiche_end();
// action buttons
print '<div class="center">';
print '<input type="submit" class="button" name="add" value="' . $langs->trans("Create") . '"> ';
print '<input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
print '</div>';
print '</form>';
}
/**
* Update Plot information in database using the Plot Edit Form data
*
* @param plot $object
* @param ExtraFields $extrafields
* @return string $action 'view' when update is done | 'edit' if fields are not properly entered
*/
function updatePlot(plot $object, ExtraFields $extrafields)
{
Global $db, $conf, $user, $langs;
$error = 0;
// Get attributes values
$object->id = GETPOST('id', 'int');
$object->ref = GETPOST('ref', 'alpha');
$object->label = GETPOST('label', 'alpha');
$object->description = dol_htmlcleanlastbr(GETPOST('description'));
// Check values
if (empty($object->ref)) {
$error ++;
setEventMessages($langs->transnoentitiesnoconv("ErrorFieldRequired", $langs->transnoentitiesnoconv("Ref")), null, 'errors');
}
// Get and check extrafields
$ret = $extrafields->setOptionalsFromPost($extrafields->attribute_label, $object);
if ($ret < 0)
$error ++;
if (! $error) {
$result = $object->update($user);
if ($result > 0) {
return $action = 'view';
} else {
if (! empty($object->errors))
setEventMessages(null, $object->errors, 'errors');
else
setEventMessages($object->error, null, 'errors');
return $action = 'edit';
}
} else {
return $action = 'edit';
}
}
/**
* Delete selected plot from database
*
* ! No control is made on plot use !
*
* @param plot $object
*/
function deletePlot(plot $object)
{
Global $db, $conf, $user, $langs;
$result = $object->delete($user);
if ($result > 0) {
setEventMessages("RecordDeleted", null, 'mesgs');
header("Location: " . dol_buildpath('/vignoble/plot_list.php', 1));
exit();
} else {
if (! empty($object->errors))
setEventMessages(null, $object->errors, 'errors');
else
setEventMessages($object->error, null, 'errors');
}
}
/**
* Build plot document
*
* Not in use yet - see comments end of page.
*
* @param plot $object
*/
function buildPlotDocument(plot $object)
{
Global $db, $conf, $user, $langs;
// Save last template used to generate document
if (GETPOST('model'))
$object->setDocModel($user, GETPOST('model', 'alpha'));
// Define output language
$outputlangs = $langs;
$newlang = '';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id']))
$newlang = $_REQUEST['lang_id'];
if (! empty($newlang)) {
$outputlangs = new Translate("", $conf);
$outputlangs->setDefaultLang($newlang);
}
$result = $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
if ($result <= 0) {
setEventMessages($object->error, $object->errors, 'errors');
$action = '';
}
$action = '';
}
/**
* Remove file associated to current object
*
* File id is provided in Get Post
*
* @param plot $object
*/
function removePlotFile(plot $object)
{
Global $db, $conf, $user, $langs;
if ($object->id > 0) {
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
$langs->load("other");
$upload_dir = $conf->vignoble->dir_output;
$file = $upload_dir . '/' . GETPOST('file');
$ret = dol_delete_file($file, 0, 0, 0, $object);
if ($ret)
setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs');
else
setEventMessages($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), null, 'errors');
}
}
/**
* Display the Plot Edit Form
*
* @param plot $object
* @param ExtraFields $extrafields
*/
function displayPlotEditForm(plot $object, ExtraFields $extrafields)
{
Global $db, $conf, $user, $langs;
print load_fiche_titre($langs->trans("EditPlot"), $object->label, 'object_plot@vignoble');
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?tab=card&id=' . $object->id . '">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="' . $object->id . '">';
dol_fiche_head();
print '<table class="border centpercent">';
// ref
print '<tr><td class="fieldrequired">' . $langs->trans("Fieldref") . '</td><td>';
print '<input class="flat" type="text" name="ref" value="' . $object->ref . '">';
print '</td></tr>';
// label
print '<tr><td>' . $langs->trans("Fieldlabel") . '</td><td>';
print '<input class="flat" type="text" name="label" value="' . $object->label . '">';
print '</td></tr>';
// description
print '<tr><td class="tdtop" width="25%">' . $langs->trans("Description") . '</td><td>';
$doleditor = new DolEditor('description', $object->description, '', 160, 'dolibarr_notes', '', false, true, $conf->global->FCKEDITOR_ENABLE_SOCIETE, ROWS_4, '(50%');
$doleditor->Create();
print "</td></tr>";
// extrafields
if (! empty($extrafields->attribute_label)) {
print $object->showOptionals($extrafields, 'edit');
}
print '</table>';
dol_fiche_end();
print '<div class="center"><input type="submit" class="button" name="save" value="' . $langs->trans("Save") . '">';
print ' <input type="submit" class="button" name="cancel" value="' . $langs->trans("Cancel") . '">';
print '</div>';
print '</form>';
}
/**
* Display the proper Plot Tab based on the tab parameter usin GETPOST.
*
* Support tabs : tasks, notes, info and card as default.
*
* @param string $action
* @param plot $object
* @param ExtraFields $extrafields
*/
function displayPlotTab($action, plot $object, ExtraFields $extrafields)
{
Global $db, $conf, $user, $langs;
$tab = GETPOST('tab', 'alpha');
$form = new Form($db);
$formvignoble = new FormVignoble($db);
$head = getTabsHeader($langs, $object);
dol_fiche_head($head, $tab, $langs->trans("Plot"), 0, 'plot@vignoble');
// object header
$formvignoble->printObjectRef($form, $langs, $object);
switch ($tab) {
case 'tasks':
displayPlotTasks($object, $form);
break;
case 'notes':
$permission = $user->rights->vignoble->plot->create;
$permissionnote = $user->rights->vignoble->plot->create;
$cssclass = "titlefield";
$moreparam = "&tab=notes";
include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php';
break;
case 'info':
$object->info($object->id);
dol_print_object_info($object, 1);
break;
default:
displayPlotCard($action, $object, $extrafields, $form);
break;
}
dol_fiche_end();
}
/**
* Display the plot card in read mode
*
* When $action = delete a confirmation popup
*
* @param string $action
* @param plot $object
* @param ExtraFields $extrafields
* @param Form $form
*/
function displayPlotCard($action, plot $object, ExtraFields $extrafields, Form $form)
{
Global $db, $conf, $user, $langs;
print '<table class="border centpercent">';
if ($action == 'delete') {
print $form->formconfirm($_SERVER["PHP_SELF"] . '?tab=card&id=' . $object->id, $langs->trans('DeletePlot'), $langs->trans('ConfirmDeletePlot') . ' ' . $object->ref, 'confirm_delete', '', 0, 1);
}
// description
print '<tr>';
print '<td class="tdtop" width="25%">' . $langs->trans("Fielddescription") . '</td>';
print '<td>' . (dol_textishtml($object->description) ? $object->description : dol_nl2br($object->description, 1, true)) . '</td>';
print '</tr>';
// Extrafields
print $object->showOptionals($extrafields);
print '</table>';
// edit and delete buttons below the card
print '<div class="tabsAction">';
$parameters = array();
if ($user->rights->vignoble->plot->create) {
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?tab=card&id=' . $object->id . '&action=edit">' . $langs->trans("Modify") . '</a></div>' . "\n";
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('Modify') . '</a></div>' . "\n";
}
if ($user->rights->vignoble->plot->delete) {
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?tab=card&id=' . $object->id . '&action=delete">' . $langs->trans('Delete') . '</a></div>' . "\n";
} else {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">' . $langs->trans('Delete') . '</a></div>' . "\n";
}
print '</div>';
}
/**
* Display the tasks table for the plot.
*
* The table could be sorted and searched on all fields
* Search on date define an interval between start and end
*
* @param plot $plot
* @param Form $form
*/
function displayPlotTasks(plot $plot, Form $form)
{
Global $db, $conf, $user, $langs;
// List of tasks associated to plot
$sort = getTasksort();
$filter = getTaskfilter($plot->id);
$params = buildTaskSearchParameters($filter);
print '<form method="POST" action="' . $_SERVER["PHP_SELF"] . '?tab=tasks&id=' . $plot->id . '">';
print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
print '<input type="hidden" name="id" value="' . $plot->id . '">';
print '<input type="hidden" name="sortfield" value="' . $sort["field"] . '">';
print '<input type="hidden" name="sortorder" value="' . $sort["order"] . '">';
print '<input type="hidden" name="action" value="' . $action . '">';
print '<div class="div-table-responsive">';
print '<table class="liste" style="border-bottom-style: none;">';
// Fields header
print '<tr class="liste_titre">';
print_liste_field_titre($langs->trans("Task"), $_SERVER['PHP_SELF'], 'taskref,date', '', $params, '', $sort["field"], $sort["order"]);
print_liste_field_titre($langs->trans("DateStart"), $_SERVER['PHP_SELF'], 'taskopen,taskref,date', '', $params, '', $sort["field"], $sort["order"]);
print_liste_field_titre($langs->trans("DateEnd"), $_SERVER['PHP_SELF'], 'taskend,taskref,date', '', $params, '', $sort["field"], $sort["order"]);
print_liste_field_titre($langs->trans("Note"), $_SERVER['PHP_SELF'], 'note,taskref,date', '', $params, 'style="width:20%;"', $sort["field"], $sort["order"]);
print_liste_field_titre($langs->trans("ProgressDeclared"), $_SERVER['PHP_SELF'], 'coverage,taskref,date', '', $params, '', $sort["field"], $sort["order"]);
print '<td width="10 px"> ';
print '</td>';
print_liste_field_titre($langs->trans("Date"), $_SERVER['PHP_SELF'], 'date,taskref', '', $params, '', $sort["field"], $sort["order"]);
print_liste_field_titre($langs->trans("By"), $_SERVER['PHP_SELF'], 'firstname,lastname,taskref,date', '', $params, '', $sort["field"], $sort["order"]);
print_liste_field_titre($langs->trans("Progress"), $_SERVER['PHP_SELF'], 'progress,taskref,date', '', $params, '', $sort["field"], $sort["order"]);
print '<td class=" right"> ';
print '</td>';
print "</tr>";
// Search Header
print '<tr class="liste_titre">';
print '<td ><input type="text" class="flat" name="search_tasklabel" value="' . $filter["tasklabel"] . '"> </td>';
print '<td >' . $form->select_date((empty($filter['begin']) ? - 1 : $filter['begin']), 'search_begin', 0, 0, 2, "search_begin", 1, 0, 1) . '</td>';
print '<td >' . $form->select_date((empty($filter['end']) ? - 1 : $filter['end']), 'search_end', 0, 0, 2, "search_end", 1, 0, 1) . '</td>';
print '<td ><input type="text" class="flat" name="search_note" value="' . $filter["note"] . '"></td>';
print '<td ><input type="text" class="flat" name="search_coverage" value="' . $filter["coverage"] . '"></td>';
print '<td > </td>';
print '<td > </td>';
print '<td ><input type="text" class="flat" name="search_by" value="' . $filter["by"] . '"></td>';
print '<td > </td>';
// // Action column
print '<td class=" right">';
print $form->showFilterAndCheckAddButtons(0, 'checkforselect', 1);
print '</td>';
print '</tr>';
$plottask = new Plotcultivationtask($db);
if ($plottask->fetchAllProgress($sort["order"], $sort["field"], 0, 0, $filter["plot"], 'AND')) {
displayPlotTaskLines($plottask);
}
print '</table>';
print '</div>';
print '</form>';
}
/**
* Get fields and order used for the plot task table sort.
*
* Use TaskRef Ascending by default.
*
* @return Array[] with keys : field, order.
*/
function getTasksort()
{
$sortfield = GETPOST(sortfield, 'alpha');
if (empty($sortfield)) {
$sortfield = 'taskref,date';
}
$sortorder = GETPOST(sortorder, 'alpha');
if (empty($sortorder)) {
$sortorder = 'ASC';
}
return $sort = array(
"field" => $sortfield,
"order" => $sortorder
);
}
/**
* Get all data needed to filter the SQL requests on plot task and produce the results
*
* @param int $id
* the current plot id
* @return Array[] containing the following keys :
* id (of the task),
* reference (of the task),
* note,
* coverage,
* plot (array of sql filter conditions for plot task),
*
*/
function getTaskfilter($id)
{
$plotfilter = array();
if (! empty($id))
$plotfilter[] = "t.fk_plot = " . $id;
// Purge search criteria
if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) { // All test are required to be compatible with all browsers
$search_note = '';
$search_coverage = '';
$search_tasklabel = '';
$search_by = '';
$search_begin = '';
$search_beginday = '';
$search_beginmonth = '';
$search_beginyear = '';
$search_end = '';
$search_endday = '';
$search_endmonth = '';
$search_endyear = '';
} else {
$search_tasklabel = GETPOST('search_tasklabel', 'alpha');
if (! empty($search_tasklabel))
$plotfilter[] = "task.label LIKE '%" . $search_tasklabel . "%'";
$search_by = GETPOST('search_by', 'alpha');
if (! empty($search_by))
$plotfilter[] = "(u.firstname LIKE '%" . $search_by . "%' OR u.lastname LIKE '%" . $search_by . "%' )";
$search_note = GETPOST('search_note', 'alpha');
if (! empty($search_note))
$plotfilter[] = "t.note LIKE '%" . $search_note . "%'";
$search_coverage = GETPOST('search_coverage', 'int');
if (! ($search_coverage === "") || ($search_coverage > 0))
$plotfilter[] = "t.coverage = " . $search_coverage;
$search_begin = GETPOST("search_beginyear") . '-' . GETPOST("search_beginmonth") . '-' . GETPOST("search_beginday");
if ($search_begin == '--') { // not in Form check URL
$search_begin = GETPOST("search_begin");
}
if (! empty($search_begin))
$plotfilter[] = "DATE(task.dateo) >= '" . $search_begin . "'";
$search_end = GETPOST("search_endyear") . '-' . GETPOST("search_endmonth") . '-' . GETPOST("search_endday");
if ($search_end == '--') { // not in Form check URL
$search_end = GETPOST("search_end");
}
if (! empty($search_end))
$plotfilter[] = "DATE(task.datee) <= '" . $search_end . "'";
}
$filter = array(
"id" => $id,
"tasklabel" => $search_tasklabel,
"begin" => $search_begin,
"end" => $search_end,
"note" => $search_note,
"coverage" => $search_coverage,
"by" => $search_by,
"plot" => $plotfilter
);
return $filter;
}
/**
* Build the parameters string to be added to URL to keep the filter conditions.
*
* (used for list sort)
*
* @param Array $filter
* the filter conditions including $id
* @return string to be added to URL
*/
function buildTaskSearchParameters($filter)
{
$params = "";
if (! empty($filter["id"]))
$params .= '&tab=tasks&id=' . $filter["id"];
if (! empty($filter["tasklabel"]))
$params .= '&search_tasklabel=' . urlencode($filter["tasklabel"]);
if (! empty($filter["note"]))
$params .= '&search_note=' . urlencode($filter["note"]);
if (! empty($filter["coverage"]))
$params .= '&search_coverage=' . urlencode($filter["coverage"]);
if (! empty($filter["by"]))
$params .= '&search_by=' . urlencode($filter["by"]);
return $params;
}
/**
* Display the plot task lines in a table in read only mode.
*
* Each line display Task ref and label, note and coverage.
*
* @param $plottask array
* the result of the SQL query on plot task
*/
function displayPlotTaskLines($plottask)
{
Global $db, $conf, $user, $langs;
$prevtaskid = 0;
foreach ($plottask->lines as $line) {
$var = ! $var;
print "<tr " . $bc[$var] . ">";
if ($prevtaskid == $line->fk_task) {
$newline = 0;
} else {
$newline = 1;
}
// Task
print '<td >';
if ($newline){
$task = new Task($db);
$task->fetch($line->fk_task);
$url = dol_buildpath('/vignoble/cultivationtaskplot.php?id=' . $task->id, 1);
print '<a href="' . $url . '">';
print $task->ref . '</a>' . ' - ' . $task->label;
}
print '</td>';
// Start date
print '<td >';
if ($newline){
print dol_print_date($task->date_start, "day");
}
print '</td>';
// End date
print '<td >';
if ($newline){
print dol_print_date($task->date_end, "day");
}
print '</td>';
// Note
print '<td >';
if ($newline){
print dol_nl2br($line->note);
}
print '</td>';
// Coverage
print '<td>';
if ($newline){
print $line->coverage . '%';
}
print '</td>';
// blank column
print '<td> ';
print '</td>';
// Date
print '<td>';
print dol_print_date($line->date, "day");
print '</td>';
// By
print '<td>';
$lineuser = new User($db);
$lineuser->id = $line->userid;
$lineuser->lastname = $line->lastname;
$lineuser->firstname = $line->firstname;
print $lineuser->getNomUrl(1);
print '</td>';
// Progress
print '<td>';
print $line->progress . '%';
print '</td>';
print '</tr>';
$prevtaskid = $line->fk_task;
}
}
/**
* Set up the 4 Tabs : Card, Tasks, Notes, Info
*
* @param plot $object
*
*/
function getTabsHeader($langs, $object)
{
$head = array();
$h = 0;
$head[$h][0] = 'plot_card.php?tab=card&id=' . $object->id;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$h ++;
$head[$h][0] = 'plot_card.php?tab=tasks&id=' . $object->id;
$head[$h][1] = $langs->trans("Tasks");
$head[$h][2] = 'tasks';
$h ++;
$head[$h][0] = 'plot_card.php?tab=notes&id=' . $object->id;
$head[$h][1] = $langs->trans("Notes");
$head[$h][2] = 'notes';
$h ++;
$head[$h][0] = 'plot_card.php?tab=info&id=' . $object->id;
$head[$h][1] = $langs->trans("Info");
$head[$h][2] = 'info';
return $head;
}
// END following lines kept for future use
// $formfile = new FormFile($db);
// $formactions = new FormActions($db);
// /**
// * - Display generic features
// */
// print '<div class="fichecenter">'; // global frame
// print '<div class="fichehalfleft">'; // left column
// /**
// * - Display generated documents
// */
// // print 'Generated Documentss<br/>';
// // $ref = dol_sanitizeFileName($object->ref);
// // $file = $conf->vignoble->dir_output . '/' . $ref . '/' . $ref . '.pdf';
// // $relativepath = $ref . '/' . $ref . '.pdf';
// // $filedir = $conf->vignoble->dir_output . '/' . $ref;
// // $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
// // $genallowed = $user->rights->vignoble->plot->create;
// // $delallowed = $user->rights->vignoble->plot->delete;
// // $somethingshown = $formfile->show_documents('vignoble', $ref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
// print '</div>'; // left column end
// print '<div class="fichehalfright">'; // right column
// /**
// * - Display links to other objects (order or invoice)
// */
// // print '<div class="ficheaddleft">';
// // print 'Linked Orders/Invoice<br/>';
// // $linktoelem = $form->showLinkToObjectBlock($object,array());
// // $somethingshown=$form->showLinkedObjectBlock($object,$linktoelem);
// // print '</div>';
// /**
// * - Display links to events
// */
// // print '<div class="ficheaddleft">';
// // print 'Linked Events<br/>';
// // include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
// // $formactions = new FormActions($db);
// // $somethingshown = $formactions->showactions($object, 'plot', $user->socid,1);
// // print '</div>';
// print '</div>'; // right column end
// print '</div>'; // fichecenter