-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
html.form.class.php
3764 lines (3400 loc) · 151 KB
/
html.form.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-2011 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-2011 Regis Houssin <regis@dolibarr.fr>
* 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) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
*
* 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 2 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 htdocs/core/class/html.form.class.php
* \ingroup core
* \brief File of class with all html predefined components
*/
/**
* \class Form
* \brief Class to manage generation of HTML components
* \remarks Only common components must be here.
*/
class Form
{
var $db;
var $error;
// Cache arrays
var $cache_types_paiements=array();
var $cache_conditions_paiements=array();
var $cache_availability=array();
var $cache_demand_reason=array();
var $cache_type_fees=array();
var $tva_taux_value;
var $tva_taux_libelle;
/**
* Constructor
*
* @param DoliDB $DB Database handler
*/
function Form($DB)
{
$this->db = $DB;
}
/**
* Output key field for an editable field
*
* @param string $text Text of label or key to translate
* @param string $htmlname Name of select field
* @param string $preselected Value to show/edit
* @param string $paramkey Key of parameter for Url (unique if there is several parameter to show). In most cases "id".
* @param string $paramvalue Value of parameter for Url
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day', ...)
* @return string HTML edit field
* TODO no GET or POST in class file, use a param
*/
function editfieldkey($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string')
{
global $langs;
$ret='';
$ret.='<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
$ret.=$langs->trans($text);
$ret.='</td>';
if (GETPOST('action') != 'edit'.$htmlname && $perm) $ret.='<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=edit'.$htmlname.'&'.$paramkey.'='.$paramvalue.'">'.img_edit($langs->trans('Edit'),1).'</a></td>';
$ret.='</tr></table>';
return $ret;
}
/**
* Output val field for an editable field
*
* @param string $text Text of label (not used in this function)
* @param string $htmlname Name of select field
* @param string $preselected Value to show/edit
* @param string $paramkey Key of parameter (unique if there is several parameter to show)
* @param boolean $perm Permission to allow button to edit parameter
* @param string $typeofdata Type of data ('string' by default, 'email', 'text' or 'textarea', 'day', ...)
* @param string $editvalue Use this value instead $preselected
* @return string HTML edit field
* TODO no GET or POST in class file, use a param
*/
function editfieldval($text,$htmlname,$preselected,$paramkey,$paramvalue,$perm,$typeofdata='string',$editvalue='')
{
global $langs,$db;
$ret='';
if (GETPOST('action') == 'edit'.$htmlname)
{
$ret.="\n";
$ret.='<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
$ret.='<input type="hidden" name="action" value="set'.$htmlname.'">';
$ret.='<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
$ret.='<input type="hidden" name="'.$paramkey.'" value="'.$paramvalue.'">';
$ret.='<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
$ret.='<tr><td>';
if (in_array($typeofdata,array('string','email')))
{
$ret.='<input type="text" id="'.$htmlname.'" name="'.$htmlname.'" value="'.($editvalue?$editvalue:$preselected).'">';
}
else if ($typeofdata == 'text' || $typeofdata == 'textarea')
{
$ret.='<textarea id="'.$htmlname.'" name="'.$htmlname.'" wrap="soft" cols="70">'.($editvalue?$editvalue:$preselected).'</textarea>';
}
else if ($typeofdata == 'day')
{
$html=new Form($db);
$ret.=$html->form_date($_SERVER['PHP_SELF'].($paramkey?'?'.$paramkey.'='.$paramvalue:''),$preselected,$htmlname);
}
$ret.='</td>';
if ($typeofdata != 'day') $ret.='<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
$ret.='</tr></table>'."\n";
$ret.='</form>'."\n";
}
else
{
if ($typeofdata == 'email') $ret.=dol_print_email($preselected,0,0,0,0,1);
elseif ($typeofdata == 'day') $ret.=dol_print_date($preselected,'day');
elseif ($typeofdata == 'text' || $typeofdata == 'textarea') $ret.=dol_htmlentitiesbr($preselected);
else $ret.=$preselected;
}
return $ret;
}
/**
* Output edit in place form
*
* @param string $value Value to show/edit
* @param string $htmlname DIV ID (field name)
* @param int $condition Condition to edit
* @param string $inputType Type of input
* @param string $inputOption Input option
* @return string HTML edit in place
*/
function editInPlace($value, $htmlname, $condition, $inputType='textarea', $inputOption='')
{
global $conf;
$out='';
// Check parameters
if ($inputType == 'textarea') $value = dol_nl2br($value);
else if ($inputType == 'numeric') $value = price($value);
else if ($inputType == 'datepicker') $value = dol_print_date($value, 'day');
if (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE) && $condition)
{
if ($inputType == 'datepicker')
{
$out.= '<input id="timeStamp" type="hidden"/>'; // Use for timestamp format
}
else if ($inputType == 'select' && ! empty($inputOption))
{
$out.= '<input id="loadmethod" value="'.$inputOption.'" type="hidden"/>';
}
else if ($inputType == 'ckeditor' && ! empty($inputOption))
{
if (! empty($conf->fckeditor->enabled))
{
$out.= '<input id="toolbar" value="'.$inputOption.'" type="hidden"/>';
}
else
{
$inputType = 'textarea';
}
}
$out.= '<div class="edit_'.$inputType.'" id="'.$htmlname.'">';
$out.= $value;
$out.= '</div>';
}
else
{
$out = $value;
}
return $out;
}
/**
* Show a text and picto with tooltip on text or picto
*
* @param text Text to show
* @param htmltext Content html of tooltip. Must be HTML/UTF8 encoded.
* @param tooltipon 1=tooltip sur texte, 2=tooltip sur picto, 3=tooltip sur les 2
* @param direction -1=Le picto est avant, 0=pas de picto, 1=le picto est apres
* @param img Code img du picto (use img_xxx() function to get it)
* @param extracss Add a CSS style to td tags
* @param notabs Do not include table and tr tags
* @param incbefore Include code before the text
* @param noencodehtmltext Do not encode into html entity the htmltext
* @return string Code html du tooltip (texte+picto)
* @see Use function textwithpicto if you can.
*/
function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='',$extracss='',$notabs=0,$incbefore='',$noencodehtmltext=0)
{
global $conf;
if ($incbefore) $text = $incbefore.$text;
if (! $htmltext) return $text;
// Sanitize tooltip
$htmltext=str_replace("\\","\\\\",$htmltext);
$htmltext=str_replace("\r","",$htmltext);
$htmltext=str_replace("\n","",$htmltext);
$htmltext=str_replace('"',""",$htmltext);
if ($tooltipon == 2 || $tooltipon == 3) $paramfortooltipimg=' class="classfortooltip'.($extracss?' '.$extracss:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td img tag to store tooltip
else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag
if ($tooltipon == 1 || $tooltipon == 3) $paramfortooltiptd=' class="classfortooltip'.($extracss?' '.$extracss:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip
else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag
$s="";
if (empty($notabs)) $s.='<table class="nobordernopadding" summary=""><tr>';
if ($direction > 0)
{
if ($text != '')
{
$s.='<td'.$paramfortooltiptd.'>'.$text;
if ($direction) $s.=' ';
$s.='</td>';
}
if ($direction) $s.='<td'.$paramfortooltipimg.' valign="top" width="14">'.$img.'</td>';
}
else
{
if ($direction) $s.='<td'.$paramfortooltipimg.' valign="top" width="14">'.$img.'</td>';
if ($text != '')
{
$s.='<td'.$paramfortooltiptd.'>';
if ($direction) $s.=' ';
$s.=$text.'</td>';
}
}
if (empty($notabs)) $s.='</tr></table>';
return $s;
}
/**
* Show a text with a picto and a tooltip on picto
*
* @param text Text to show
* @param htmltooltip Content of tooltip
* @param direction 1=Icon is after text, -1=Icon is before text, 0=no icon
* @param type Type of picto (info, help, warning, superadmin...)
* @param extracss Add a CSS style to td tags
* @param noencodehtmltext Do not encode into html entity the htmltext
* @return string HTML code of text, picto, tooltip
*/
function textwithpicto($text,$htmltext,$direction=1,$type='help',$extracss='',$noencodehtmltext=0)
{
global $conf;
if ("$type" == "0") $type='info'; // For backward compatibility
$alt='';
// If info or help with no javascript, show only text
if (empty($conf->use_javascript_ajax))
{
if ($type == 'info' || $type == 'help') return $text;
else { $alt=$htmltext; $htmltext=''; }
}
// If info or help with smartphone, show only text
if (! empty($conf->browser->phone))
{
if ($type == 'info' || $type == 'help') return $text;
}
// Info or help
if ($type == 'info') $img=img_help(0,$alt);
if ($type == 'help' || $type ==1) $img=img_help(1,$alt);
if ($type == 'superadmin') $img=img_picto($alt,"redstar");
if ($type == 'admin') $img=img_picto($alt,"star");
// Warnings
if ($type == 'warning') $img=img_warning($alt);
return $this->textwithtooltip($text,$htmltext,2,$direction,$img,$extracss,0,'',$noencodehtmltext);
}
/**
* Return combo list of activated countries, into language of user
*
* @param selected Id or Code or Label of preselected country
* @param htmlname Name of html select object
* @param htmloption Options html on select object
*/
function select_pays($selected='',$htmlname='pays_id',$htmloption='')
{
print $this->select_country($selected,$htmlname,$htmloption);
}
/**
* Return combo list of activated countries, into language of user
*
* @param selected Id or Code or Label of preselected country
* @param htmlname Name of html select object
* @param htmloption Options html on select object
* @return string HTML string with select
*/
function select_country($selected='',$htmlname='pays_id',$htmloption='')
{
global $conf,$langs;
$langs->load("dict");
$out='';
$countryArray=array();
$label=array();
$sql = "SELECT rowid, code as code_iso, libelle as label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_pays";
$sql.= " WHERE active = 1";
$sql.= " ORDER BY code ASC";
dol_syslog("Form::select_country sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$out.= '<select id="select'.$htmlname.'" class="flat selectpays" name="'.$htmlname.'" '.$htmloption.'>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
$foundselected=false;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$countryArray[$i]['rowid'] = $obj->rowid;
$countryArray[$i]['code_iso'] = $obj->code_iso;
$countryArray[$i]['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country".$obj->code_iso)!="Country".$obj->code_iso?$langs->transnoentitiesnoconv("Country".$obj->code_iso):($obj->label!='-'?$obj->label:''));
$label[$i] = $countryArray[$i]['label'];
$i++;
}
array_multisort($label, SORT_ASC, $countryArray);
foreach ($countryArray as $row)
{
//print 'rr'.$selected.'-'.$row['label'].'-'.$row['code_iso'].'<br>';
if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['label']) )
{
$foundselected=true;
$out.= '<option value="'.$row['rowid'].'" selected="selected">';
}
else
{
$out.= '<option value="'.$row['rowid'].'">';
}
$out.= $row['label'];
if ($row['code_iso']) $out.= ' ('.$row['code_iso'] . ')';
$out.= '</option>';
}
}
$out.= '</select>';
}
else
{
dol_print_error($this->db);
}
return $out;
}
/**
* Retourne la liste des types de comptes financiers
*
* @param selected Type pre-selectionne
* @param htmlname Nom champ formulaire
*/
function select_type_comptes_financiers($selected=1,$htmlname='type')
{
global $langs;
$langs->load("banks");
$type_available=array(0,1,2);
print '<select class="flat" name="'.$htmlname.'">';
$num = count($type_available);
$i = 0;
if ($num)
{
while ($i < $num)
{
if ($selected == $type_available[$i])
{
print '<option value="'.$type_available[$i].'" selected="selected">'.$langs->trans("BankType".$type_available[$i]).'</option>';
}
else
{
print '<option value="'.$type_available[$i].'">'.$langs->trans("BankType".$type_available[$i]).'</option>';
}
$i++;
}
}
print '</select>';
}
/**
* Return list of social contributions.
* Use mysoc->pays_id or mysoc->pays_code so they must be defined.
*
* @param selected Preselected type
* @param htmlname Name of field in form
* @param useempty Set to 1 if we want an empty value
* @param maxlen Max length of text in combo box
* @param help Add or not the admin help picto
*/
function select_type_socialcontrib($selected='',$htmlname='actioncode', $useempty=0, $maxlen=40, $help=1)
{
global $db,$langs,$user,$mysoc;
if (empty($mysoc->pays_id) && empty($mysoc->pays_code))
{
dol_print_error('','Call to select_type_socialcontrib with mysoc country not yet defined');
exit;
}
if (! empty($mysoc->pays_id))
{
$sql = "SELECT c.id, c.libelle as type";
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c";
$sql.= " WHERE c.active = 1";
$sql.= " AND c.fk_pays = ".$mysoc->pays_id;
$sql.= " ORDER BY c.libelle ASC";
}
else
{
$sql = "SELECT c.id, c.libelle as type";
$sql.= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c, ".MAIN_DB_PREFIX."c_pays as p";
$sql.= " WHERE c.active = 1 AND c.fk_pays = p.rowid";
$sql.= " AND p.code = '".$mysoc->pays_code."'";
$sql.= " ORDER BY c.libelle ASC";
}
dol_syslog("Form::select_type_socialcontrib sql=".$sql, LOG_DEBUG);
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
if ($num)
{
print '<select class="flat" name="'.$htmlname.'">';
$i = 0;
if ($useempty) print '<option value="0"> </option>';
while ($i < $num)
{
$obj = $db->fetch_object($resql);
print '<option value="'.$obj->id.'"';
if ($obj->id == $selected) print ' selected="selected"';
print '>'.dol_trunc($obj->type,$maxlen);
$i++;
}
print '</select>';
if ($user->admin && $help) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
else
{
print $langs->trans("ErrorNoSocialContributionForSellerCountry",$mysoc->pays_code);
}
}
else
{
dol_print_error($db,$db->lasterror());
}
}
/**
* Return list of types of lines (product or service)
* Example: 0=product, 1=service, 9=other (for external module)
*
* @param selected Preselected type
* @param htmlname Name of field in html form
* @param showempty Add an empty field
* @param hidetext Do not show label before combo box
* @param forceall Force to show products and services in combo list, whatever are activated modules
*/
function select_type_of_lines($selected='',$htmlname='type',$showempty=0,$hidetext=0,$forceall=0)
{
global $db,$langs,$user,$conf;
// If product & services are enabled or both disabled.
if ($forceall || ($conf->product->enabled && $conf->service->enabled)
|| (empty($conf->product->enabled) && empty($conf->service->enabled)))
{
if (empty($hidetext)) print $langs->trans("Type").': ';
print '<select class="flat" name="'.$htmlname.'">';
if ($showempty)
{
print '<option value="-1"';
if ($selected == -1) print ' selected="selected"';
print '> </option>';
}
print '<option value="0"';
if (0 == $selected) print ' selected="selected"';
print '>'.$langs->trans("Product");
print '<option value="1"';
if (1 == $selected) print ' selected="selected"';
print '>'.$langs->trans("Service");
print '</select>';
//if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
if (! $forceall && empty($conf->product->enabled) && $conf->service->enabled)
{
print '<input type="hidden" name="'.$htmlname.'" value="1">';
}
if (! $forceall && $conf->product->enabled && empty($conf->service->enabled))
{
print '<input type="hidden" name="'.$htmlname.'" value="0">';
}
}
/**
* Load into cache cache_types_fees, array of types of fees
*
* @return int Nb of lines loaded, 0 if already loaded, <0 if ko
* TODO move in DAO class
*/
function load_cache_types_fees()
{
global $langs;
$langs->load("trips");
if (count($this->cache_types_fees)) return 0; // Cache already load
$sql = "SELECT c.code, c.libelle as label";
$sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c";
$sql.= " ORDER BY lower(c.libelle) ASC";
dol_syslog(get_class($this).'::load_cache_types_fees sql='.$sql, LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
$label=($obj->code != $langs->trans($obj->code) ? $langs->trans($obj->code) : $langs->trans($obj->label));
$this->cache_types_fees[$obj->code] = $label;
$i++;
}
return $num;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Return list of types of notes
*
* @param string $selected Preselected type
* @param string $htmlname Name of field in form
* @param int $showempty Add an empty field
* @return void
*/
function select_type_fees($selected='',$htmlname='type',$showempty=0)
{
global $user, $langs;
dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG);
$this->load_cache_types_fees();
print '<select class="flat" name="'.$htmlname.'">';
if ($showempty)
{
print '<option value="-1"';
if ($selected == -1) print ' selected="selected"';
print '> </option>';
}
foreach($this->cache_types_fees as $key => $value)
{
print '<option value="'.$key.'"';
if ($key == $selected) print ' selected="selected"';
print '>';
print $value;
print '</option>';
}
print '</select>';
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
}
/**
* Output html form to select a third party
*
* @param selected Preselected type
* @param htmlname Name of field in form
* @param filter Optionnal filters criteras
* @param showempty Add an empty field
* @param showtype Show third party type in combolist (customer, prospect or supplier)
* @param forcecombo Force to use combo box
*/
function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
{
print $this->select_company($selected,$htmlname,$filter,$showempty,$showtype,$forcecombo);
}
/**
* Output html form to select a third party
*
* @param selected Preselected type
* @param htmlname Name of field in form
* @param filter Optionnal filters criteras
* @param showempty Add an empty field
* @param showtype Show third party type in combolist (customer, prospect or supplier)
* @param forcecombo Force to use combo box
*/
function select_company($selected='',$htmlname='socid',$filter='',$showempty=0, $showtype=0, $forcecombo=0)
{
global $conf,$user,$langs;
$out='';
// On recherche les societes
$sql = "SELECT s.rowid, s.nom, s.client, s.fournisseur, s.code_client, s.code_fournisseur";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe as s";
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE s.entity = ".$conf->entity;
if ($filter) $sql.= " AND ".$filter;
if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
$sql.= " ORDER BY nom ASC";
dol_syslog("Form::select_societes sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && ! $forcecombo)
{
//$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
$out.= ajax_combobox($htmlname);
}
$out.= '<select id="'.$htmlname.'" class="flat" name="'.$htmlname.'">';
if ($showempty) $out.= '<option value="-1"> </option>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$label=$obj->nom;
if ($showtype)
{
if ($obj->client || $obj->fournisseur) $label.=' (';
if ($obj->client == 1 || $obj->client == 3) $label.=$langs->trans("Customer");
if ($obj->client == 2 || $obj->client == 3) $label.=($obj->client==3?', ':'').$langs->trans("Prospect");
if ($obj->fournisseur) $label.=($obj->client?', ':'').$langs->trans("Supplier");
if ($obj->client || $obj->fournisseur) $label.=')';
}
if ($selected > 0 && $selected == $obj->rowid)
{
$out.= '<option value="'.$obj->rowid.'" selected="selected">'.$label.'</option>';
}
else
{
$out.= '<option value="'.$obj->rowid.'">'.$label.'</option>';
}
$i++;
}
}
$out.= '</select>';
}
else
{
dol_print_error($this->db);
}
return $out;
}
/**
* Return HTML combo list of absolute discounts
*
* @param selected Id remise fixe pre-selectionnee
* @param htmlname Nom champ formulaire
* @param filter Criteres optionnels de filtre
* @param maxvalue Max value for lines that can be selected
* @return int Return number of qualifed lines in list
*/
function select_remises($selected='',$htmlname='remise_id',$filter='',$socid, $maxvalue=0)
{
global $langs,$conf;
// On recherche les remises
$sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
$sql.= " re.description, re.fk_facture_source";
$sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re";
$sql.= " WHERE fk_soc = ".$socid;
if ($filter) $sql.= " AND ".$filter;
$sql.= " ORDER BY re.description ASC";
dol_syslog("Form::select_remises sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
print '<select class="flat" name="'.$htmlname.'">';
$num = $this->db->num_rows($resql);
$qualifiedlines=$num;
$i = 0;
if ($num)
{
print '<option value="0"> </option>';
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$desc=dol_trunc($obj->description,40);
if ($desc=='(CREDIT_NOTE)') $desc=$langs->trans("CreditNote");
if ($desc=='(DEPOSIT)') $desc=$langs->trans("Deposit");
$selectstring='';
if ($selected > 0 && $selected == $obj->rowid) $selectstring=' selected="selected"';
$disabled='';
if ($maxvalue && $obj->amount_ttc > $maxvalue)
{
$qualifiedlines--;
$disabled=' disabled="disabled"';
}
print '<option value="'.$obj->rowid.'"'.$selectstring.$disabled.'>'.$desc.' ('.price($obj->amount_ht).' '.$langs->trans("HT").' - '.price($obj->amount_ttc).' '.$langs->trans("TTC").')</option>';
$i++;
}
}
print '</select>';
return $qualifiedlines;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Return list of all contacts (for a third party or all)
*
* @param socid Id ot third party or 0 for all
* @param selected Id contact pre-selectionne
* @param htmlname Name of HTML field ('none' for a not editable field)
* @param show_empty 0=no empty value, 1=add an empty value
* @param exclude List of contacts id to exclude
* @param limitto Disable answers that are not id in this array list
* @param showfunction Add function into label
* @param moreclass Add more class to class style
* @return int <0 if KO, Nb of contact in list if OK
*/
function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='')
{
global $conf,$langs;
// On recherche les societes
$sql = "SELECT s.rowid, s.name, s.firstname, s.poste FROM";
$sql.= " ".MAIN_DB_PREFIX ."socpeople as s";
$sql.= " WHERE entity = ".$conf->entity;
if ($socid > 0) $sql.= " AND fk_soc=".$socid;
$sql.= " ORDER BY s.name ASC";
dol_syslog("Form::select_contacts sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num=$this->db->num_rows($resql);
if ($num == 0) return 0;
if ($htmlname != 'none') print '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">';
if ($showempty) print '<option value="0"></option>';
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
include_once(DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php');
$contactstatic=new Contact($this->db);
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$contactstatic->id=$obj->rowid;
$contactstatic->name=$obj->name;
$contactstatic->firstname=$obj->firstname;
if ($htmlname != 'none')
{
$disabled=0;
if (is_array($exclude) && count($exclude) && in_array($obj->rowid,$exclude)) $disabled=1;
if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
if ($selected && $selected == $obj->rowid)
{
print '<option value="'.$obj->rowid.'"';
if ($disabled) print ' disabled="disabled"';
print ' selected="selected">';
print $contactstatic->getFullName($langs);
if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
print '</option>';
}
else
{
print '<option value="'.$obj->rowid.'"';
if ($disabled) print ' disabled="disabled"';
print '>';
print $contactstatic->getFullName($langs);
if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
print '</option>';
}
}
else
{
if ($selected == $obj->rowid)
{
print $contactstatic->getFullName($langs);
if ($showfunction && $obj->poste) print ' ('.$obj->poste.')';
}
}
$i++;
}
}
if ($htmlname != 'none')
{
print '</select>';
}
return $num;
}
else
{
dol_print_error($this->db);
return -1;
}
}
/**
* Return select list of users
*
* @param selected Id user preselected
* @param htmlname Field name in form
* @param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
* @param exclude Array list of users id to exclude
* @param disabled If select list must be disabled
* @param include Array list of users id to include
* @param enableonly Array list of users id to be enabled. All other must be disabled
* @param force_entity Possibility to force entity
*/
function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0)
{
print $this->select_dolusers($selected,$htmlname,$show_empty,$exclude,$disabled,$include,$enableonly,$force_entity);
}
/**
* Return select list of users
*
* @param selected User id or user object of user preselected. If -1, we use id of current user.
* @param htmlname Field name in form
* @param show_empty 0=liste sans valeur nulle, 1=ajoute valeur inconnue
* @param exclude Array list of users id to exclude
* @param disabled If select list must be disabled
* @param include Array list of users id to include
* @param enableonly Array list of users id to be enabled. All other must be disabled
* @param force_entity Possibility to force entity
*/
function select_dolusers($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0)
{
global $conf,$user,$langs;
// If no preselected user defined, we take current user
if ($selected < -1 && empty($conf->global->SOCIETE_DISABLE_DEFAULT_SALESREPRESENTATIVE)) $selected=$user->id;
// Permettre l'exclusion d'utilisateurs
if (is_array($exclude)) $excludeUsers = implode("','",$exclude);
// Permettre l'inclusion d'utilisateurs
if (is_array($include)) $includeUsers = implode("','",$include);
$out='';
// On recherche les utilisateurs
$sql = "SELECT u.rowid, u.name, u.firstname, u.login, u.admin, u.entity";
if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
$sql.= ", e.label";
}
$sql.= " FROM ".MAIN_DB_PREFIX ."user as u";
if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."entity as e on e.rowid=u.entity";
if ($force_entity) $sql.= " WHERE u.entity IN (0,".$force_entity.")";
else $sql.= " WHERE u.entity IS NOT NULL";
}
else
{
$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
}
if (is_array($exclude) && $excludeUsers) $sql.= " AND u.rowid NOT IN ('".$excludeUsers."')";
if (is_array($include) && $includeUsers) $sql.= " AND u.rowid IN ('".$includeUsers."')";
$sql.= " ORDER BY u.name ASC";
dol_syslog("Form::select_dolusers sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i = 0;
if ($num)
{
$out.= '<select class="flat" id="'.$htmlname.'" name="'.$htmlname.'"'.($disabled?' disabled="disabled"':'').'>';
if ($show_empty) $out.= '<option value="-1"'.($id==-1?' selected="selected"':'').'> </option>'."\n";
$userstatic=new User($this->db);
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$userstatic->id=$obj->rowid;
$userstatic->nom=$obj->name;
$userstatic->prenom=$obj->firstname;
$disableline=0;
if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1;
if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid))
{
$out.= '<option value="'.$obj->rowid.'"';
if ($disableline) $out.= ' disabled="disabled"';
$out.= ' selected="selected">';
}
else
{
$out.= '<option value="'.$obj->rowid.'"';
if ($disableline) $out.= ' disabled="disabled"';
$out.= '>';
}
$out.= $userstatic->getFullName($langs);
if(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
{
if ($obj->admin && ! $obj->entity) $out.=" (".$langs->trans("AllEntities").")";
else $out.=" (".$obj->label.")";
}
//if ($obj->admin) $out.= ' *';
if ($conf->global->MAIN_SHOW_LOGIN) $out.= ' ('.$obj->login.')';
$out.= '</option>';
$i++;
}
}
else
{
$out.= '<select class="flat" name="'.$htmlname.'" disabled="disabled">';
$out.= '<option value="">'.$langs->trans("None").'</option>';
}
$out.= '</select>';
}
else
{
dol_print_error($this->db);
}