/
html.formother.class.php
1341 lines (1204 loc) · 55.1 KB
/
html.formother.class.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
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* Copyright (c) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
*
* 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 <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/class/html.formother.class.php
* \ingroup core
* \brief Fichier de la classe des fonctions predefinie de composants html autre
*/
/**
* Classe permettant la generation de composants html autre
* Only common components are here.
*/
class FormOther
{
private $db;
/**
* @var string Error code (or message)
*/
public $error;
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
public function __construct($db)
{
$this->db = $db;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML select list of export models
*
* @param string $selected Id modele pre-selectionne
* @param string $htmlname Nom de la zone select
* @param string $type Type des modeles recherches
* @param int $useempty Show an empty value in list
* @param int $fk_user User that has created the template (this is set to null to get all export model when EXPORTS_SHARE_MODELS is on)
* @return void
*/
public function select_export_model($selected = '', $htmlname = 'exportmodelid', $type = '', $useempty = 0, $fk_user = null)
{
// phpcs:enable
global $conf, $langs, $user;
$sql = "SELECT rowid, label, fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."export_model";
$sql .= " WHERE type = '".$this->db->escape($type)."'";
if (!empty($fk_user)) $sql .= " AND fk_user IN (0, ".$fk_user.")"; // An export model
$sql .= " ORDER BY rowid";
$result = $this->db->query($sql);
if ($result)
{
print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
if ($useempty)
{
print '<option value="-1"> </option>';
}
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$label = $obj->label;
if ($obj->fk_user == 0) {
$label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
}
elseif (! empty($conf->global->EXPORTS_SHARE_MODELS) && empty($fk_user) && is_object($user) && $user->id != $obj->fk_user) {
$tmpuser = new User($this->db);
$tmpuser->fetch($obj->fk_user);
$label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
}
if ($selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
}
else
{
print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
}
print $label;
print '</option>';
$i++;
}
print "</select>";
print ajax_combobox($htmlname);
}
else {
dol_print_error($this->db);
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of export models
*
* @param string $selected Id modele pre-selectionne
* @param string $htmlname Nom de la zone select
* @param string $type Type des modeles recherches
* @param int $useempty Affiche valeur vide dans liste
* @param int $fk_user User that has created the template (this is set to null to get all export model when EXPORTS_SHARE_MODELS is on)
* @return void
*/
public function select_import_model($selected = '', $htmlname = 'importmodelid', $type = '', $useempty = 0, $fk_user = null)
{
// phpcs:enable
global $conf, $langs, $user;
$sql = "SELECT rowid, label, fk_user";
$sql .= " FROM ".MAIN_DB_PREFIX."import_model";
$sql .= " WHERE type = '".$this->db->escape($type)."'";
if (!empty($fk_user)) $sql .= " AND fk_user IN (0, ".$fk_user.")"; // An export model
$sql .= " ORDER BY rowid";
$result = $this->db->query($sql);
if ($result)
{
print '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
if ($useempty)
{
print '<option value="-1"> </option>';
}
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$label = $obj->label;
if ($obj->fk_user == 0) {
$label .= ' <span class="opacitymedium">('.$langs->trans("Everybody").')</span>';
}
elseif (! empty($conf->global->EXPORTS_SHARE_MODELS) && empty($fk_user) && is_object($user) && $user->id != $obj->fk_user) {
$tmpuser = new User($this->db);
$tmpuser->fetch($obj->fk_user);
$label .= ' <span class="opacitymedium">('.$tmpuser->getFullName($langs).')</span>';
}
if ($selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected data-html="'.dol_escape_htmltag($label).'">';
}
else
{
print '<option value="'.$obj->rowid.'" data-html="'.dol_escape_htmltag($label).'">';
}
print $label;
print '</option>';
$i++;
}
print "</select>";
print ajax_combobox($htmlname);
}
else {
dol_print_error($this->db);
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of ecotaxes with label
*
* @param string $selected Preselected ecotaxes
* @param string $htmlname Name of combo list
* @return integer
*/
public function select_ecotaxes($selected = '', $htmlname = 'ecotaxe_id')
{
// phpcs:enable
global $langs;
$sql = "SELECT e.rowid, e.code, e.label, e.price, e.organization,";
$sql .= " c.label as country";
$sql .= " FROM ".MAIN_DB_PREFIX."c_ecotaxe as e,".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE e.active = 1 AND e.fk_pays = c.rowid";
$sql .= " ORDER BY country, e.organization ASC, e.code ASC";
dol_syslog(get_class($this).'::select_ecotaxes', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
print '<select class="flat" name="'.$htmlname.'">';
$num = $this->db->num_rows($resql);
$i = 0;
print '<option value="-1"> </option>'."\n";
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($selected && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'" selected>';
}
else
{
print '<option value="'.$obj->rowid.'">';
//print '<option onmouseover="showtip(\''.$obj->label.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
}
$selectOptionValue = $obj->code.' - '.$obj->label.' : '.price($obj->price).' '.$langs->trans("HT").' ('.$obj->organization.')';
print $selectOptionValue;
print '</option>';
$i++;
}
}
print '</select>';
return 0;
}
else
{
dol_print_error($this->db);
return 1;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of revenue stamp for country
*
* @param string $selected Value of preselected revenue stamp
* @param string $htmlname Name of combo list
* @param string $country_code Country Code
* @return string HTML select list
*/
public function select_revenue_stamp($selected = '', $htmlname = 'revenuestamp', $country_code = '')
{
// phpcs:enable
global $langs;
$out = '';
$sql = "SELECT r.taux, r.revenuestamp_type";
$sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r,".MAIN_DB_PREFIX."c_country as c";
$sql .= " WHERE r.active = 1 AND r.fk_pays = c.rowid";
$sql .= " AND c.code = '".$country_code."'";
dol_syslog(get_class($this).'::select_revenue_stamp', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$out .= '<select class="flat" name="'.$htmlname.'">';
$num = $this->db->num_rows($resql);
$i = 0;
$out .= '<option value="0"> </option>'."\n";
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if (($selected && $selected == $obj->taux) || $num == 1)
{
$out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').' selected>';
}
else
{
$out .= '<option value="'.$obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '').'"'.($obj->revenuestamp_type == 'percent' ? ' data-type="percent"' : '').'>';
//print '<option onmouseover="showtip(\''.$obj->libelle.'\')" onMouseout="hidetip()" value="'.$obj->rowid.'">';
}
$out .= $obj->taux.($obj->revenuestamp_type == 'percent' ? '%' : '');
$out .= '</option>';
$i++;
}
}
$out .= '</select>';
return $out;
}
else
{
dol_print_error($this->db);
return '';
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return a HTML select list to select a percent
*
* @param integer $selected pourcentage pre-selectionne
* @param string $htmlname nom de la liste deroulante
* @param int $disabled Disabled or not
* @param int $increment increment value
* @param int $start start value
* @param int $end end value
* @param int $showempty Add also an empty line
* @return string HTML select string
*/
public function select_percent($selected = 0, $htmlname = 'percent', $disabled = 0, $increment = 5, $start = 0, $end = 100, $showempty = 0)
{
// phpcs:enable
$return = '<select class="flat" name="'.$htmlname.'" '.($disabled ? 'disabled' : '').'>';
if ($showempty) $return .= '<option value="-1"'.(($selected == -1 || $selected == '') ? ' selected' : '').'> </option>';
for ($i = $start; $i <= $end; $i += $increment)
{
if ($selected != '' && (int) $selected == $i)
{
$return .= '<option value="'.$i.'" selected>';
}
else
{
$return .= '<option value="'.$i.'">';
}
$return .= $i.' % ';
$return .= '</option>';
}
$return .= '</select>';
return $return;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return select list for categories (to use in form search selectors)
*
* @param int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated.
* @param integer $selected Preselected value
* @param string $htmlname Name of combo list
* @param int $nocateg Show also an entry "Not categorized"
* @param int $showempty Add also an empty line
* @param string $morecss More CSS
* @return string Html combo list code
* @see select_all_categories()
*/
public function select_categories($type, $selected = 0, $htmlname = 'search_categ', $nocateg = 0, $showempty = 1, $morecss = '')
{
// phpcs:enable
global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
// For backward compatibility
if (is_numeric($type))
{
dol_syslog(__METHOD__.': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING);
}
// Load list of "categories"
$static_categs = new Categorie($this->db);
$tab_categs = $static_categs->get_full_arbo($type);
$moreforfilter = '';
// Enhance with select2
if ($conf->use_javascript_ajax)
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
$comboenhancement = ajax_combobox('select_categ_'.$htmlname);
$moreforfilter .= $comboenhancement;
}
// Print a select with each of them
$moreforfilter .= '<select class="flat minwidth100'.($morecss ? ' '.$morecss : '').'" id="select_categ_'.$htmlname.'" name="'.$htmlname.'">';
if ($showempty) $moreforfilter .= '<option value="0"> </option>'; // Should use -1 to say nothing
if (is_array($tab_categs))
{
foreach ($tab_categs as $categ)
{
$moreforfilter .= '<option value="'.$categ['id'].'"';
if ($categ['id'] == $selected) $moreforfilter .= ' selected';
$moreforfilter .= '>'.dol_trunc($categ['fulllabel'], 50, 'middle').'</option>';
}
}
if ($nocateg)
{
$langs->load("categories");
$moreforfilter .= '<option value="-2"'.($selected == -2 ? ' selected' : '').'>- '.$langs->trans("NotCategorized").' -</option>';
}
$moreforfilter .= '</select>';
return $moreforfilter;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return select list for categories (to use in form search selectors)
*
* @param string $selected Preselected value
* @param string $htmlname Name of combo list (example: 'search_sale')
* @param User $user Object user
* @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status
* @param int $showempty 1=show also an empty value
* @param string $morecss More CSS
* @param int $norepresentative Show also an entry "Not categorized"
* @return string Html combo list code
*/
public function select_salesrepresentatives($selected, $htmlname, $user, $showstatus = 0, $showempty = 1, $morecss = '', $norepresentative = 0)
{
// phpcs:enable
global $conf, $langs;
$langs->load('users');
$out = '';
// Enhance with select2
if ($conf->use_javascript_ajax)
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
$comboenhancement = ajax_combobox($htmlname);
if ($comboenhancement)
{
$out.=$comboenhancement;
}
}
// Select each sales and print them in a select input
$out.='<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
if ($showempty) $out.='<option value="0"> </option>';
// Get list of users allowed to be viewed
$sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut, u.login";
$sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u";
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
{
if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql_usr.= " WHERE u.entity IS NOT NULL"; // Show all users
} else {
$sql_usr.= " WHERE EXISTS (SELECT ug.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug WHERE u.rowid = ug.fk_user AND ug.entity IN (".getEntity('usergroup')."))";
$sql_usr.= " OR u.entity = 0"; // Show always superadmin
}
}
else
{
$sql_usr.= " WHERE u.entity IN (".getEntity('user').")";
}
if (empty($user->rights->user->user->lire)) $sql_usr.=" AND u.rowid = ".$user->id;
if (! empty($user->socid)) $sql_usr.=" AND u.fk_soc = ".$user->socid;
// Add existing sales representatives of thirdparty of external user
if (empty($user->rights->user->user->lire) && $user->socid)
{
$sql_usr.=" UNION ";
$sql_usr.= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut, u2.login";
$sql_usr.= " FROM ".MAIN_DB_PREFIX."user as u2, ".MAIN_DB_PREFIX."societe_commerciaux as sc";
if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
{
if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
$sql_usr.= " WHERE u2.entity IS NOT NULL"; // Show all users
} else {
$sql_usr.= " WHERE EXISTS (SELECT ug2.fk_user FROM ".MAIN_DB_PREFIX."usergroup_user as ug2 WHERE u2.rowid = ug2.fk_user AND ug2.entity IN (".getEntity('usergroup')."))";
}
}
else
{
$sql_usr.= " WHERE u2.entity IN (".getEntity('user').")";
}
$sql_usr.= " AND u2.rowid = sc.fk_user AND sc.fk_soc=".$user->socid;
}
$sql_usr.= " ORDER BY statut DESC, lastname ASC"; // Do not use 'ORDER BY u.statut' here, not compatible with the UNION.
//print $sql_usr;exit;
$resql_usr = $this->db->query($sql_usr);
if ($resql_usr)
{
while ($obj_usr = $this->db->fetch_object($resql_usr))
{
$out.='<option value="'.$obj_usr->rowid.'"';
if ($obj_usr->rowid == $selected) $out.=' selected';
$out.='>';
$out.=dolGetFirstLastname($obj_usr->firstname, $obj_usr->lastname);
// Complete name with more info
$moreinfo=0;
if (! empty($conf->global->MAIN_SHOW_LOGIN))
{
$out.=($moreinfo?' - ':' (').$obj_usr->login;
$moreinfo++;
}
if ($showstatus >= 0)
{
if ($obj_usr->statut == 1 && $showstatus == 1)
{
$out.=($moreinfo?' - ':' (').$langs->trans('Enabled');
$moreinfo++;
}
if ($obj_usr->statut == 0)
{
$out.=($moreinfo?' - ':' (').$langs->trans('Disabled');
$moreinfo++;
}
}
$out.=($moreinfo?')':'');
$out.='</option>';
}
$this->db->free($resql_usr);
}
else
{
dol_print_error($this->db);
}
if ($norepresentative)
{
$langs->load("companies");
$out.='<option value="-2"'.($selected == -2 ? ' selected':'').'>- '.$langs->trans("NoSalesRepresentativeAffected").' -</option>';
}
$out.='</select>';
return $out;
}
/**
* Return list of project and tasks
*
* @param int $selectedtask Pre-selected task
* @param int $projectid Project id
* @param string $htmlname Name of html select
* @param int $modeproject 1 to restrict on projects owned by user
* @param int $modetask 1 to restrict on tasks associated to user
* @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists
* @param int $useempty 0=Allow empty values
* @param int $disablechildoftaskid 1=Disable task that are child of the provided task id
* @param string $filteronprojstatus Filter on project status ('-1'=no filter, '0,1'=Draft+Validated status)
* @param string $morecss More css
* @return void
*/
public function selectProjectTasks($selectedtask = '', $projectid = 0, $htmlname = 'task_parent', $modeproject = 0, $modetask = 0, $mode = 0, $useempty = 0, $disablechildoftaskid = 0, $filteronprojstatus = '', $morecss = '')
{
global $user, $langs;
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
//print $modeproject.'-'.$modetask;
$task = new Task($this->db);
$tasksarray = $task->getTasksArray($modetask ? $user : 0, $modeproject ? $user : 0, $projectid, 0, $mode, '', $filteronprojstatus);
if ($tasksarray)
{
print '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
if ($useempty) print '<option value="0"> </option>';
$j = 0;
$level = 0;
$this->_pLineSelect($j, 0, $tasksarray, $level, $selectedtask, $projectid, $disablechildoftaskid);
print '</select>';
print ajax_combobox($htmlname);
}
else
{
print '<div class="warning">'.$langs->trans("NoProject").'</div>';
}
}
/**
* Write lines of a project (all lines of a project if parent = 0)
*
* @param int $inc Cursor counter
* @param int $parent Id of parent task we want to see
* @param array $lines Array of task lines
* @param int $level Level
* @param int $selectedtask Id selected task
* @param int $selectedproject Id selected project
* @param int $disablechildoftaskid 1=Disable task that are child of the provided task id
* @return void
*/
private function _pLineSelect(&$inc, $parent, $lines, $level = 0, $selectedtask = 0, $selectedproject = 0, $disablechildoftaskid = 0)
{
global $langs, $user, $conf;
$lastprojectid = 0;
$numlines = count($lines);
for ($i = 0; $i < $numlines; $i++) {
if ($lines[$i]->fk_parent == $parent) {
$var = !$var;
//var_dump($selectedproject."--".$selectedtask."--".$lines[$i]->fk_project."_".$lines[$i]->id); // $lines[$i]->id may be empty if project has no lines
// Break on a new project
if ($parent == 0) // We are on a task at first level
{
if ($lines[$i]->fk_project != $lastprojectid) // Break found on project
{
if ($i > 0) print '<option value="0" disabled>----------</option>';
print '<option value="'.$lines[$i]->fk_project.'_0"';
if ($selectedproject == $lines[$i]->fk_project) print ' selected';
print '>'; // Project -> Task
print $langs->trans("Project").' '.$lines[$i]->projectref;
if (empty($lines[$i]->public))
{
print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
}
else
{
print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
}
//print '-'.$parent.'-'.$lines[$i]->fk_project.'-'.$lastprojectid;
print "</option>\n";
$lastprojectid = $lines[$i]->fk_project;
$inc++;
}
}
$newdisablechildoftaskid = $disablechildoftaskid;
// Print task
if (isset($lines[$i]->id)) // We use isset because $lines[$i]->id may be null if project has no task and are on root project (tasks may be caught by a left join). We enter here only if '0' or >0
{
// Check if we must disable entry
$disabled = 0;
if ($disablechildoftaskid && (($lines[$i]->id == $disablechildoftaskid || $lines[$i]->fk_parent == $disablechildoftaskid)))
{
$disabled++;
if ($lines[$i]->fk_parent == $disablechildoftaskid) $newdisablechildoftaskid = $lines[$i]->id; // If task is child of a disabled parent, we will propagate id to disable next child too
}
print '<option value="'.$lines[$i]->fk_project.'_'.$lines[$i]->id.'"';
if (($lines[$i]->id == $selectedtask) || ($lines[$i]->fk_project.'_'.$lines[$i]->id == $selectedtask)) print ' selected';
if ($disabled) print ' disabled';
print '>';
print $langs->trans("Project").' '.$lines[$i]->projectref;
print ' '.$lines[$i]->projectlabel;
if (empty($lines[$i]->public))
{
print ' ('.$langs->trans("Visibility").': '.$langs->trans("PrivateProject").')';
}
else
{
print ' ('.$langs->trans("Visibility").': '.$langs->trans("SharedProject").')';
}
if ($lines[$i]->id) print ' > ';
for ($k = 0; $k < $level; $k++)
{
print " ";
}
print $lines[$i]->ref.' '.$lines[$i]->label."</option>\n";
$inc++;
}
$level++;
if ($lines[$i]->id) $this->_pLineSelect($inc, $lines[$i]->id, $lines, $level, $selectedtask, $selectedproject, $newdisablechildoftaskid);
$level--;
}
}
}
/**
* Output a HTML thumb of color or a text if not defined.
*
* @param string $color String with hex (FFFFFF) or comma RGB ('255,255,255')
* @param string $textifnotdefined Text to show if color not defined
* @return string HTML code for color thumb
* @see selectColor()
*/
public static function showColor($color, $textifnotdefined = '')
{
$textcolor = 'FFF';
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
if (colorIsLight($color)) $textcolor = '000';
$color = colorArrayToHex(colorStringToArray($color, array()), '');
if ($color) print '<input type="text" class="colorthumb" disabled style="padding: 1px; margin-top: 0; margin-bottom: 0; color: #'.$textcolor.'; background-color: #'.$color.'" value="'.$color.'">';
else print $textifnotdefined;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Output a HTML code to select a color
*
* @param string $set_color Pre-selected color
* @param string $prefix Name of HTML field
* @param string $form_name Deprecated. Not used.
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
* @return void
* @deprecated Use instead selectColor
* @see selectColor()
*/
public function select_color($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '')
{
// phpcs:enable
print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors);
}
/**
* Output a HTML code to select a color. Field will return an hexa color like '334455'.
*
* @param string $set_color Pre-selected color
* @param string $prefix Name of HTML field
* @param string $form_name Deprecated. Not used.
* @param int $showcolorbox 1=Show color code and color box, 0=Show only color code
* @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813')
* @param string $morecss Add css style into input field
* @return string
* @see showColor()
*/
public static function selectColor($set_color = '', $prefix = 'f_color', $form_name = '', $showcolorbox = 1, $arrayofcolors = '', $morecss = '')
{
// Deprecation warning
if ($form_name) {
dol_syslog(__METHOD__.": form_name parameter is deprecated", LOG_WARNING);
}
global $langs, $conf;
$out = '';
if (!is_array($arrayofcolors) || count($arrayofcolors) < 1)
{
$langs->load("other");
if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax))
{
$out .= '<link rel="stylesheet" media="screen" type="text/css" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/css/jPicker-1.1.6.css" />';
$out .= '<script type="text/javascript" src="'.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/jpicker-1.1.6.js"></script>';
$out .= '<script type="text/javascript">
jQuery(document).ready(function(){
$(\'#colorpicker'.$prefix.'\').jPicker( {
window: {
title: \''.dol_escape_js($langs->trans("SelectAColor")).'\', /* any title for the jPicker window itself - displays "Drag Markers To Pick A Color" if left null */
effects:
{
type: \'show\', /* effect used to show/hide an expandable picker. Acceptable values "slide", "show", "fade" */
speed:
{
show: \'fast\', /* duration of "show" effect. Acceptable values are "fast", "slow", or time in ms */
hide: \'fast\' /* duration of "hide" effect. Acceptable values are "fast", "slow", or time in ms */
}
},
position:
{
x: \'screenCenter\', /* acceptable values "left", "center", "right", "screenCenter", or relative px value */
y: \'center\' /* acceptable values "top", "bottom", "center", or relative px value */
},
},
images: {
clientPath: \''.DOL_URL_ROOT.'/includes/jquery/plugins/jpicker/images/\',
picker: { file: \'../../../../../theme/common/colorpicker.png\', width: 14, height: 14 }
},
localization: // alter these to change the text presented by the picker (e.g. different language)
{
text:
{
title: \''.dol_escape_js($langs->trans("SelectAColor")).'\',
newColor: \''.dol_escape_js($langs->trans("New")).'\',
currentColor: \''.dol_escape_js($langs->trans("Current")).'\',
ok: \''.dol_escape_js($langs->trans("Save")).'\',
cancel: \''.dol_escape_js($langs->trans("Cancel")).'\'
}
}
} ); });
</script>';
}
$out .= '<input id="colorpicker'.$prefix.'" name="'.$prefix.'" size="6" maxlength="7" class="flat'.($morecss ? ' '.$morecss : '').'" type="text" value="'.dol_escape_htmltag($set_color).'" />';
}
else // In most cases, this is not used. We used instead function with no specific list of colors
{
if (empty($conf->dol_use_jmobile) && !empty($conf->use_javascript_ajax))
{
$out .= '<link rel="stylesheet" href="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.css" type="text/css" media="screen" />';
$out .= '<script src="'.DOL_URL_ROOT.'/includes/jquery/plugins/colorpicker/jquery.colorpicker.js" type="text/javascript"></script>';
$out .= '<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(\'#colorpicker'.$prefix.'\').colorpicker({
size: 14,
label: \'\',
hide: true
});
});
</script>';
}
$out .= '<select id="colorpicker'.$prefix.'" class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$prefix.'">';
//print '<option value="-1"> </option>';
foreach ($arrayofcolors as $val)
{
$out .= '<option value="'.$val.'"';
if ($set_color == $val) $out .= ' selected';
$out .= '>'.$val.'</option>';
}
$out .= '</select>';
}
return $out;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Creation d'un icone de couleur
*
* @param string $color Couleur de l'image
* @param string $module Nom du module
* @param string $name Nom de l'image
* @param int $x Largeur de l'image en pixels
* @param int $y Hauteur de l'image en pixels
* @return void
*/
public function CreateColorIcon($color, $module, $name, $x = '12', $y = '12')
{
// phpcs:enable
global $conf;
$file = $conf->$module->dir_temp.'/'.$name.'.png';
// On cree le repertoire contenant les icones
if (!file_exists($conf->$module->dir_temp))
{
dol_mkdir($conf->$module->dir_temp);
}
// On cree l'image en vraies couleurs
$image = imagecreatetruecolor($x, $y);
$color = substr($color, 1, 6);
$rouge = hexdec(substr($color, 0, 2)); //conversion du canal rouge
$vert = hexdec(substr($color, 2, 2)); //conversion du canal vert
$bleu = hexdec(substr($color, 4, 2)); //conversion du canal bleu
$couleur = imagecolorallocate($image, $rouge, $vert, $bleu);
//print $rouge.$vert.$bleu;
imagefill($image, 0, 0, $couleur); //on remplit l'image
// On cree la couleur et on l'attribue a une variable pour ne pas la perdre
ImagePng($image, $file); //renvoie une image sous format png
ImageDestroy($image);
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML combo list of week
*
* @param string $selected Preselected value
* @param string $htmlname Nom de la zone select
* @param int $useempty Affiche valeur vide dans liste
* @return string
*/
public function select_dayofweek($selected = '', $htmlname = 'weekid', $useempty = 0)
{
// phpcs:enable
global $langs;
$week = array(
0=>$langs->trans("Day0"),
1=>$langs->trans("Day1"),
2=>$langs->trans("Day2"),
3=>$langs->trans("Day3"),
4=>$langs->trans("Day4"),
5=>$langs->trans("Day5"),
6=>$langs->trans("Day6")
);
$select_week = '<select class="flat" name="'.$htmlname.'">';
if ($useempty)
{
$select_week .= '<option value="-1"> </option>';
}
foreach ($week as $key => $val)
{
if ($selected == $key)
{
$select_week .= '<option value="'.$key.'" selected>';
}
else
{
$select_week .= '<option value="'.$key.'">';
}
$select_week .= $val;
$select_week .= '</option>';
}
$select_week .= '</select>';
return $select_week;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML combo list of month
*
* @param string $selected Preselected value
* @param string $htmlname Name of HTML select object
* @param int $useempty Show empty in list
* @param int $longlabel Show long label
* @param string $morecss More Css
* @return string
*/
public function select_month($selected = '', $htmlname = 'monthid', $useempty = 0, $longlabel = 0, $morecss = 'maxwidth50imp valignmiddle')
{
// phpcs:enable
global $langs;
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
if ($longlabel) $montharray = monthArray($langs, 0); // Get array
else $montharray = monthArray($langs, 1);
$select_month = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
if ($useempty)
{
$select_month .= '<option value="0"> </option>';
}
foreach ($montharray as $key => $val)
{
if ($selected == $key)
{
$select_month .= '<option value="'.$key.'" selected>';
}
else
{
$select_month .= '<option value="'.$key.'">';
}
$select_month .= $val;
$select_month .= '</option>';
}
$select_month .= '</select>';
return $select_month;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return HTML combo list of years
*
* @param string $selected Preselected value (''=current year, -1=none, year otherwise)
* @param string $htmlname Name of HTML select object
* @param int $useempty Affiche valeur vide dans liste
* @param int $min_year Offset of minimum year into list (by default current year -10)
* @param int $max_year Offset of maximum year into list (by default current year + 5)
* @param int $offset Offset
* @param int $invert Invert
* @param string $option Option
* @param string $morecss More CSS
* @return string
*/
public function select_year($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp')
{
// phpcs:enable
print $this->selectyear($selected, $htmlname, $useempty, $min_year, $max_year, $offset, $invert, $option, $morecss);
}
/**
* Return HTML combo list of years
*
* @param string $selected Preselected value (''=current year, -1=none, year otherwise)
* @param string $htmlname Name of HTML select object
* @param int $useempty Affiche valeur vide dans liste
* @param int $min_year Offset of minimum year into list (by default current year -10)
* @param int $max_year Offset of maximum year into list (by default current year + 5)
* @param int $offset Offset
* @param int $invert Invert
* @param string $option Option
* @param string $morecss More css
* @return string
*/
public function selectyear($selected = '', $htmlname = 'yearid', $useempty = 0, $min_year = 10, $max_year = 5, $offset = 0, $invert = 0, $option = '', $morecss = 'valignmiddle maxwidth75imp')
{
$out = '';
$currentyear = date("Y") + $offset;
$max_year = $currentyear + $max_year;
$min_year = $currentyear - $min_year;
if (empty($selected) && empty($useempty)) $selected = $currentyear;
$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"'.$option.' >';
if ($useempty)
{
$selected_html = '';
if ($selected == '') $selected_html = ' selected';
$out .= '<option value=""'.$selected_html.'> </option>';
}
if (!$invert)