@@ -103,7 +103,9 @@ discard block |
||
| 103 | 103 | $isgdinstalled=0; |
| 104 | 104 | foreach ($modules_list as $module) |
| 105 | 105 | { |
| 106 | - if ($module == 'gd') $isgdinstalled=1; |
|
| 106 | + if ($module == 'gd') { |
|
| 107 | + $isgdinstalled=1; |
|
| 108 | + } |
|
| 107 | 109 | } |
| 108 | 110 | if (! $isgdinstalled) |
| 109 | 111 | { |
@@ -120,9 +122,15 @@ discard block |
||
| 120 | 122 | if (is_readable($color_file)) |
| 121 | 123 | { |
| 122 | 124 | include_once $color_file; |
| 123 | - if (isset($theme_bordercolor)) $this->bordercolor = $theme_bordercolor; |
|
| 124 | - if (isset($theme_datacolor)) $this->datacolor = $theme_datacolor; |
|
| 125 | - if (isset($theme_bgcolor)) $this->bgcolor = $theme_bgcolor; |
|
| 125 | + if (isset($theme_bordercolor)) { |
|
| 126 | + $this->bordercolor = $theme_bordercolor; |
|
| 127 | + } |
|
| 128 | + if (isset($theme_datacolor)) { |
|
| 129 | + $this->datacolor = $theme_datacolor; |
|
| 130 | + } |
|
| 131 | + if (isset($theme_bgcolor)) { |
|
| 132 | + $this->bgcolor = $theme_bgcolor; |
|
| 133 | + } |
|
| 126 | 134 | } |
| 127 | 135 | //print 'bgcolor: '.join(',',$this->bgcolor).'<br>'; |
| 128 | 136 | } |
@@ -493,13 +501,11 @@ discard block |
||
| 493 | 501 | { |
| 494 | 502 | //print 'ee'.join(',',$theme_bgcoloronglet); |
| 495 | 503 | $this->bgcolor = $theme_bgcoloronglet; |
| 496 | - } |
|
| 497 | - else |
|
| 504 | + } else |
|
| 498 | 505 | { |
| 499 | 506 | $this->bgcolor = $theme_bgcolor; |
| 500 | 507 | } |
| 501 | - } |
|
| 502 | - else |
|
| 508 | + } else |
|
| 503 | 509 | { |
| 504 | 510 | $this->bgcolor = $bg_color; |
| 505 | 511 | } |
@@ -523,13 +529,11 @@ discard block |
||
| 523 | 529 | { |
| 524 | 530 | //print 'ee'.join(',',$theme_bgcoloronglet); |
| 525 | 531 | $this->bgcolorgrid = $theme_bgcoloronglet; |
| 526 | - } |
|
| 527 | - else |
|
| 532 | + } else |
|
| 528 | 533 | { |
| 529 | 534 | $this->bgcolorgrid = $theme_bgcolor; |
| 530 | 535 | } |
| 531 | - } |
|
| 532 | - else |
|
| 536 | + } else |
|
| 533 | 537 | { |
| 534 | 538 | $this->bgcolorgrid = $bg_colorgrid; |
| 535 | 539 | } |
@@ -611,7 +615,9 @@ discard block |
||
| 611 | 615 | { |
| 612 | 616 | // phpcs:enable |
| 613 | 617 | $max = $this->GetMaxValueInData(); |
| 614 | - if ($max != 0) $max++; |
|
| 618 | + if ($max != 0) { |
|
| 619 | + $max++; |
|
| 620 | + } |
|
| 615 | 621 | $size=dol_strlen(abs(ceil($max))); |
| 616 | 622 | $factor=1; |
| 617 | 623 | for ($i=0; $i < ($size-1); $i++) |
@@ -620,7 +626,9 @@ discard block |
||
| 620 | 626 | } |
| 621 | 627 | |
| 622 | 628 | $res=0; |
| 623 | - if (is_numeric($max)) $res=ceil($max/$factor)*$factor; |
|
| 629 | + if (is_numeric($max)) { |
|
| 630 | + $res=ceil($max/$factor)*$factor; |
|
| 631 | + } |
|
| 624 | 632 | |
| 625 | 633 | //print "max=".$max." res=".$res; |
| 626 | 634 | return $res; |
@@ -636,8 +644,12 @@ discard block |
||
| 636 | 644 | { |
| 637 | 645 | // phpcs:enable |
| 638 | 646 | $min = $this->GetMinValueInData(); |
| 639 | - if ($min == '') $min=0; |
|
| 640 | - if ($min != 0) $min--; |
|
| 647 | + if ($min == '') { |
|
| 648 | + $min=0; |
|
| 649 | + } |
|
| 650 | + if ($min != 0) { |
|
| 651 | + $min--; |
|
| 652 | + } |
|
| 641 | 653 | $size=dol_strlen(abs(floor($min))); |
| 642 | 654 | $factor=1; |
| 643 | 655 | for ($i=0; $i < ($size-1); $i++) |
@@ -697,15 +709,27 @@ discard block |
||
| 697 | 709 | |
| 698 | 710 | dol_syslog(get_class($this)."::draw_artichow this->type=".join(',',$this->type)); |
| 699 | 711 | |
| 700 | - if (! defined('SHADOW_RIGHT_TOP')) define('SHADOW_RIGHT_TOP',3); |
|
| 701 | - if (! defined('LEGEND_BACKGROUND')) define('LEGEND_BACKGROUND',2); |
|
| 702 | - if (! defined('LEGEND_LINE')) define('LEGEND_LINE',1); |
|
| 712 | + if (! defined('SHADOW_RIGHT_TOP')) { |
|
| 713 | + define('SHADOW_RIGHT_TOP',3); |
|
| 714 | + } |
|
| 715 | + if (! defined('LEGEND_BACKGROUND')) { |
|
| 716 | + define('LEGEND_BACKGROUND',2); |
|
| 717 | + } |
|
| 718 | + if (! defined('LEGEND_LINE')) { |
|
| 719 | + define('LEGEND_LINE',1); |
|
| 720 | + } |
|
| 703 | 721 | |
| 704 | 722 | // Create graph |
| 705 | 723 | $classname=''; |
| 706 | - if (! isset($this->type[0]) || $this->type[0] == 'bars') $classname='BarPlot'; // Only one type (first one) is supported by artichow |
|
| 707 | - else if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') $classname='LinePlot'; |
|
| 708 | - else $classname='TypeUnknown'; |
|
| 724 | + if (! isset($this->type[0]) || $this->type[0] == 'bars') { |
|
| 725 | + $classname='BarPlot'; |
|
| 726 | + } |
|
| 727 | + // Only one type (first one) is supported by artichow |
|
| 728 | + else if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') { |
|
| 729 | + $classname='LinePlot'; |
|
| 730 | + } else { |
|
| 731 | + $classname='TypeUnknown'; |
|
| 732 | + } |
|
| 709 | 733 | include_once ARTICHOW_PATH.$classname.'.class.php'; |
| 710 | 734 | |
| 711 | 735 | // Definition de couleurs |
@@ -727,8 +751,11 @@ discard block |
||
| 727 | 751 | $graph->title->setFont(new $artichow_defaultfont(10)); |
| 728 | 752 | } |
| 729 | 753 | |
| 730 | - if (is_array($this->bgcolor)) $graph->setBackgroundColor($bgcolor); |
|
| 731 | - else $graph->setBackgroundGradient($colorgradient); |
|
| 754 | + if (is_array($this->bgcolor)) { |
|
| 755 | + $graph->setBackgroundColor($bgcolor); |
|
| 756 | + } else { |
|
| 757 | + $graph->setBackgroundGradient($colorgradient); |
|
| 758 | + } |
|
| 732 | 759 | |
| 733 | 760 | $group = new PlotGroup; |
| 734 | 761 | //$group->setSpace(5, 5, 0, 0); |
@@ -736,18 +763,27 @@ discard block |
||
| 736 | 763 | $paddleft=50; |
| 737 | 764 | $paddright=10; |
| 738 | 765 | $strl=dol_strlen(max(abs($this->MaxValue),abs($this->MinValue))); |
| 739 | - if ($strl > 6) $paddleft += ($strl * 4); |
|
| 766 | + if ($strl > 6) { |
|
| 767 | + $paddleft += ($strl * 4); |
|
| 768 | + } |
|
| 740 | 769 | $group->setPadding($paddleft, $paddright); // Width on left and right for Y axis values |
| 741 | 770 | $group->legend->setSpace(0); |
| 742 | 771 | $group->legend->setPadding(2,2,2,2); |
| 743 | 772 | $group->legend->setPosition(null, 0.1); |
| 744 | 773 | $group->legend->setBackgroundColor($colorsemitrans); |
| 745 | 774 | |
| 746 | - if (is_array($this->bgcolorgrid)) $group->grid->setBackgroundColor($bgcolorgrid); |
|
| 747 | - else $group->grid->setBackgroundColor($colortrans); |
|
| 775 | + if (is_array($this->bgcolorgrid)) { |
|
| 776 | + $group->grid->setBackgroundColor($bgcolorgrid); |
|
| 777 | + } else { |
|
| 778 | + $group->grid->setBackgroundColor($colortrans); |
|
| 779 | + } |
|
| 748 | 780 | |
| 749 | - if ($this->hideXGrid) $group->grid->hideVertical(true); |
|
| 750 | - if ($this->hideYGrid) $group->grid->hideHorizontal(true); |
|
| 781 | + if ($this->hideXGrid) { |
|
| 782 | + $group->grid->hideVertical(true); |
|
| 783 | + } |
|
| 784 | + if ($this->hideYGrid) { |
|
| 785 | + $group->grid->hideHorizontal(true); |
|
| 786 | + } |
|
| 751 | 787 | |
| 752 | 788 | // On boucle sur chaque lot de donnees |
| 753 | 789 | $legends=array(); |
@@ -785,17 +821,29 @@ discard block |
||
| 785 | 821 | $colorgrey=new Color(100,100,100); |
| 786 | 822 | $colorborder=new Color($this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]); |
| 787 | 823 | |
| 788 | - if ($this->mode == 'side') $plot = new BarPlot($newvalues, $i+1, $nblot); |
|
| 789 | - if ($this->mode == 'depth') $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5); |
|
| 824 | + if ($this->mode == 'side') { |
|
| 825 | + $plot = new BarPlot($newvalues, $i+1, $nblot); |
|
| 826 | + } |
|
| 827 | + if ($this->mode == 'depth') { |
|
| 828 | + $plot = new BarPlot($newvalues, 1, 1, ($nblot-$i-1)*5); |
|
| 829 | + } |
|
| 790 | 830 | |
| 791 | 831 | $plot->barBorder->setColor($colorgrey); |
| 792 | 832 | //$plot->setBarColor($color); |
| 793 | 833 | $plot->setBarGradient(new LinearGradient($colorbis, $color, 90)); |
| 794 | 834 | |
| 795 | - if ($this->mode == 'side') $plot->setBarPadding(0.1, 0.1); |
|
| 796 | - if ($this->mode == 'depth') $plot->setBarPadding(0.1, 0.4); |
|
| 797 | - if ($this->mode == 'side') $plot->setBarSpace(5); |
|
| 798 | - if ($this->mode == 'depth') $plot->setBarSpace(2); |
|
| 835 | + if ($this->mode == 'side') { |
|
| 836 | + $plot->setBarPadding(0.1, 0.1); |
|
| 837 | + } |
|
| 838 | + if ($this->mode == 'depth') { |
|
| 839 | + $plot->setBarPadding(0.1, 0.4); |
|
| 840 | + } |
|
| 841 | + if ($this->mode == 'side') { |
|
| 842 | + $plot->setBarSpace(5); |
|
| 843 | + } |
|
| 844 | + if ($this->mode == 'depth') { |
|
| 845 | + $plot->setBarSpace(2); |
|
| 846 | + } |
|
| 799 | 847 | |
| 800 | 848 | $plot->barShadow->setSize($this->SetShading); |
| 801 | 849 | $plot->barShadow->setPosition(SHADOW_RIGHT_TOP); |
@@ -840,8 +888,12 @@ discard block |
||
| 840 | 888 | // solve a bug in Artichow with UTF8 |
| 841 | 889 | if (count($this->Legend)) |
| 842 | 890 | { |
| 843 | - if ($this->type[0] == 'bars') $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND); |
|
| 844 | - if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE); |
|
| 891 | + if ($this->type[0] == 'bars') { |
|
| 892 | + $group->legend->add($plot, $this->Legend[$i], LEGEND_BACKGROUND); |
|
| 893 | + } |
|
| 894 | + if ($this->type[0] == 'lines' || $this->type[0] == 'linesnopoint') { |
|
| 895 | + $group->legend->add($plot, $this->Legend[$i], LEGEND_LINE); |
|
| 896 | + } |
|
| 845 | 897 | } |
| 846 | 898 | $group->add($plot); |
| 847 | 899 | |
@@ -852,7 +904,9 @@ discard block |
||
| 852 | 904 | $group->axis->bottom->label->setFont(new $artichow_defaultfont(7)); |
| 853 | 905 | |
| 854 | 906 | //print $group->axis->bottom->getLabelNumber(); |
| 855 | - if ($this->labelInterval > 0) $group->axis->bottom->setLabelInterval($this->labelInterval); |
|
| 907 | + if ($this->labelInterval > 0) { |
|
| 908 | + $group->axis->bottom->setLabelInterval($this->labelInterval); |
|
| 909 | + } |
|
| 856 | 910 | |
| 857 | 911 | $graph->add($group); |
| 858 | 912 | |
@@ -895,23 +949,30 @@ discard block |
||
| 895 | 949 | |
| 896 | 950 | $legends=array(); |
| 897 | 951 | $nblot=count($this->data[0])-1; // -1 to remove legend |
| 898 | - if ($nblot < 0) dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING); |
|
| 952 | + if ($nblot < 0) { |
|
| 953 | + dol_syslog('Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw', LOG_WARNING); |
|
| 954 | + } |
|
| 899 | 955 | $firstlot=0; |
| 900 | 956 | // Works with line but not with bars |
| 901 | 957 | //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x |
| 902 | 958 | |
| 903 | 959 | $i=$firstlot; |
| 904 | 960 | $serie=array(); |
| 905 | - while ($i < $nblot) // Loop on each serie |
|
| 961 | + while ($i < $nblot) { |
|
| 962 | + // Loop on each serie |
|
| 906 | 963 | { |
| 907 | - $values=array(); // Array with horizontal y values (specific values of a serie) for each abscisse x |
|
| 964 | + $values=array(); |
|
| 965 | + } |
|
| 966 | + // Array with horizontal y values (specific values of a serie) for each abscisse x |
|
| 908 | 967 | $serie[$i]="var d".$i." = [];\n"; |
| 909 | 968 | |
| 910 | 969 | // Fill array $values |
| 911 | 970 | $x=0; |
| 912 | - foreach($this->data as $valarray) // Loop on each x |
|
| 971 | + foreach($this->data as $valarray) { |
|
| 972 | + // Loop on each x |
|
| 913 | 973 | { |
| 914 | 974 | $legends[$x] = $valarray[0]; |
| 975 | + } |
|
| 915 | 976 | $values[$x] = (is_numeric($valarray[$i+1]) ? $valarray[$i+1] : null); |
| 916 | 977 | $x++; |
| 917 | 978 | } |
@@ -920,13 +981,16 @@ discard block |
||
| 920 | 981 | if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') |
| 921 | 982 | { |
| 922 | 983 | foreach($values as $x => $y) { |
| 923 | - if (isset($y)) $serie[$i].='d'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; |
|
| 984 | + if (isset($y)) { |
|
| 985 | + $serie[$i].='d'.$i.'.push({"label":"'.dol_escape_js($legends[$x]).'", "data":'.$y.'});'."\n"; |
|
| 986 | + } |
|
| 924 | 987 | } |
| 925 | - } |
|
| 926 | - else |
|
| 988 | + } else |
|
| 927 | 989 | { |
| 928 | 990 | foreach($values as $x => $y) { |
| 929 | - if (isset($y)) $serie[$i].='d'.$i.'.push(['.$x.', '.$y.']);'."\n"; |
|
| 991 | + if (isset($y)) { |
|
| 992 | + $serie[$i].='d'.$i.'.push(['.$x.', '.$y.']);'."\n"; |
|
| 993 | + } |
|
| 930 | 994 | } |
| 931 | 995 | } |
| 932 | 996 | |
@@ -936,7 +1000,9 @@ discard block |
||
| 936 | 1000 | $tag=dol_escape_htmltag(dol_string_unaccent(dol_string_nospecial(basename($file),'_',array('-','.')))); |
| 937 | 1001 | |
| 938 | 1002 | $this->stringtoshow ='<!-- Build using '.$this->_library.' -->'."\n"; |
| 939 | - if (! empty($this->title)) $this->stringtoshow.='<div align="center" class="dolgraphtitle'.(empty($this->cssprefix)?'':' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; |
|
| 1003 | + if (! empty($this->title)) { |
|
| 1004 | + $this->stringtoshow.='<div align="center" class="dolgraphtitle'.(empty($this->cssprefix)?'':' dolgraphtitle'.$this->cssprefix).'">'.$this->title.'</div>'; |
|
| 1005 | + } |
|
| 940 | 1006 | if (! empty($this->shownographyet)) |
| 941 | 1007 | { |
| 942 | 1008 | $this->stringtoshow.='<div style="width:'.$this->width.'px;height:'.$this->height.'px;" class="nographyet"></div>'; |
@@ -951,8 +1017,7 @@ discard block |
||
| 951 | 1017 | if ($nblot < 0) |
| 952 | 1018 | { |
| 953 | 1019 | $this->stringtoshow.='<!-- No series of data -->'; |
| 954 | - } |
|
| 955 | - else |
|
| 1020 | + } else |
|
| 956 | 1021 | { |
| 957 | 1022 | while ($i < $nblot) |
| 958 | 1023 | { |
@@ -966,7 +1031,9 @@ discard block |
||
| 966 | 1031 | if (isset($this->type[$firstlot]) && $this->type[$firstlot] == 'pie') |
| 967 | 1032 | { |
| 968 | 1033 | $datacolor=array(); |
| 969 | - foreach($this->datacolor as $val) $datacolor[]="#".sprintf("%02x%02x%02x",$val[0],$val[1],$val[2]); |
|
| 1034 | + foreach($this->datacolor as $val) { |
|
| 1035 | + $datacolor[]="#".sprintf("%02x%02x%02x",$val[0],$val[1],$val[2]); |
|
| 1036 | + } |
|
| 970 | 1037 | |
| 971 | 1038 | $urltemp=''; // TODO Add support for url link into labels |
| 972 | 1039 | $showlegend=$this->showlegend; |
@@ -993,13 +1060,17 @@ discard block |
||
| 993 | 1060 | var number=series.data[0][1]; |
| 994 | 1061 | return \''; |
| 995 | 1062 | $this->stringtoshow.='<span style="font-size:8pt;text-align:center;padding:2px;color:black;">'; |
| 996 | - if ($urltemp) $this->stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">'; |
|
| 1063 | + if ($urltemp) { |
|
| 1064 | + $this->stringtoshow.='<a style="color: #FFFFFF;" border="0" href="'.$urltemp.'">'; |
|
| 1065 | + } |
|
| 997 | 1066 | $this->stringtoshow.='\'+'; |
| 998 | 1067 | $this->stringtoshow.=($showlegend?'':'label+\' \'+'); // Hide label if already shown in legend |
| 999 | 1068 | $this->stringtoshow.=($showpointvalue?'number+':''); |
| 1000 | 1069 | $this->stringtoshow.=($showpercent?'\'<br/>\'+percent+\'%\'+':''); |
| 1001 | 1070 | $this->stringtoshow.='\''; |
| 1002 | - if ($urltemp) $this->stringtoshow.='</a>'; |
|
| 1071 | + if ($urltemp) { |
|
| 1072 | + $this->stringtoshow.='</a>'; |
|
| 1073 | + } |
|
| 1003 | 1074 | $this->stringtoshow.='</span>\'; |
| 1004 | 1075 | }, |
| 1005 | 1076 | background: { |
@@ -1060,9 +1131,11 @@ discard block |
||
| 1060 | 1131 | var y = item.datapoint[1].toFixed(2); |
| 1061 | 1132 | var z = item.series.xaxis.ticks[item.dataIndex].label; |
| 1062 | 1133 | '; |
| 1063 | - if ($this->showpointvalue > 0) $this->stringtoshow.=' |
|
| 1134 | + if ($this->showpointvalue > 0) { |
|
| 1135 | + $this->stringtoshow.=' |
|
| 1064 | 1136 | showTooltip_'.$tag.'(item.pageX, item.pageY, item.series.label + "<br>" + z + " => " + y); |
| 1065 | 1137 | '; |
| 1138 | + } |
|
| 1066 | 1139 | $this->stringtoshow.=' |
| 1067 | 1140 | } |
| 1068 | 1141 | } |
@@ -1080,11 +1153,17 @@ discard block |
||
| 1080 | 1153 | $i=$firstlot; |
| 1081 | 1154 | while ($i < $nblot) |
| 1082 | 1155 | { |
| 1083 | - if ($i > $firstlot) $this->stringtoshow.=', '."\n"; |
|
| 1156 | + if ($i > $firstlot) { |
|
| 1157 | + $this->stringtoshow.=', '."\n"; |
|
| 1158 | + } |
|
| 1084 | 1159 | $color=sprintf("%02x%02x%02x",$this->datacolor[$i][0],$this->datacolor[$i][1],$this->datacolor[$i][2]); |
| 1085 | 1160 | $this->stringtoshow.='{ '; |
| 1086 | - if (! isset($this->type[$i]) || $this->type[$i] == 'bars') $this->stringtoshow.='bars: { lineWidth: 1, show: true, align: "'.($i==$firstlot?'center':'left').'", barWidth: 0.5 }, '; |
|
| 1087 | - if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) $this->stringtoshow.='lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, '; |
|
| 1161 | + if (! isset($this->type[$i]) || $this->type[$i] == 'bars') { |
|
| 1162 | + $this->stringtoshow.='bars: { lineWidth: 1, show: true, align: "'.($i==$firstlot?'center':'left').'", barWidth: 0.5 }, '; |
|
| 1163 | + } |
|
| 1164 | + if (isset($this->type[$i]) && ($this->type[$i] == 'lines' || $this->type[$i] == 'linesnopoint')) { |
|
| 1165 | + $this->stringtoshow.='lines: { show: true, fill: false }, points: { show: '.($this->type[$i] == 'linesnopoint' ? 'false' : 'true').' }, '; |
|
| 1166 | + } |
|
| 1088 | 1167 | $this->stringtoshow.='color: "#'.$color.'", label: "'.(isset($this->Legend[$i]) ? dol_escape_js($this->Legend[$i]) : '').'", data: d'.$i.' }'; |
| 1089 | 1168 | $i++; |
| 1090 | 1169 | } |
@@ -1096,7 +1175,9 @@ discard block |
||
| 1096 | 1175 | $x=0; |
| 1097 | 1176 | foreach($this->data as $key => $valarray) |
| 1098 | 1177 | { |
| 1099 | - if ($x > 0) $this->stringtoshow.=', '."\n"; |
|
| 1178 | + if ($x > 0) { |
|
| 1179 | + $this->stringtoshow.=', '."\n"; |
|
| 1180 | + } |
|
| 1100 | 1181 | $this->stringtoshow.= ' ['.$x.', "'.$valarray[0].'"]'; |
| 1101 | 1182 | $x++; |
| 1102 | 1183 | } |
@@ -1155,8 +1236,11 @@ discard block |
||
| 1155 | 1236 | |
| 1156 | 1237 | if ($direction == 'width') |
| 1157 | 1238 | { |
| 1158 | - if (empty($conf->dol_optimize_smallscreen)) return ($defaultsize ? $defaultsize : '500'); |
|
| 1159 | - else return (empty($_SESSION['dol_screen_width']) ? '280' : ($_SESSION['dol_screen_width']-40)); |
|
| 1239 | + if (empty($conf->dol_optimize_smallscreen)) { |
|
| 1240 | + return ($defaultsize ? $defaultsize : '500'); |
|
| 1241 | + } else { |
|
| 1242 | + return (empty($_SESSION['dol_screen_width']) ? '280' : ($_SESSION['dol_screen_width']-40)); |
|
| 1243 | + } |
|
| 1160 | 1244 | } |
| 1161 | 1245 | if ($direction == 'height') |
| 1162 | 1246 | { |
@@ -173,11 +173,19 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0, $default_value='', $param='', $alwayseditable=0, $perms='', $list='-1', $help='', $computed='', $entity='', $langfile='', $enabled='1') |
| 175 | 175 | { |
| 176 | - if (empty($attrname)) return -1; |
|
| 177 | - if (empty($label)) return -1; |
|
| 176 | + if (empty($attrname)) { |
|
| 177 | + return -1; |
|
| 178 | + } |
|
| 179 | + if (empty($label)) { |
|
| 180 | + return -1; |
|
| 181 | + } |
|
| 178 | 182 | |
| 179 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 180 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 183 | + if ($elementtype == 'thirdparty') { |
|
| 184 | + $elementtype='societe'; |
|
| 185 | + } |
|
| 186 | + if ($elementtype == 'contact') { |
|
| 187 | + $elementtype='socpeople'; |
|
| 188 | + } |
|
| 181 | 189 | |
| 182 | 190 | // Create field into database except for separator type which is not stored in database |
| 183 | 191 | if ($type != 'separate') |
@@ -195,10 +203,10 @@ discard block |
||
| 195 | 203 | $this->error=''; |
| 196 | 204 | $this->errno=0; |
| 197 | 205 | return 1; |
| 206 | + } else { |
|
| 207 | + return -2; |
|
| 198 | 208 | } |
| 199 | - else return -2; |
|
| 200 | - } |
|
| 201 | - else |
|
| 209 | + } else |
|
| 202 | 210 | { |
| 203 | 211 | return -1; |
| 204 | 212 | } |
@@ -223,11 +231,17 @@ discard block |
||
| 223 | 231 | */ |
| 224 | 232 | private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list='0', $computed='') |
| 225 | 233 | { |
| 226 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 227 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 234 | + if ($elementtype == 'thirdparty') { |
|
| 235 | + $elementtype='societe'; |
|
| 236 | + } |
|
| 237 | + if ($elementtype == 'contact') { |
|
| 238 | + $elementtype='socpeople'; |
|
| 239 | + } |
|
| 228 | 240 | |
| 229 | 241 | $table=$elementtype.'_extrafields'; |
| 230 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
| 242 | + if ($elementtype == 'categorie') { |
|
| 243 | + $table='categories_extrafields'; |
|
| 244 | + } |
|
| 231 | 245 | |
| 232 | 246 | if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9_]*$/",$attrname) && ! is_numeric($attrname)) |
| 233 | 247 | { |
@@ -261,7 +275,9 @@ discard block |
||
| 261 | 275 | } else { |
| 262 | 276 | $typedb=$type; |
| 263 | 277 | $lengthdb=$length; |
| 264 | - if ($type == 'varchar' && empty($lengthdb)) $lengthdb='255'; |
|
| 278 | + if ($type == 'varchar' && empty($lengthdb)) { |
|
| 279 | + $lengthdb='255'; |
|
| 280 | + } |
|
| 265 | 281 | } |
| 266 | 282 | $field_desc = array( |
| 267 | 283 | 'type'=>$typedb, |
@@ -279,15 +295,13 @@ discard block |
||
| 279 | 295 | $resql=$this->db->query($sql,1,'dml'); |
| 280 | 296 | } |
| 281 | 297 | return 1; |
| 282 | - } |
|
| 283 | - else |
|
| 298 | + } else |
|
| 284 | 299 | { |
| 285 | 300 | $this->error=$this->db->lasterror(); |
| 286 | 301 | $this->errno=$this->db->lasterrno(); |
| 287 | 302 | return -1; |
| 288 | 303 | } |
| 289 | - } |
|
| 290 | - else |
|
| 304 | + } else |
|
| 291 | 305 | { |
| 292 | 306 | return 0; |
| 293 | 307 | } |
@@ -322,27 +336,39 @@ discard block |
||
| 322 | 336 | // phpcs:enable |
| 323 | 337 | global $conf,$user; |
| 324 | 338 | |
| 325 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 326 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 339 | + if ($elementtype == 'thirdparty') { |
|
| 340 | + $elementtype='societe'; |
|
| 341 | + } |
|
| 342 | + if ($elementtype == 'contact') { |
|
| 343 | + $elementtype='socpeople'; |
|
| 344 | + } |
|
| 327 | 345 | |
| 328 | 346 | // Clean parameters |
| 329 | - if (empty($pos)) $pos=0; |
|
| 330 | - if (empty($list)) $list='0'; |
|
| 331 | - if (empty($required)) $required=0; |
|
| 332 | - if (empty($unique)) $unique=0; |
|
| 333 | - if (empty($alwayseditable)) $alwayseditable=0; |
|
| 347 | + if (empty($pos)) { |
|
| 348 | + $pos=0; |
|
| 349 | + } |
|
| 350 | + if (empty($list)) { |
|
| 351 | + $list='0'; |
|
| 352 | + } |
|
| 353 | + if (empty($required)) { |
|
| 354 | + $required=0; |
|
| 355 | + } |
|
| 356 | + if (empty($unique)) { |
|
| 357 | + $unique=0; |
|
| 358 | + } |
|
| 359 | + if (empty($alwayseditable)) { |
|
| 360 | + $alwayseditable=0; |
|
| 361 | + } |
|
| 334 | 362 | |
| 335 | 363 | if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname) && ! is_numeric($attrname)) |
| 336 | 364 | { |
| 337 | 365 | if (is_array($param) && count($param) > 0) |
| 338 | 366 | { |
| 339 | 367 | $params = serialize($param); |
| 340 | - } |
|
| 341 | - elseif (strlen($param) > 0) |
|
| 368 | + } elseif (strlen($param) > 0) |
|
| 342 | 369 | { |
| 343 | 370 | $params = trim($param); |
| 344 | - } |
|
| 345 | - else |
|
| 371 | + } else |
|
| 346 | 372 | { |
| 347 | 373 | $params=''; |
| 348 | 374 | } |
@@ -397,8 +423,7 @@ discard block |
||
| 397 | 423 | if ($this->db->query($sql)) |
| 398 | 424 | { |
| 399 | 425 | return 1; |
| 400 | - } |
|
| 401 | - else |
|
| 426 | + } else |
|
| 402 | 427 | { |
| 403 | 428 | $this->error=$this->db->lasterror(); |
| 404 | 429 | $this->errno=$this->db->lasterrno(); |
@@ -416,11 +441,17 @@ discard block |
||
| 416 | 441 | */ |
| 417 | 442 | function delete($attrname, $elementtype='member') |
| 418 | 443 | { |
| 419 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 420 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 444 | + if ($elementtype == 'thirdparty') { |
|
| 445 | + $elementtype='societe'; |
|
| 446 | + } |
|
| 447 | + if ($elementtype == 'contact') { |
|
| 448 | + $elementtype='socpeople'; |
|
| 449 | + } |
|
| 421 | 450 | |
| 422 | 451 | $table=$elementtype.'_extrafields'; |
| 423 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
| 452 | + if ($elementtype == 'categorie') { |
|
| 453 | + $table='categories_extrafields'; |
|
| 454 | + } |
|
| 424 | 455 | |
| 425 | 456 | $error=0; |
| 426 | 457 | |
@@ -457,8 +488,7 @@ discard block |
||
| 457 | 488 | } |
| 458 | 489 | |
| 459 | 490 | return $result; |
| 460 | - } |
|
| 461 | - else |
|
| 491 | + } else |
|
| 462 | 492 | { |
| 463 | 493 | return 0; |
| 464 | 494 | } |
@@ -477,8 +507,12 @@ discard block |
||
| 477 | 507 | // phpcs:enable |
| 478 | 508 | global $conf; |
| 479 | 509 | |
| 480 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 481 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 510 | + if ($elementtype == 'thirdparty') { |
|
| 511 | + $elementtype='societe'; |
|
| 512 | + } |
|
| 513 | + if ($elementtype == 'contact') { |
|
| 514 | + $elementtype='socpeople'; |
|
| 515 | + } |
|
| 482 | 516 | |
| 483 | 517 | if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
| 484 | 518 | { |
@@ -492,14 +526,12 @@ discard block |
||
| 492 | 526 | if ($resql) |
| 493 | 527 | { |
| 494 | 528 | return 1; |
| 495 | - } |
|
| 496 | - else |
|
| 529 | + } else |
|
| 497 | 530 | { |
| 498 | 531 | print dol_print_error($this->db); |
| 499 | 532 | return -1; |
| 500 | 533 | } |
| 501 | - } |
|
| 502 | - else |
|
| 534 | + } else |
|
| 503 | 535 | { |
| 504 | 536 | return 0; |
| 505 | 537 | } |
@@ -531,11 +563,17 @@ discard block |
||
| 531 | 563 | */ |
| 532 | 564 | function update($attrname, $label, $type, $length, $elementtype, $unique=0, $required=0, $pos=0, $param='', $alwayseditable=0, $perms='', $list='', $help='', $default='', $computed='', $entity='', $langfile='', $enabled='1', $totalizable=0) |
| 533 | 565 | { |
| 534 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 535 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 566 | + if ($elementtype == 'thirdparty') { |
|
| 567 | + $elementtype='societe'; |
|
| 568 | + } |
|
| 569 | + if ($elementtype == 'contact') { |
|
| 570 | + $elementtype='socpeople'; |
|
| 571 | + } |
|
| 536 | 572 | |
| 537 | 573 | $table=$elementtype.'_extrafields'; |
| 538 | - if ($elementtype == 'categorie') $table='categories_extrafields'; |
|
| 574 | + if ($elementtype == 'categorie') { |
|
| 575 | + $table='categories_extrafields'; |
|
| 576 | + } |
|
| 539 | 577 | |
| 540 | 578 | if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
| 541 | 579 | { |
@@ -571,10 +609,12 @@ discard block |
||
| 571 | 609 | } |
| 572 | 610 | $field_desc = array('type'=>$typedb, 'value'=>$lengthdb, 'null'=>($required?'NOT NULL':'NULL'), 'default'=>$default); |
| 573 | 611 | |
| 574 | - if ($type != 'separate') // No table update when separate type |
|
| 612 | + if ($type != 'separate') { |
|
| 613 | + // No table update when separate type |
|
| 575 | 614 | { |
| 576 | 615 | $result=$this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); |
| 577 | 616 | } |
| 617 | + } |
|
| 578 | 618 | if ($result > 0 || $type == 'separate') |
| 579 | 619 | { |
| 580 | 620 | if ($label) |
@@ -587,28 +627,24 @@ discard block |
||
| 587 | 627 | if ($unique) |
| 588 | 628 | { |
| 589 | 629 | $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; |
| 590 | - } |
|
| 591 | - else |
|
| 630 | + } else |
|
| 592 | 631 | { |
| 593 | 632 | $sql="ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; |
| 594 | 633 | } |
| 595 | 634 | dol_syslog(get_class($this).'::update', LOG_DEBUG); |
| 596 | 635 | $resql=$this->db->query($sql,1,'dml'); |
| 597 | 636 | return 1; |
| 598 | - } |
|
| 599 | - else |
|
| 637 | + } else |
|
| 600 | 638 | { |
| 601 | 639 | $this->error=$this->db->lasterror(); |
| 602 | 640 | return -1; |
| 603 | 641 | } |
| 604 | - } |
|
| 605 | - else |
|
| 642 | + } else |
|
| 606 | 643 | { |
| 607 | 644 | $this->error=$this->db->lasterror(); |
| 608 | 645 | return -1; |
| 609 | 646 | } |
| 610 | - } |
|
| 611 | - else |
|
| 647 | + } else |
|
| 612 | 648 | { |
| 613 | 649 | return 0; |
| 614 | 650 | } |
@@ -646,17 +682,31 @@ discard block |
||
| 646 | 682 | dol_syslog(get_class($this)."::update_label ".$attrname.", ".$label.", ".$type.", ".$size.", ".$elementtype.", ".$unique.", ".$required.", ".$pos.", ".$alwayseditable.", ".$perms.", ".$list.", ".$default.", ".$computed.", ".$entity.", ".$langfile.", ".$enabled.", ".$totalizable); |
| 647 | 683 | |
| 648 | 684 | // Clean parameters |
| 649 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 650 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 685 | + if ($elementtype == 'thirdparty') { |
|
| 686 | + $elementtype='societe'; |
|
| 687 | + } |
|
| 688 | + if ($elementtype == 'contact') { |
|
| 689 | + $elementtype='socpeople'; |
|
| 690 | + } |
|
| 651 | 691 | |
| 652 | - if (empty($pos)) $pos=0; |
|
| 653 | - if (empty($list)) $list='0'; |
|
| 692 | + if (empty($pos)) { |
|
| 693 | + $pos=0; |
|
| 694 | + } |
|
| 695 | + if (empty($list)) { |
|
| 696 | + $list='0'; |
|
| 697 | + } |
|
| 654 | 698 | if (empty($totalizable)) { |
| 655 | 699 | $totalizable = 0; |
| 656 | 700 | } |
| 657 | - if (empty($required)) $required=0; |
|
| 658 | - if (empty($unique)) $unique=0; |
|
| 659 | - if (empty($alwayseditable)) $alwayseditable=0; |
|
| 701 | + if (empty($required)) { |
|
| 702 | + $required=0; |
|
| 703 | + } |
|
| 704 | + if (empty($unique)) { |
|
| 705 | + $unique=0; |
|
| 706 | + } |
|
| 707 | + if (empty($alwayseditable)) { |
|
| 708 | + $alwayseditable=0; |
|
| 709 | + } |
|
| 660 | 710 | |
| 661 | 711 | if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) |
| 662 | 712 | { |
@@ -665,12 +715,10 @@ discard block |
||
| 665 | 715 | if (is_array($param) && count($param) > 0) |
| 666 | 716 | { |
| 667 | 717 | $params = serialize($param); |
| 668 | - } |
|
| 669 | - elseif (strlen($param) > 0) |
|
| 718 | + } elseif (strlen($param) > 0) |
|
| 670 | 719 | { |
| 671 | 720 | $params = trim($param); |
| 672 | - } |
|
| 673 | - else |
|
| 721 | + } else |
|
| 674 | 722 | { |
| 675 | 723 | $params=''; |
| 676 | 724 | } |
@@ -682,8 +730,7 @@ discard block |
||
| 682 | 730 | $sql_del.= " WHERE name = '".$attrname."'"; |
| 683 | 731 | $sql_del.= " AND entity IN (0, ".($entity===''?$conf->entity:$entity).")"; |
| 684 | 732 | $sql_del.= " AND elementtype = '".$elementtype."'"; |
| 685 | - } |
|
| 686 | - else |
|
| 733 | + } else |
|
| 687 | 734 | { |
| 688 | 735 | // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity) |
| 689 | 736 | $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; |
@@ -747,15 +794,13 @@ discard block |
||
| 747 | 794 | { |
| 748 | 795 | $this->db->commit(); |
| 749 | 796 | return 1; |
| 750 | - } |
|
| 751 | - else |
|
| 797 | + } else |
|
| 752 | 798 | { |
| 753 | 799 | $this->db->rollback(); |
| 754 | 800 | print dol_print_error($this->db); |
| 755 | 801 | return -1; |
| 756 | 802 | } |
| 757 | - } |
|
| 758 | - else |
|
| 803 | + } else |
|
| 759 | 804 | { |
| 760 | 805 | return 0; |
| 761 | 806 | } |
@@ -775,16 +820,26 @@ discard block |
||
| 775 | 820 | // phpcs:enable |
| 776 | 821 | global $conf; |
| 777 | 822 | |
| 778 | - if (empty($elementtype)) return array(); |
|
| 823 | + if (empty($elementtype)) { |
|
| 824 | + return array(); |
|
| 825 | + } |
|
| 779 | 826 | |
| 780 | - if ($elementtype == 'thirdparty') $elementtype='societe'; |
|
| 781 | - if ($elementtype == 'contact') $elementtype='socpeople'; |
|
| 782 | - if ($elementtype == 'order_supplier') $elementtype='commande_fournisseur'; |
|
| 827 | + if ($elementtype == 'thirdparty') { |
|
| 828 | + $elementtype='societe'; |
|
| 829 | + } |
|
| 830 | + if ($elementtype == 'contact') { |
|
| 831 | + $elementtype='socpeople'; |
|
| 832 | + } |
|
| 833 | + if ($elementtype == 'order_supplier') { |
|
| 834 | + $elementtype='commande_fournisseur'; |
|
| 835 | + } |
|
| 783 | 836 | |
| 784 | 837 | $array_name_label=array(); |
| 785 | 838 | |
| 786 | 839 | // To avoid conflicts with external modules. TODO Remove this. |
| 787 | - if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; |
|
| 840 | + if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { |
|
| 841 | + return $array_name_label; |
|
| 842 | + } |
|
| 788 | 843 | |
| 789 | 844 | // Set array of label of entity |
| 790 | 845 | // TODO Remove completely loading of label. This should be done by presentation. |
@@ -808,7 +863,10 @@ discard block |
||
| 808 | 863 | $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,langs,list,totalizable,fielddefault,fieldcomputed,entity,enabled,help"; |
| 809 | 864 | $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; |
| 810 | 865 | $sql.= " WHERE entity IN (0,".$conf->entity.")"; |
| 811 | - if ($elementtype) $sql.= " AND elementtype = '".$elementtype."'"; // Filed with object->table_element |
|
| 866 | + if ($elementtype) { |
|
| 867 | + $sql.= " AND elementtype = '".$elementtype."'"; |
|
| 868 | + } |
|
| 869 | + // Filed with object->table_element |
|
| 812 | 870 | $sql.= " ORDER BY pos"; |
| 813 | 871 | |
| 814 | 872 | $resql=$this->db->query($sql); |
@@ -867,9 +925,11 @@ discard block |
||
| 867 | 925 | $this->attributes[$tab->elementtype]['loaded']=1; |
| 868 | 926 | } |
| 869 | 927 | } |
| 870 | - if ($elementtype) $this->attributes[$elementtype]['loaded']=1; // If nothing found, we also save tag 'loaded' |
|
| 871 | - } |
|
| 872 | - else |
|
| 928 | + if ($elementtype) { |
|
| 929 | + $this->attributes[$elementtype]['loaded']=1; |
|
| 930 | + } |
|
| 931 | + // If nothing found, we also save tag 'loaded' |
|
| 932 | + } else |
|
| 873 | 933 | { |
| 874 | 934 | $this->error=$this->db->lasterror(); |
| 875 | 935 | dol_syslog(get_class($this)."::fetch_name_optionals_label ".$this->error, LOG_ERR); |
@@ -923,8 +983,7 @@ discard block |
||
| 923 | 983 | $totalizable=$this->attributes[$extrafieldsobjectkey]['totalizable'][$key]; |
| 924 | 984 | $help=$this->attributes[$extrafieldsobjectkey]['help'][$key]; |
| 925 | 985 | $hidden=(empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
| 926 | - } |
|
| 927 | - else // Old usage |
|
| 986 | + } else // Old usage |
|
| 928 | 987 | { |
| 929 | 988 | $label=$this->attribute_label[$key]; |
| 930 | 989 | $type =$this->attribute_type[$key]; |
@@ -943,8 +1002,11 @@ discard block |
||
| 943 | 1002 | |
| 944 | 1003 | if ($computed) |
| 945 | 1004 | { |
| 946 | - if (! preg_match('/^search_/', $keyprefix)) return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 947 | - else return ''; |
|
| 1005 | + if (! preg_match('/^search_/', $keyprefix)) { |
|
| 1006 | + return '<span class="opacitymedium">'.$langs->trans("AutomaticallyCalculated").'</span>'; |
|
| 1007 | + } else { |
|
| 1008 | + return ''; |
|
| 1009 | + } |
|
| 948 | 1010 | } |
| 949 | 1011 | |
| 950 | 1012 | if (empty($morecss)) |
@@ -952,38 +1014,30 @@ discard block |
||
| 952 | 1014 | if ($type == 'date') |
| 953 | 1015 | { |
| 954 | 1016 | $morecss = 'minwidth100imp'; |
| 955 | - } |
|
| 956 | - elseif ($type == 'datetime') |
|
| 1017 | + } elseif ($type == 'datetime') |
|
| 957 | 1018 | { |
| 958 | 1019 | $morecss = 'minwidth200imp'; |
| 959 | - } |
|
| 960 | - elseif (in_array($type,array('int','integer','double','price'))) |
|
| 1020 | + } elseif (in_array($type,array('int','integer','double','price'))) |
|
| 961 | 1021 | { |
| 962 | 1022 | $morecss = 'maxwidth75'; |
| 963 | - } |
|
| 964 | - elseif ($type == 'password') |
|
| 1023 | + } elseif ($type == 'password') |
|
| 965 | 1024 | { |
| 966 | 1025 | $morecss='maxwidth100'; |
| 967 | - } |
|
| 968 | - elseif ($type == 'url') |
|
| 1026 | + } elseif ($type == 'url') |
|
| 969 | 1027 | { |
| 970 | 1028 | $morecss='minwidth400'; |
| 971 | - } |
|
| 972 | - elseif ($type == 'boolean') |
|
| 1029 | + } elseif ($type == 'boolean') |
|
| 973 | 1030 | { |
| 974 | 1031 | $morecss=''; |
| 975 | - } |
|
| 976 | - else |
|
| 1032 | + } else |
|
| 977 | 1033 | { |
| 978 | 1034 | if (round($size) < 12) |
| 979 | 1035 | { |
| 980 | 1036 | $morecss = 'minwidth100'; |
| 981 | - } |
|
| 982 | - else if (round($size) <= 48) |
|
| 1037 | + } else if (round($size) <= 48) |
|
| 983 | 1038 | { |
| 984 | 1039 | $morecss = 'minwidth200'; |
| 985 | - } |
|
| 986 | - else |
|
| 1040 | + } else |
|
| 987 | 1041 | { |
| 988 | 1042 | $morecss = 'minwidth400'; |
| 989 | 1043 | } |
@@ -998,52 +1052,50 @@ discard block |
||
| 998 | 1052 | $showtime = in_array($type,array('datetime')) ? 1 : 0; |
| 999 | 1053 | |
| 1000 | 1054 | // Do not show current date when field not required (see selectDate() method) |
| 1001 | - if (!$required && $value == '') $value = '-1'; |
|
| 1055 | + if (!$required && $value == '') { |
|
| 1056 | + $value = '-1'; |
|
| 1057 | + } |
|
| 1002 | 1058 | |
| 1003 | 1059 | // TODO Must also support $moreparam |
| 1004 | 1060 | $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); |
| 1005 | - } |
|
| 1006 | - elseif (in_array($type,array('int','integer'))) |
|
| 1061 | + } elseif (in_array($type,array('int','integer'))) |
|
| 1007 | 1062 | { |
| 1008 | 1063 | $tmp=explode(',',$size); |
| 1009 | 1064 | $newsize=$tmp[0]; |
| 1010 | 1065 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$newsize.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
| 1011 | - } |
|
| 1012 | - elseif (preg_match('/varchar/', $type)) |
|
| 1066 | + } elseif (preg_match('/varchar/', $type)) |
|
| 1013 | 1067 | { |
| 1014 | 1068 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" maxlength="'.$size.'" value="'.dol_escape_htmltag($value).'"'.($moreparam?$moreparam:'').'>'; |
| 1015 | - } |
|
| 1016 | - elseif (in_array($type, array('mail', 'phone', 'url'))) |
|
| 1069 | + } elseif (in_array($type, array('mail', 'phone', 'url'))) |
|
| 1017 | 1070 | { |
| 1018 | 1071 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 1019 | - } |
|
| 1020 | - elseif ($type == 'text') |
|
| 1072 | + } elseif ($type == 'text') |
|
| 1021 | 1073 | { |
| 1022 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1074 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 1075 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1023 | 1076 | { |
| 1024 | 1077 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 1078 | + } |
|
| 1025 | 1079 | $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,false,ROWS_5,'90%'); |
| 1026 | 1080 | $out=$doleditor->Create(1); |
| 1027 | - } |
|
| 1028 | - else |
|
| 1081 | + } else |
|
| 1029 | 1082 | { |
| 1030 | 1083 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 1031 | 1084 | } |
| 1032 | - } |
|
| 1033 | - elseif ($type == 'html') |
|
| 1085 | + } elseif ($type == 'html') |
|
| 1034 | 1086 | { |
| 1035 | - if (! preg_match('/search_/', $keyprefix)) // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1087 | + if (! preg_match('/search_/', $keyprefix)) { |
|
| 1088 | + // If keyprefix is search_ or search_options_, we must just use a simple text field |
|
| 1036 | 1089 | { |
| 1037 | 1090 | require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; |
| 1091 | + } |
|
| 1038 | 1092 | $doleditor=new DolEditor($keyprefix.$key.$keysuffix,$value,'',200,'dolibarr_notes','In',false,false,! empty($conf->fckeditor->enabled) && $conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_5,'90%'); |
| 1039 | 1093 | $out=$doleditor->Create(1); |
| 1040 | - } |
|
| 1041 | - else |
|
| 1094 | + } else |
|
| 1042 | 1095 | { |
| 1043 | 1096 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.dol_escape_htmltag($value).'" '.($moreparam?$moreparam:'').'>'; |
| 1044 | 1097 | } |
| 1045 | - } |
|
| 1046 | - elseif ($type == 'boolean') |
|
| 1098 | + } elseif ($type == 'boolean') |
|
| 1047 | 1099 | { |
| 1048 | 1100 | $checked=''; |
| 1049 | 1101 | if (!empty($value)) { |
@@ -1052,22 +1104,19 @@ discard block |
||
| 1052 | 1104 | $checked=' value="1" '; |
| 1053 | 1105 | } |
| 1054 | 1106 | $out='<input type="checkbox" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" '.$checked.' '.($moreparam?$moreparam:'').'>'; |
| 1055 | - } |
|
| 1056 | - elseif ($type == 'price') |
|
| 1107 | + } elseif ($type == 'price') |
|
| 1057 | 1108 | { |
| 1058 | 1109 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 1059 | 1110 | $value=price($value); |
| 1060 | 1111 | } |
| 1061 | 1112 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '.$langs->getCurrencySymbol($conf->currency); |
| 1062 | - } |
|
| 1063 | - elseif ($type == 'double') |
|
| 1113 | + } elseif ($type == 'double') |
|
| 1064 | 1114 | { |
| 1065 | 1115 | if (!empty($value)) { // $value in memory is a php numeric, we format it into user number format. |
| 1066 | 1116 | $value=price($value); |
| 1067 | 1117 | } |
| 1068 | 1118 | $out='<input type="text" class="flat '.$morecss.' maxwidthonsmartphone" name="'.$keyprefix.$key.$keysuffix.'" id="'.$keyprefix.$key.$keysuffix.'" value="'.$value.'" '.($moreparam?$moreparam:'').'> '; |
| 1069 | - } |
|
| 1070 | - elseif ($type == 'select') |
|
| 1119 | + } elseif ($type == 'select') |
|
| 1071 | 1120 | { |
| 1072 | 1121 | $out = ''; |
| 1073 | 1122 | if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
@@ -1080,19 +1129,23 @@ discard block |
||
| 1080 | 1129 | $out.='<option value="0"> </option>'; |
| 1081 | 1130 | foreach ($param['options'] as $key => $val) |
| 1082 | 1131 | { |
| 1083 | - if ((string) $key == '') continue; |
|
| 1132 | + if ((string) $key == '') { |
|
| 1133 | + continue; |
|
| 1134 | + } |
|
| 1084 | 1135 | list($val, $parent) = explode('|', $val); |
| 1085 | 1136 | $out.='<option value="'.$key.'"'; |
| 1086 | 1137 | $out.= (((string) $value == (string) $key)?' selected':''); |
| 1087 | 1138 | $out.= (!empty($parent)?' parent="'.$parent.'"':''); |
| 1088 | 1139 | $out.='>'; |
| 1089 | - if ($langfile && $val) $out.=$langs->trans($val); |
|
| 1090 | - else $out.=$val; |
|
| 1140 | + if ($langfile && $val) { |
|
| 1141 | + $out.=$langs->trans($val); |
|
| 1142 | + } else { |
|
| 1143 | + $out.=$val; |
|
| 1144 | + } |
|
| 1091 | 1145 | $out.='</option>'; |
| 1092 | 1146 | } |
| 1093 | 1147 | $out.='</select>'; |
| 1094 | - } |
|
| 1095 | - elseif ($type == 'sellist') |
|
| 1148 | + } elseif ($type == 'sellist') |
|
| 1096 | 1149 | { |
| 1097 | 1150 | $out = ''; |
| 1098 | 1151 | if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->MAIN_EXTRAFIELDS_USE_SELECT2)) |
@@ -1163,13 +1216,11 @@ discard block |
||
| 1163 | 1216 | { |
| 1164 | 1217 | $sql.= ' as main, '.MAIN_DB_PREFIX .$InfoFieldList[0].'_extrafields as extra'; |
| 1165 | 1218 | $sqlwhere.= ' WHERE extra.fk_object=main.'.$InfoFieldList[2]. ' AND '.$InfoFieldList[4]; |
| 1166 | - } |
|
| 1167 | - else |
|
| 1219 | + } else |
|
| 1168 | 1220 | { |
| 1169 | 1221 | $sqlwhere.= ' WHERE '.$InfoFieldList[4]; |
| 1170 | 1222 | } |
| 1171 | - } |
|
| 1172 | - else |
|
| 1223 | + } else |
|
| 1173 | 1224 | { |
| 1174 | 1225 | $sqlwhere.= ' WHERE 1=1'; |
| 1175 | 1226 | } |
@@ -1205,8 +1256,7 @@ discard block |
||
| 1205 | 1256 | { |
| 1206 | 1257 | $labeltoshow.= $obj->$field_toshow.' '; |
| 1207 | 1258 | } |
| 1208 | - } |
|
| 1209 | - else |
|
| 1259 | + } else |
|
| 1210 | 1260 | { |
| 1211 | 1261 | $labeltoshow=$obj->{$InfoFieldList[1]}; |
| 1212 | 1262 | } |
@@ -1219,25 +1269,25 @@ discard block |
||
| 1219 | 1269 | $translabel=$langs->trans($obj->$field_toshow); |
| 1220 | 1270 | if ($translabel!=$obj->$field_toshow) { |
| 1221 | 1271 | $labeltoshow=dol_trunc($translabel,18).' '; |
| 1222 | - }else { |
|
| 1272 | + } else { |
|
| 1223 | 1273 | $labeltoshow=dol_trunc($obj->$field_toshow,18).' '; |
| 1224 | 1274 | } |
| 1225 | 1275 | } |
| 1226 | 1276 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
| 1227 | - } |
|
| 1228 | - else |
|
| 1277 | + } else |
|
| 1229 | 1278 | { |
| 1230 | 1279 | if (! $notrans) |
| 1231 | 1280 | { |
| 1232 | 1281 | $translabel=$langs->trans($obj->{$InfoFieldList[1]}); |
| 1233 | 1282 | if ($translabel!=$obj->{$InfoFieldList[1]}) { |
| 1234 | 1283 | $labeltoshow=dol_trunc($translabel,18); |
| 1235 | - } |
|
| 1236 | - else { |
|
| 1284 | + } else { |
|
| 1237 | 1285 | $labeltoshow=dol_trunc($obj->{$InfoFieldList[1]},18); |
| 1238 | 1286 | } |
| 1239 | 1287 | } |
| 1240 | - if (empty($labeltoshow)) $labeltoshow='(not defined)'; |
|
| 1288 | + if (empty($labeltoshow)) { |
|
| 1289 | + $labeltoshow='(not defined)'; |
|
| 1290 | + } |
|
| 1241 | 1291 | if ($value==$obj->rowid) |
| 1242 | 1292 | { |
| 1243 | 1293 | $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>'; |
@@ -1257,19 +1307,16 @@ discard block |
||
| 1257 | 1307 | $i++; |
| 1258 | 1308 | } |
| 1259 | 1309 | $this->db->free($resql); |
| 1260 | - } |
|
| 1261 | - else { |
|
| 1310 | + } else { |
|
| 1262 | 1311 | print 'Error in request '.$sql.' '.$this->db->lasterror().'. Check setup of extra parameters.<br>'; |
| 1263 | 1312 | } |
| 1264 | 1313 | } |
| 1265 | 1314 | $out.='</select>'; |
| 1266 | - } |
|
| 1267 | - elseif ($type == 'checkbox') |
|
| 1315 | + } elseif ($type == 'checkbox') |
|
| 1268 | 1316 | { |
| 1269 | 1317 | $value_arr=explode(',',$value); |
| 1270 | 1318 | $out=$form->multiselectarray($keyprefix.$key.$keysuffix, (empty($param['options'])?null:$param['options']), $value_arr, '', 0, '', 0, '100%'); |
| 1271 | - } |
|
| 1272 | - elseif ($type == 'radio') |
|
| 1319 | + } elseif ($type == 'radio') |
|
| 1273 | 1320 | { |
| 1274 | 1321 | $out=''; |
| 1275 | 1322 | foreach ($param['options'] as $keyopt => $val) |
@@ -1280,13 +1327,11 @@ discard block |
||
| 1280 | 1327 | $out.= ($value==$keyopt?'checked':''); |
| 1281 | 1328 | $out.='/><label for="'.$keyprefix.$key.$keysuffix.'_'.$keyopt.'">'.$val.'</label><br>'; |
| 1282 | 1329 | } |
| 1283 | - } |
|
| 1284 | - elseif ($type == 'chkbxlst') |
|
| 1330 | + } elseif ($type == 'chkbxlst') |
|
| 1285 | 1331 | { |
| 1286 | 1332 | if (is_array($value)) { |
| 1287 | 1333 | $value_arr = $value; |
| 1288 | - } |
|
| 1289 | - else { |
|
| 1334 | + } else { |
|
| 1290 | 1335 | $value_arr = explode(',', $value); |
| 1291 | 1336 | } |
| 1292 | 1337 | |
@@ -1365,17 +1410,14 @@ discard block |
||
| 1365 | 1410 | if (! empty($matchCondition[1]) && ! empty($matchCondition[3]) && $matchCondition[1] != $matchCondition[3] ) { |
| 1366 | 1411 | // Nobody sain would do that without parentheses |
| 1367 | 1412 | $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
| 1368 | - } |
|
| 1369 | - else { |
|
| 1413 | + } else { |
|
| 1370 | 1414 | if (! empty($matchCondition[1])) { |
| 1371 | 1415 | $boolCond =(( $matchCondition[1] == "AND" )?' AND 1 ':' OR 0 '); |
| 1372 | 1416 | $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond.$matchCondition[3],$InfoFieldList[4]); |
| 1373 | - } |
|
| 1374 | - else if (! empty($matchCondition[3])) { |
|
| 1417 | + } else if (! empty($matchCondition[3])) { |
|
| 1375 | 1418 | $boolCond =(( $matchCondition[3] == "AND" )?' 1 AND ':' 0 OR'); |
| 1376 | 1419 | $InfoFieldList[4]=str_replace($matchCondition[0],$boolCond,$InfoFieldList[4]); |
| 1377 | - } |
|
| 1378 | - else { |
|
| 1420 | + } else { |
|
| 1379 | 1421 | $InfoFieldList[4] = 1; |
| 1380 | 1422 | } |
| 1381 | 1423 | } |
@@ -1383,8 +1425,7 @@ discard block |
||
| 1383 | 1425 | // Si l'on a un AND ou un OR, avant ou après |
| 1384 | 1426 | preg_match('#(AND|OR|) *('.$word.') *(AND|OR|)#',$InfoFieldList[4],$matchCondition); |
| 1385 | 1427 | } |
| 1386 | - } |
|
| 1387 | - else { |
|
| 1428 | + } else { |
|
| 1388 | 1429 | $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); |
| 1389 | 1430 | } |
| 1390 | 1431 | |
@@ -1452,8 +1493,9 @@ discard block |
||
| 1452 | 1493 | $labeltoshow = dol_trunc($obj->{$InfoFieldList[1]}, 18); |
| 1453 | 1494 | } |
| 1454 | 1495 | } |
| 1455 | - if (empty($labeltoshow)) |
|
| 1456 | - $labeltoshow = '(not defined)'; |
|
| 1496 | + if (empty($labeltoshow)) { |
|
| 1497 | + $labeltoshow = '(not defined)'; |
|
| 1498 | + } |
|
| 1457 | 1499 | |
| 1458 | 1500 | if (is_array($value_arr) && in_array($obj->rowid, $value_arr)) { |
| 1459 | 1501 | $data[$obj->rowid]=$labeltoshow; |
@@ -1475,14 +1517,12 @@ discard block |
||
| 1475 | 1517 | print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.<br>'; |
| 1476 | 1518 | } |
| 1477 | 1519 | } |
| 1478 | - } |
|
| 1479 | - elseif ($type == 'link') |
|
| 1520 | + } elseif ($type == 'link') |
|
| 1480 | 1521 | { |
| 1481 | 1522 | $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
| 1482 | 1523 | $showempty=(($required && $default != '')?0:1); |
| 1483 | 1524 | $out=$form->selectForForms($param_list[0], $keyprefix.$key.$keysuffix, $value, $showempty); |
| 1484 | - } |
|
| 1485 | - elseif ($type == 'password') |
|
| 1525 | + } elseif ($type == 'password') |
|
| 1486 | 1526 | { |
| 1487 | 1527 | // If prefix is 'search_', field is used as a filter, we use a common text field. |
| 1488 | 1528 | $out='<input style="display:none" type="text" name="fakeusernameremembered">'; // Hidden field to reduce impact of evil Google Chrome autopopulate bug. |
@@ -1527,8 +1567,7 @@ discard block |
||
| 1527 | 1567 | $list=dol_eval($this->attributes[$extrafieldsobjectkey]['list'][$key], 1); |
| 1528 | 1568 | $help=$this->attributes[$extrafieldsobjectkey]['help'][$key]; |
| 1529 | 1569 | $hidden=(empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
| 1530 | - } |
|
| 1531 | - else // Old usage |
|
| 1570 | + } else // Old usage |
|
| 1532 | 1571 | { |
| 1533 | 1572 | $label=$this->attribute_label[$key]; |
| 1534 | 1573 | $type=$this->attribute_type[$key]; |
@@ -1545,7 +1584,10 @@ discard block |
||
| 1545 | 1584 | $hidden=(empty($list) ? 1 : 0); // If $list empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) |
| 1546 | 1585 | } |
| 1547 | 1586 | |
| 1548 | - if ($hidden) return ''; // This is a protection. If field is hidden, we should just not call this method. |
|
| 1587 | + if ($hidden) { |
|
| 1588 | + return ''; |
|
| 1589 | + } |
|
| 1590 | + // This is a protection. If field is hidden, we should just not call this method. |
|
| 1549 | 1591 | |
| 1550 | 1592 | // If field is a computed field, value must become result of compute |
| 1551 | 1593 | if ($computed) |
@@ -1560,52 +1602,45 @@ discard block |
||
| 1560 | 1602 | { |
| 1561 | 1603 | $showsize=10; |
| 1562 | 1604 | $value=dol_print_date($value, 'day'); |
| 1563 | - } |
|
| 1564 | - elseif ($type == 'datetime') |
|
| 1605 | + } elseif ($type == 'datetime') |
|
| 1565 | 1606 | { |
| 1566 | 1607 | $showsize=19; |
| 1567 | 1608 | $value=dol_print_date($value, 'dayhour'); |
| 1568 | - } |
|
| 1569 | - elseif ($type == 'int') |
|
| 1609 | + } elseif ($type == 'int') |
|
| 1570 | 1610 | { |
| 1571 | 1611 | $showsize=10; |
| 1572 | - } |
|
| 1573 | - elseif ($type == 'double') |
|
| 1612 | + } elseif ($type == 'double') |
|
| 1574 | 1613 | { |
| 1575 | 1614 | if (!empty($value)) { |
| 1576 | 1615 | $value=price($value); |
| 1577 | 1616 | } |
| 1578 | - } |
|
| 1579 | - elseif ($type == 'boolean') |
|
| 1617 | + } elseif ($type == 'boolean') |
|
| 1580 | 1618 | { |
| 1581 | 1619 | $checked=''; |
| 1582 | 1620 | if (!empty($value)) { |
| 1583 | 1621 | $checked=' checked '; |
| 1584 | 1622 | } |
| 1585 | 1623 | $value='<input type="checkbox" '.$checked.' '.($moreparam?$moreparam:'').' readonly disabled>'; |
| 1586 | - } |
|
| 1587 | - elseif ($type == 'mail') |
|
| 1624 | + } elseif ($type == 'mail') |
|
| 1588 | 1625 | { |
| 1589 | 1626 | $value=dol_print_email($value, 0, 0, 0, 64, 1, 1); |
| 1590 | - } |
|
| 1591 | - elseif ($type == 'url') |
|
| 1627 | + } elseif ($type == 'url') |
|
| 1592 | 1628 | { |
| 1593 | 1629 | $value=dol_print_url($value,'_blank',32,1); |
| 1594 | - } |
|
| 1595 | - elseif ($type == 'phone') |
|
| 1630 | + } elseif ($type == 'phone') |
|
| 1596 | 1631 | { |
| 1597 | 1632 | $value=dol_print_phone($value, '', 0, 0, '', ' ', 1); |
| 1598 | - } |
|
| 1599 | - elseif ($type == 'price') |
|
| 1633 | + } elseif ($type == 'price') |
|
| 1600 | 1634 | { |
| 1601 | 1635 | $value=price($value, 0, $langs, 0, 0, -1, $conf->currency); |
| 1602 | - } |
|
| 1603 | - elseif ($type == 'select') |
|
| 1636 | + } elseif ($type == 'select') |
|
| 1604 | 1637 | { |
| 1605 | - if ($langfile && $param['options'][$value]) $value=$langs->trans($param['options'][$value]); |
|
| 1606 | - else $value=$param['options'][$value]; |
|
| 1607 | - } |
|
| 1608 | - elseif ($type == 'sellist') |
|
| 1638 | + if ($langfile && $param['options'][$value]) { |
|
| 1639 | + $value=$langs->trans($param['options'][$value]); |
|
| 1640 | + } else { |
|
| 1641 | + $value=$param['options'][$value]; |
|
| 1642 | + } |
|
| 1643 | + } elseif ($type == 'sellist') |
|
| 1609 | 1644 | { |
| 1610 | 1645 | $param_list=array_keys($param['options']); |
| 1611 | 1646 | $InfoFieldList = explode(":", $param_list[0]); |
@@ -1635,7 +1670,7 @@ discard block |
||
| 1635 | 1670 | $sql.= " WHERE ".$selectkey."=0"; |
| 1636 | 1671 | } elseif ($selectkey=='rowid') { |
| 1637 | 1672 | $sql.= " WHERE ".$selectkey."=".$this->db->escape($value); |
| 1638 | - }else { |
|
| 1673 | + } else { |
|
| 1639 | 1674 | $sql.= " WHERE ".$selectkey."='".$this->db->escape($value)."'"; |
| 1640 | 1675 | } |
| 1641 | 1676 | |
@@ -1662,12 +1697,11 @@ discard block |
||
| 1662 | 1697 | } |
| 1663 | 1698 | if ($translabel!=$field_toshow) { |
| 1664 | 1699 | $value.=dol_trunc($translabel,18).' '; |
| 1665 | - }else { |
|
| 1700 | + } else { |
|
| 1666 | 1701 | $value.=$obj->$field_toshow.' '; |
| 1667 | 1702 | } |
| 1668 | 1703 | } |
| 1669 | - } |
|
| 1670 | - else |
|
| 1704 | + } else |
|
| 1671 | 1705 | { |
| 1672 | 1706 | $translabel=''; |
| 1673 | 1707 | if (!empty($obj->{$InfoFieldList[1]})) { |
@@ -1675,18 +1709,17 @@ discard block |
||
| 1675 | 1709 | } |
| 1676 | 1710 | if ($translabel!=$obj->{$InfoFieldList[1]}) { |
| 1677 | 1711 | $value=dol_trunc($translabel,18); |
| 1678 | - }else { |
|
| 1712 | + } else { |
|
| 1679 | 1713 | $value=$obj->{$InfoFieldList[1]}; |
| 1680 | 1714 | } |
| 1681 | 1715 | } |
| 1716 | + } else { |
|
| 1717 | + dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 1682 | 1718 | } |
| 1683 | - else dol_syslog(get_class($this).'::showOutputField error '.$this->db->lasterror(), LOG_WARNING); |
|
| 1684 | - } |
|
| 1685 | - elseif ($type == 'radio') |
|
| 1719 | + } elseif ($type == 'radio') |
|
| 1686 | 1720 | { |
| 1687 | 1721 | $value=$param['options'][$value]; |
| 1688 | - } |
|
| 1689 | - elseif ($type == 'checkbox') |
|
| 1722 | + } elseif ($type == 'checkbox') |
|
| 1690 | 1723 | { |
| 1691 | 1724 | $value_arr=explode(',',$value); |
| 1692 | 1725 | $value=''; |
@@ -1698,8 +1731,7 @@ discard block |
||
| 1698 | 1731 | } |
| 1699 | 1732 | } |
| 1700 | 1733 | $value='<div class="select2-container-multi-dolibarr" style="width: 90%;"><ul class="select2-choices-dolibarr">'.implode(' ', $toprint).'</ul></div>'; |
| 1701 | - } |
|
| 1702 | - elseif ($type == 'chkbxlst') |
|
| 1734 | + } elseif ($type == 'chkbxlst') |
|
| 1703 | 1735 | { |
| 1704 | 1736 | $value_arr = explode(',', $value); |
| 1705 | 1737 | |
@@ -1767,15 +1799,17 @@ discard block |
||
| 1767 | 1799 | } else { |
| 1768 | 1800 | dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); |
| 1769 | 1801 | } |
| 1770 | - } |
|
| 1771 | - elseif ($type == 'link') |
|
| 1802 | + } elseif ($type == 'link') |
|
| 1772 | 1803 | { |
| 1773 | 1804 | $out=''; |
| 1774 | 1805 | |
| 1775 | 1806 | // Only if something to display (perf) |
| 1776 | - if ($value) // If we have -1 here, pb is into sert, not into ouptu |
|
| 1807 | + if ($value) { |
|
| 1808 | + // If we have -1 here, pb is into sert, not into ouptu |
|
| 1777 | 1809 | { |
| 1778 | - $param_list=array_keys($param['options']); // $param_list='ObjectName:classPath' |
|
| 1810 | + $param_list=array_keys($param['options']); |
|
| 1811 | + } |
|
| 1812 | + // $param_list='ObjectName:classPath' |
|
| 1779 | 1813 | |
| 1780 | 1814 | $InfoFieldList = explode(":", $param_list[0]); |
| 1781 | 1815 | $classname=$InfoFieldList[0]; |
@@ -1789,30 +1823,27 @@ discard block |
||
| 1789 | 1823 | $object->fetch($value); |
| 1790 | 1824 | $value=$object->getNomUrl(3); |
| 1791 | 1825 | } |
| 1792 | - } |
|
| 1793 | - else |
|
| 1826 | + } else |
|
| 1794 | 1827 | { |
| 1795 | 1828 | dol_syslog('Error bad setup of extrafield', LOG_WARNING); |
| 1796 | 1829 | return 'Error bad setup of extrafield'; |
| 1797 | 1830 | } |
| 1798 | 1831 | } |
| 1799 | - } |
|
| 1800 | - elseif ($type == 'text') |
|
| 1832 | + } elseif ($type == 'text') |
|
| 1801 | 1833 | { |
| 1802 | 1834 | $value=dol_htmlentitiesbr($value); |
| 1803 | - } |
|
| 1804 | - elseif ($type == 'html') |
|
| 1835 | + } elseif ($type == 'html') |
|
| 1805 | 1836 | { |
| 1806 | 1837 | $value=dol_htmlentitiesbr($value); |
| 1807 | - } |
|
| 1808 | - elseif ($type == 'password') |
|
| 1838 | + } elseif ($type == 'password') |
|
| 1809 | 1839 | { |
| 1810 | 1840 | $value=dol_trunc(preg_replace('/./i','*',$value), 8, 'right', 'UTF-8', 1); |
| 1811 | - } |
|
| 1812 | - else |
|
| 1841 | + } else |
|
| 1813 | 1842 | { |
| 1814 | 1843 | $showsize=round($size); |
| 1815 | - if ($showsize > 48) $showsize=48; |
|
| 1844 | + if ($showsize > 48) { |
|
| 1845 | + $showsize=48; |
|
| 1846 | + } |
|
| 1816 | 1847 | } |
| 1817 | 1848 | |
| 1818 | 1849 | //print $type.'-'.$size; |
@@ -1832,40 +1863,36 @@ discard block |
||
| 1832 | 1863 | { |
| 1833 | 1864 | global $conf,$langs; |
| 1834 | 1865 | |
| 1835 | - if (! empty($extrafieldsobjectkey)) $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1836 | - else $type=$this->attribute_type[$key]; |
|
| 1866 | + if (! empty($extrafieldsobjectkey)) { |
|
| 1867 | + $type=$this->attributes[$extrafieldsobjectkey]['type'][$key]; |
|
| 1868 | + } else { |
|
| 1869 | + $type=$this->attribute_type[$key]; |
|
| 1870 | + } |
|
| 1837 | 1871 | |
| 1838 | 1872 | $align=''; |
| 1839 | 1873 | |
| 1840 | 1874 | if ($type == 'date') |
| 1841 | 1875 | { |
| 1842 | 1876 | $align="center"; |
| 1843 | - } |
|
| 1844 | - elseif ($type == 'datetime') |
|
| 1877 | + } elseif ($type == 'datetime') |
|
| 1845 | 1878 | { |
| 1846 | 1879 | $align="center"; |
| 1847 | - } |
|
| 1848 | - elseif ($type == 'int') |
|
| 1880 | + } elseif ($type == 'int') |
|
| 1849 | 1881 | { |
| 1850 | 1882 | $align="right"; |
| 1851 | - } |
|
| 1852 | - elseif ($type == 'double') |
|
| 1883 | + } elseif ($type == 'double') |
|
| 1853 | 1884 | { |
| 1854 | 1885 | $align="right"; |
| 1855 | - } |
|
| 1856 | - elseif ($type == 'boolean') |
|
| 1886 | + } elseif ($type == 'boolean') |
|
| 1857 | 1887 | { |
| 1858 | 1888 | $align="center"; |
| 1859 | - } |
|
| 1860 | - elseif ($type == 'radio') |
|
| 1889 | + } elseif ($type == 'radio') |
|
| 1861 | 1890 | { |
| 1862 | 1891 | $align="center"; |
| 1863 | - } |
|
| 1864 | - elseif ($type == 'checkbox') |
|
| 1892 | + } elseif ($type == 'checkbox') |
|
| 1865 | 1893 | { |
| 1866 | 1894 | $align="center"; |
| 1867 | - } |
|
| 1868 | - elseif ($type == 'price') |
|
| 1895 | + } elseif ($type == 'price') |
|
| 1869 | 1896 | { |
| 1870 | 1897 | $align="right"; |
| 1871 | 1898 | } |
@@ -1904,17 +1931,23 @@ discard block |
||
| 1904 | 1931 | $nofillrequired='';// For error when required field left blank |
| 1905 | 1932 | $error_field_required = array(); |
| 1906 | 1933 | |
| 1907 | - if (is_array($this->attributes[$object->table_element]['label'])) $extralabels=$this->attributes[$object->table_element]['label']; |
|
| 1934 | + if (is_array($this->attributes[$object->table_element]['label'])) { |
|
| 1935 | + $extralabels=$this->attributes[$object->table_element]['label']; |
|
| 1936 | + } |
|
| 1908 | 1937 | |
| 1909 | 1938 | if (is_array($extralabels)) |
| 1910 | 1939 | { |
| 1911 | 1940 | // Get extra fields |
| 1912 | 1941 | foreach ($extralabels as $key => $value) |
| 1913 | 1942 | { |
| 1914 | - if (! empty($onlykey) && $key != $onlykey) continue; |
|
| 1943 | + if (! empty($onlykey) && $key != $onlykey) { |
|
| 1944 | + continue; |
|
| 1945 | + } |
|
| 1915 | 1946 | |
| 1916 | 1947 | $key_type = $this->attributes[$object->table_element]['type'][$key]; |
| 1917 | - if ($key_type == 'separate') continue; |
|
| 1948 | + if ($key_type == 'separate') { |
|
| 1949 | + continue; |
|
| 1950 | + } |
|
| 1918 | 1951 | |
| 1919 | 1952 | $enabled = 1; |
| 1920 | 1953 | if (isset($this->attributes[$object->table_element]['list'][$key])) |
@@ -1926,10 +1959,15 @@ discard block |
||
| 1926 | 1959 | { |
| 1927 | 1960 | $perms = dol_eval($this->attributes[$object->table_element]['perms'][$key], 1); |
| 1928 | 1961 | } |
| 1929 | - if (empty($enabled)) continue; |
|
| 1930 | - if (empty($perms)) continue; |
|
| 1962 | + if (empty($enabled)) { |
|
| 1963 | + continue; |
|
| 1964 | + } |
|
| 1965 | + if (empty($perms)) { |
|
| 1966 | + continue; |
|
| 1967 | + } |
|
| 1931 | 1968 | |
| 1932 | - if ($this->attributes[$object->table_element]['required'][$key]) // Value is required |
|
| 1969 | + if ($this->attributes[$object->table_element]['required'][$key]) { |
|
| 1970 | + // Value is required |
|
| 1933 | 1971 | { |
| 1934 | 1972 | // Check if empty without using GETPOST, value can be alpha, int, array, etc... |
| 1935 | 1973 | if ((! is_array($_POST["options_".$key]) && empty($_POST["options_".$key]) && $_POST["options_".$key] != '0') |
@@ -1937,6 +1975,7 @@ discard block |
||
| 1937 | 1975 | { |
| 1938 | 1976 | //print 'ccc'.$value.'-'.$this->attributes[$object->table_element]['required'][$key]; |
| 1939 | 1977 | $nofillrequired++; |
| 1978 | + } |
|
| 1940 | 1979 | $error_field_required[] = $langs->transnoentitiesnoconv($value); |
| 1941 | 1980 | } |
| 1942 | 1981 | } |
@@ -1946,28 +1985,24 @@ discard block |
||
| 1946 | 1985 | // Clean parameters |
| 1947 | 1986 | // TODO GMT date in memory must be GMT so we should add gm=true in parameters |
| 1948 | 1987 | $value_key=dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
| 1949 | - } |
|
| 1950 | - elseif (in_array($key_type,array('datetime'))) |
|
| 1988 | + } elseif (in_array($key_type,array('datetime'))) |
|
| 1951 | 1989 | { |
| 1952 | 1990 | // Clean parameters |
| 1953 | 1991 | // TODO GMT date in memory must be GMT so we should add gm=true in parameters |
| 1954 | 1992 | $value_key=dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); |
| 1955 | - } |
|
| 1956 | - else if (in_array($key_type,array('checkbox','chkbxlst'))) |
|
| 1993 | + } else if (in_array($key_type,array('checkbox','chkbxlst'))) |
|
| 1957 | 1994 | { |
| 1958 | 1995 | $value_arr=GETPOST("options_".$key, 'array'); // check if an array |
| 1959 | 1996 | if (!empty($value_arr)) { |
| 1960 | 1997 | $value_key=implode($value_arr,','); |
| 1961 | - }else { |
|
| 1998 | + } else { |
|
| 1962 | 1999 | $value_key=''; |
| 1963 | 2000 | } |
| 1964 | - } |
|
| 1965 | - else if (in_array($key_type,array('price','double'))) |
|
| 2001 | + } else if (in_array($key_type,array('price','double'))) |
|
| 1966 | 2002 | { |
| 1967 | 2003 | $value_arr=GETPOST("options_".$key, 'alpha'); |
| 1968 | 2004 | $value_key=price2num($value_arr); |
| 1969 | - } |
|
| 1970 | - else |
|
| 2005 | + } else |
|
| 1971 | 2006 | { |
| 1972 | 2007 | $value_key=GETPOST("options_".$key); |
| 1973 | 2008 | } |
@@ -1979,12 +2014,10 @@ discard block |
||
| 1979 | 2014 | $langs->load('errors'); |
| 1980 | 2015 | setEventMessages($langs->trans('ErrorFieldsRequired').' : '.implode(', ',$error_field_required), null, 'errors'); |
| 1981 | 2016 | return -1; |
| 1982 | - } |
|
| 1983 | - else { |
|
| 2017 | + } else { |
|
| 1984 | 2018 | return 1; |
| 1985 | 2019 | } |
| 1986 | - } |
|
| 1987 | - else { |
|
| 2020 | + } else { |
|
| 1988 | 2021 | return 0; |
| 1989 | 2022 | } |
| 1990 | 2023 | } |
@@ -2004,8 +2037,7 @@ discard block |
||
| 2004 | 2037 | if (is_string($extrafieldsobjectkey) && is_array($this->attributes[$extrafieldsobjectkey]['label'])) |
| 2005 | 2038 | { |
| 2006 | 2039 | $extralabels = $this->attributes[$extrafieldsobjectkey]['label']; |
| 2007 | - } |
|
| 2008 | - else |
|
| 2040 | + } else |
|
| 2009 | 2041 | { |
| 2010 | 2042 | $extralabels = $extrafieldsobjectkey; |
| 2011 | 2043 | } |
@@ -2027,20 +2059,17 @@ discard block |
||
| 2027 | 2059 | { |
| 2028 | 2060 | // Clean parameters |
| 2029 | 2061 | $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); |
| 2030 | - } |
|
| 2031 | - else if (in_array($key_type,array('checkbox', 'chkbxlst'))) |
|
| 2062 | + } else if (in_array($key_type,array('checkbox', 'chkbxlst'))) |
|
| 2032 | 2063 | { |
| 2033 | 2064 | $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); |
| 2034 | 2065 | // Make sure we get an array even if there's only one checkbox |
| 2035 | 2066 | $value_arr=(array) $value_arr; |
| 2036 | 2067 | $value_key=implode(',', $value_arr); |
| 2037 | - } |
|
| 2038 | - else if (in_array($key_type,array('price','double'))) |
|
| 2068 | + } else if (in_array($key_type,array('price','double'))) |
|
| 2039 | 2069 | { |
| 2040 | 2070 | $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); |
| 2041 | 2071 | $value_key=price2num($value_arr); |
| 2042 | - } |
|
| 2043 | - else |
|
| 2072 | + } else |
|
| 2044 | 2073 | { |
| 2045 | 2074 | $value_key=GETPOST($keysuffix."options_".$key.$keyprefix); |
| 2046 | 2075 | } |
@@ -137,7 +137,9 @@ discard block |
||
| 137 | 137 | |
| 138 | 138 | // Clean parameters |
| 139 | 139 | $this->description=trim($this->description); |
| 140 | - if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT']; |
|
| 140 | + if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) { |
|
| 141 | + $this->user_agent=$_SERVER['HTTP_USER_AGENT']; |
|
| 142 | + } |
|
| 141 | 143 | |
| 142 | 144 | // Check parameters |
| 143 | 145 | if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; } |
@@ -167,8 +169,7 @@ discard block |
||
| 167 | 169 | { |
| 168 | 170 | $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events"); |
| 169 | 171 | return $this->id; |
| 170 | - } |
|
| 171 | - else |
|
| 172 | + } else |
|
| 172 | 173 | { |
| 173 | 174 | $this->error="Error ".$this->db->lasterror(); |
| 174 | 175 | return -1; |
@@ -256,8 +257,7 @@ discard block |
||
| 256 | 257 | $this->db->free($resql); |
| 257 | 258 | |
| 258 | 259 | return 1; |
| 259 | - } |
|
| 260 | - else |
|
| 260 | + } else |
|
| 261 | 261 | { |
| 262 | 262 | $this->error="Error ".$this->db->lasterror(); |
| 263 | 263 | return -1; |
@@ -172,9 +172,13 @@ |
||
| 172 | 172 | |
| 173 | 173 | |
| 174 | 174 | $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; |
| 175 | - if ($id) $sql.= " WHERE t.id = ".$id; |
|
| 176 | - elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 177 | - elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 175 | + if ($id) { |
|
| 176 | + $sql.= " WHERE t.id = ".$id; |
|
| 177 | + } elseif ($code) { |
|
| 178 | + $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; |
|
| 179 | + } elseif ($label) { |
|
| 180 | + $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; |
|
| 181 | + } |
|
| 178 | 182 | |
| 179 | 183 | |
| 180 | 184 | $resql = $this->db->query($sql); |
@@ -105,7 +105,9 @@ discard block |
||
| 105 | 105 | // phpcs:enable |
| 106 | 106 | global $conf, $langs, $user, $form; |
| 107 | 107 | |
| 108 | - if (! is_object($form)) $form=new Form($this->db); |
|
| 108 | + if (! is_object($form)) { |
|
| 109 | + $form=new Form($this->db); |
|
| 110 | + } |
|
| 109 | 111 | |
| 110 | 112 | // Load translation files required by the page |
| 111 | 113 | $langs->loadLangs(array('other', 'mails', 'sms')); |
@@ -131,7 +133,9 @@ discard block |
||
| 131 | 133 | } |
| 132 | 134 | </script>'; |
| 133 | 135 | |
| 134 | - if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n"; |
|
| 136 | + if ($showform) { |
|
| 137 | + print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n"; |
|
| 138 | + } |
|
| 135 | 139 | |
| 136 | 140 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
| 137 | 141 | foreach ($this->param as $key=>$value) |
@@ -141,9 +145,11 @@ discard block |
||
| 141 | 145 | print "<table class=\"border centpercent\">\n"; |
| 142 | 146 | |
| 143 | 147 | // Substitution array |
| 144 | - if (! empty($this->withsubstit)) // Unset or set ->withsubstit=0 to disable this. |
|
| 148 | + if (! empty($this->withsubstit)) { |
|
| 149 | + // Unset or set ->withsubstit=0 to disable this. |
|
| 145 | 150 | { |
| 146 | 151 | print "<tr><td colspan=\"2\">"; |
| 152 | + } |
|
| 147 | 153 | $help=""; |
| 148 | 154 | foreach($this->substit as $key => $val) |
| 149 | 155 | { |
@@ -172,8 +178,7 @@ discard block |
||
| 172 | 178 | if ($this->fromsms) |
| 173 | 179 | { |
| 174 | 180 | print $this->fromsms; |
| 175 | - } |
|
| 176 | - else |
|
| 181 | + } else |
|
| 177 | 182 | { |
| 178 | 183 | if ($this->fromtype) |
| 179 | 184 | { |
@@ -183,34 +188,34 @@ discard block |
||
| 183 | 188 | } |
| 184 | 189 | print "</td></tr>\n"; |
| 185 | 190 | print "</td></tr>\n"; |
| 186 | - } |
|
| 187 | - else |
|
| 191 | + } else |
|
| 188 | 192 | { |
| 189 | 193 | print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>"; |
| 190 | 194 | //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">'; |
| 191 | - if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') // For backward compatibility @deprecated |
|
| 195 | + if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') { |
|
| 196 | + // For backward compatibility @deprecated |
|
| 192 | 197 | { |
| 193 | 198 | dol_include_once('/ovh/class/ovhsms.class.php'); |
| 199 | + } |
|
| 194 | 200 | try |
| 195 | 201 | { |
| 196 | 202 | $sms = new OvhSms($this->db); |
| 197 | 203 | if (empty($conf->global->OVHSMS_ACCOUNT)) |
| 198 | 204 | { |
| 199 | 205 | $resultsender = 'ErrorOVHSMS_ACCOUNT not defined'; |
| 200 | - } |
|
| 201 | - else |
|
| 206 | + } else |
|
| 202 | 207 | { |
| 203 | 208 | $resultsender = $sms->SmsSenderList(); |
| 204 | 209 | } |
| 205 | - } |
|
| 206 | - catch(Exception $e) |
|
| 210 | + } catch(Exception $e) |
|
| 207 | 211 | { |
| 208 | 212 | dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
| 209 | 213 | } |
| 210 | - } |
|
| 211 | - else if (!empty($conf->global->MAIN_SMS_SENDMODE)) // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
|
| 214 | + } else if (!empty($conf->global->MAIN_SMS_SENDMODE)) { |
|
| 215 | + // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module' |
|
| 212 | 216 | { |
| 213 | 217 | $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE); |
| 218 | + } |
|
| 214 | 219 | $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]); |
| 215 | 220 | dol_include_once('/'.$module.'/class/'.$classfile.'.class.php'); |
| 216 | 221 | try |
@@ -220,20 +225,17 @@ discard block |
||
| 220 | 225 | { |
| 221 | 226 | $sms = new $classname($this->db); |
| 222 | 227 | $resultsender = $sms->SmsSenderList(); |
| 223 | - } |
|
| 224 | - else |
|
| 228 | + } else |
|
| 225 | 229 | { |
| 226 | 230 | $sms = new stdClass(); |
| 227 | 231 | $sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found'; |
| 228 | 232 | } |
| 229 | - } |
|
| 230 | - catch(Exception $e) |
|
| 233 | + } catch(Exception $e) |
|
| 231 | 234 | { |
| 232 | 235 | dol_print_error('','Error to get list of senders: '.$e->getMessage()); |
| 233 | 236 | exit; |
| 234 | 237 | } |
| 235 | - } |
|
| 236 | - else |
|
| 238 | + } else |
|
| 237 | 239 | { |
| 238 | 240 | dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING); |
| 239 | 241 | $resultsender=array(); |
@@ -248,11 +250,12 @@ discard block |
||
| 248 | 250 | print '<option value="'.$obj->number.'">'.$obj->number.'</option>'; |
| 249 | 251 | } |
| 250 | 252 | print '</select>'; |
| 251 | - } |
|
| 252 | - else |
|
| 253 | + } else |
|
| 253 | 254 | { |
| 254 | 255 | print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound"); |
| 255 | - if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error; |
|
| 256 | + if (is_object($sms) && ! empty($sms->error)) { |
|
| 257 | + print ' '.$sms->error; |
|
| 258 | + } |
|
| 256 | 259 | print '</span>'; |
| 257 | 260 | } |
| 258 | 261 | print '</td>'; |
@@ -271,8 +274,7 @@ discard block |
||
| 271 | 274 | if ($this->withtoreadonly) |
| 272 | 275 | { |
| 273 | 276 | print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:""; |
| 274 | - } |
|
| 275 | - else |
|
| 277 | + } else |
|
| 276 | 278 | { |
| 277 | 279 | print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">"; |
| 278 | 280 | if (! empty($this->withtosocid) && $this->withtosocid > 0) |
@@ -300,7 +302,9 @@ discard block |
||
| 300 | 302 | $defaultmessage=$this->withbody; |
| 301 | 303 | } |
| 302 | 304 | $defaultmessage=make_substitutions($defaultmessage,$this->substit); |
| 303 | - if (isset($_POST["message"])) $defaultmessage=$_POST["message"]; |
|
| 305 | + if (isset($_POST["message"])) { |
|
| 306 | + $defaultmessage=$_POST["message"]; |
|
| 307 | + } |
|
| 304 | 308 | $defaultmessage=str_replace('\n',"\n",$defaultmessage); |
| 305 | 309 | |
| 306 | 310 | print "<tr>"; |
@@ -310,8 +314,7 @@ discard block |
||
| 310 | 314 | { |
| 311 | 315 | print nl2br($defaultmessage); |
| 312 | 316 | print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">'; |
| 313 | - } |
|
| 314 | - else |
|
| 317 | + } else |
|
| 315 | 318 | { |
| 316 | 319 | print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>'; |
| 317 | 320 | print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>'; |
@@ -218,19 +218,19 @@ discard block |
||
| 218 | 218 | $foundintocache=1; |
| 219 | 219 | |
| 220 | 220 | $this->_lastfetchdate=$filedate; |
| 221 | - } |
|
| 222 | - else |
|
| 221 | + } else |
|
| 223 | 222 | { |
| 224 | 223 | dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it."); |
| 225 | 224 | } |
| 226 | 225 | } |
| 227 | 226 | |
| 228 | 227 | // Load file into $str |
| 229 | - if ($foundintocache) // Cache file found and is not too old |
|
| 228 | + if ($foundintocache) { |
|
| 229 | + // Cache file found and is not too old |
|
| 230 | 230 | { |
| 231 | 231 | $str = file_get_contents($newpathofdestfile); |
| 232 | 232 | } |
| 233 | - else |
|
| 233 | + } else |
|
| 234 | 234 | { |
| 235 | 235 | try { |
| 236 | 236 | ini_set("user_agent","Dolibarr ERP-CRM RSS reader"); |
@@ -238,14 +238,17 @@ discard block |
||
| 238 | 238 | ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT); |
| 239 | 239 | |
| 240 | 240 | $opts = array('http'=>array('method'=>"GET")); |
| 241 | - if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT; |
|
| 242 | - if (! empty($conf->global->MAIN_PROXY_USE)) $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT; |
|
| 241 | + if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) { |
|
| 242 | + $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT; |
|
| 243 | + } |
|
| 244 | + if (! empty($conf->global->MAIN_PROXY_USE)) { |
|
| 245 | + $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT; |
|
| 246 | + } |
|
| 243 | 247 | //var_dump($opts);exit; |
| 244 | 248 | $context = stream_context_create($opts); |
| 245 | 249 | |
| 246 | 250 | $str = file_get_contents($this->_urlRSS, false, $context); |
| 247 | - } |
|
| 248 | - catch (Exception $e) { |
|
| 251 | + } catch (Exception $e) { |
|
| 249 | 252 | print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage(); |
| 250 | 253 | } |
| 251 | 254 | } |
@@ -258,8 +261,7 @@ discard block |
||
| 258 | 261 | //print 'xx'.LIBXML_NOCDATA; |
| 259 | 262 | libxml_use_internal_errors(false); |
| 260 | 263 | $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA); |
| 261 | - } |
|
| 262 | - else |
|
| 264 | + } else |
|
| 263 | 265 | { |
| 264 | 266 | $xmlparser=xml_parser_create(''); |
| 265 | 267 | if (!is_resource($xmlparser)) { |
@@ -283,18 +285,21 @@ discard block |
||
| 283 | 285 | if (empty($foundintocache) && $cachedir) |
| 284 | 286 | { |
| 285 | 287 | dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk."); |
| 286 | - if (! dol_is_dir($cachedir)) dol_mkdir($cachedir); |
|
| 288 | + if (! dol_is_dir($cachedir)) { |
|
| 289 | + dol_mkdir($cachedir); |
|
| 290 | + } |
|
| 287 | 291 | $fp = fopen($newpathofdestfile, 'w'); |
| 288 | 292 | if ($fp) |
| 289 | 293 | { |
| 290 | 294 | fwrite($fp, $str); |
| 291 | 295 | fclose($fp); |
| 292 | - if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK; |
|
| 296 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 297 | + $newmask=$conf->global->MAIN_UMASK; |
|
| 298 | + } |
|
| 293 | 299 | @chmod($newpathofdestfile, octdec($newmask)); |
| 294 | 300 | |
| 295 | 301 | $this->_lastfetchdate=$nowgmt; |
| 296 | - } |
|
| 297 | - else |
|
| 302 | + } else |
|
| 298 | 303 | { |
| 299 | 304 | print 'Error, failed to open file '.$newpathofdestfile.' for write'; |
| 300 | 305 | } |
@@ -302,10 +307,14 @@ discard block |
||
| 302 | 307 | |
| 303 | 308 | unset($str); // Free memory |
| 304 | 309 | |
| 305 | - if (empty($rss->_format)) // If format not detected automatically |
|
| 310 | + if (empty($rss->_format)) { |
|
| 311 | + // If format not detected automatically |
|
| 306 | 312 | { |
| 307 | 313 | $rss->_format='rss'; |
| 308 | - if (empty($rss->channel)) $rss->_format='atom'; |
|
| 314 | + } |
|
| 315 | + if (empty($rss->channel)) { |
|
| 316 | + $rss->_format='atom'; |
|
| 317 | + } |
|
| 309 | 318 | } |
| 310 | 319 | |
| 311 | 320 | $items=array(); |
@@ -316,58 +325,114 @@ discard block |
||
| 316 | 325 | //var_dump($rss); |
| 317 | 326 | if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
| 318 | 327 | { |
| 319 | - if (!empty($rss->channel->language)) $this->_language = (string) $rss->channel->language; |
|
| 320 | - if (!empty($rss->channel->generator)) $this->_generator = (string) $rss->channel->generator; |
|
| 321 | - if (!empty($rss->channel->copyright)) $this->_copyright = (string) $rss->channel->copyright; |
|
| 322 | - if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate; |
|
| 323 | - if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0]; |
|
| 324 | - if (!empty($rss->channel->link)) $this->_link = (string) $rss->channel->link; |
|
| 325 | - if (!empty($rss->channel->title)) $this->_title = (string) $rss->channel->title; |
|
| 326 | - if (!empty($rss->channel->description)) $this->_description = (string) $rss->channel->description; |
|
| 327 | - } |
|
| 328 | - else |
|
| 328 | + if (!empty($rss->channel->language)) { |
|
| 329 | + $this->_language = (string) $rss->channel->language; |
|
| 330 | + } |
|
| 331 | + if (!empty($rss->channel->generator)) { |
|
| 332 | + $this->_generator = (string) $rss->channel->generator; |
|
| 333 | + } |
|
| 334 | + if (!empty($rss->channel->copyright)) { |
|
| 335 | + $this->_copyright = (string) $rss->channel->copyright; |
|
| 336 | + } |
|
| 337 | + if (!empty($rss->channel->lastbuilddate)) { |
|
| 338 | + $this->_lastbuilddate = (string) $rss->channel->lastbuilddate; |
|
| 339 | + } |
|
| 340 | + if (!empty($rss->channel->image->url[0])) { |
|
| 341 | + $this->_imageurl = (string) $rss->channel->image->url[0]; |
|
| 342 | + } |
|
| 343 | + if (!empty($rss->channel->link)) { |
|
| 344 | + $this->_link = (string) $rss->channel->link; |
|
| 345 | + } |
|
| 346 | + if (!empty($rss->channel->title)) { |
|
| 347 | + $this->_title = (string) $rss->channel->title; |
|
| 348 | + } |
|
| 349 | + if (!empty($rss->channel->description)) { |
|
| 350 | + $this->_description = (string) $rss->channel->description; |
|
| 351 | + } |
|
| 352 | + } else |
|
| 329 | 353 | { |
| 330 | 354 | //var_dump($rss->channel); |
| 331 | - if (!empty($rss->channel['language'])) $this->_language = (string) $rss->channel['language']; |
|
| 332 | - if (!empty($rss->channel['generator'])) $this->_generator = (string) $rss->channel['generator']; |
|
| 333 | - if (!empty($rss->channel['copyright'])) $this->_copyright = (string) $rss->channel['copyright']; |
|
| 334 | - if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate']; |
|
| 335 | - if (!empty($rss->image['url'])) $this->_imageurl = (string) $rss->image['url']; |
|
| 336 | - if (!empty($rss->channel['link'])) $this->_link = (string) $rss->channel['link']; |
|
| 337 | - if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title']; |
|
| 338 | - if (!empty($rss->channel['description'])) $this->_description = (string) $rss->channel['description']; |
|
| 355 | + if (!empty($rss->channel['language'])) { |
|
| 356 | + $this->_language = (string) $rss->channel['language']; |
|
| 357 | + } |
|
| 358 | + if (!empty($rss->channel['generator'])) { |
|
| 359 | + $this->_generator = (string) $rss->channel['generator']; |
|
| 360 | + } |
|
| 361 | + if (!empty($rss->channel['copyright'])) { |
|
| 362 | + $this->_copyright = (string) $rss->channel['copyright']; |
|
| 363 | + } |
|
| 364 | + if (!empty($rss->channel['lastbuilddate'])) { |
|
| 365 | + $this->_lastbuilddate = (string) $rss->channel['lastbuilddate']; |
|
| 366 | + } |
|
| 367 | + if (!empty($rss->image['url'])) { |
|
| 368 | + $this->_imageurl = (string) $rss->image['url']; |
|
| 369 | + } |
|
| 370 | + if (!empty($rss->channel['link'])) { |
|
| 371 | + $this->_link = (string) $rss->channel['link']; |
|
| 372 | + } |
|
| 373 | + if (!empty($rss->channel['title'])) { |
|
| 374 | + $this->_title = (string) $rss->channel['title']; |
|
| 375 | + } |
|
| 376 | + if (!empty($rss->channel['description'])) { |
|
| 377 | + $this->_description = (string) $rss->channel['description']; |
|
| 378 | + } |
|
| 339 | 379 | } |
| 340 | 380 | |
| 341 | - if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item; // With simplexml |
|
| 342 | - else $items=$rss->items; // With xmlparse |
|
| 381 | + if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) { |
|
| 382 | + $items=$rss->channel->item; |
|
| 383 | + } |
|
| 384 | + // With simplexml |
|
| 385 | + else { |
|
| 386 | + $items=$rss->items; |
|
| 387 | + } |
|
| 388 | + // With xmlparse |
|
| 343 | 389 | //var_dump($items);exit; |
| 344 | - } |
|
| 345 | - else if ($rss->_format == 'atom') |
|
| 390 | + } else if ($rss->_format == 'atom') |
|
| 346 | 391 | { |
| 347 | 392 | //var_dump($rss); |
| 348 | 393 | if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
| 349 | 394 | { |
| 350 | - if (!empty($rss->generator)) $this->_generator = (string) $rss->generator; |
|
| 351 | - if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified; |
|
| 352 | - if (!empty($rss->link->href)) $this->_link = (string) $rss->link->href; |
|
| 353 | - if (!empty($rss->title)) $this->_title = (string) $rss->title; |
|
| 354 | - if (!empty($rss->description)) $this->_description = (string) $rss->description; |
|
| 355 | - } |
|
| 356 | - else |
|
| 395 | + if (!empty($rss->generator)) { |
|
| 396 | + $this->_generator = (string) $rss->generator; |
|
| 397 | + } |
|
| 398 | + if (!empty($rss->lastbuilddate)) { |
|
| 399 | + $this->_lastbuilddate = (string) $rss->modified; |
|
| 400 | + } |
|
| 401 | + if (!empty($rss->link->href)) { |
|
| 402 | + $this->_link = (string) $rss->link->href; |
|
| 403 | + } |
|
| 404 | + if (!empty($rss->title)) { |
|
| 405 | + $this->_title = (string) $rss->title; |
|
| 406 | + } |
|
| 407 | + if (!empty($rss->description)) { |
|
| 408 | + $this->_description = (string) $rss->description; |
|
| 409 | + } |
|
| 410 | + } else |
|
| 357 | 411 | { |
| 358 | 412 | //if (!empty($rss->channel['rss_language'])) $this->_language = (string) $rss->channel['rss_language']; |
| 359 | - if (!empty($rss->channel['generator'])) $this->_generator = (string) $rss->channel['generator']; |
|
| 413 | + if (!empty($rss->channel['generator'])) { |
|
| 414 | + $this->_generator = (string) $rss->channel['generator']; |
|
| 415 | + } |
|
| 360 | 416 | //if (!empty($rss->channel['rss_copyright'])) $this->_copyright = (string) $rss->channel['rss_copyright']; |
| 361 | - if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified']; |
|
| 417 | + if (!empty($rss->channel['modified'])) { |
|
| 418 | + $this->_lastbuilddate = (string) $rss->channel['modified']; |
|
| 419 | + } |
|
| 362 | 420 | //if (!empty($rss->image['rss_url'])) $this->_imageurl = (string) $rss->image['rss_url']; |
| 363 | - if (!empty($rss->channel['link'])) $this->_link = (string) $rss->channel['link']; |
|
| 364 | - if (!empty($rss->channel['title'])) $this->_title = (string) $rss->channel['title']; |
|
| 421 | + if (!empty($rss->channel['link'])) { |
|
| 422 | + $this->_link = (string) $rss->channel['link']; |
|
| 423 | + } |
|
| 424 | + if (!empty($rss->channel['title'])) { |
|
| 425 | + $this->_title = (string) $rss->channel['title']; |
|
| 426 | + } |
|
| 365 | 427 | //if (!empty($rss->channel['rss_description'])) $this->_description = (string) $rss->channel['rss_description']; |
| 366 | 428 | } |
| 367 | 429 | if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) { |
| 368 | 430 | $tmprss=xml2php($rss); $items=$tmprss['entry']; |
| 369 | 431 | } // With simplexml |
| 370 | - else $items=$rss->items; // With xmlparse |
|
| 432 | + else { |
|
| 433 | + $items=$rss->items; |
|
| 434 | + } |
|
| 435 | + // With xmlparse |
|
| 371 | 436 | //var_dump($items);exit; |
| 372 | 437 | } |
| 373 | 438 | |
@@ -389,8 +454,7 @@ discard block |
||
| 389 | 454 | $itemPubDate = (string) $item->pubDate; |
| 390 | 455 | $itemId = ''; |
| 391 | 456 | $itemAuthor = ''; |
| 392 | - } |
|
| 393 | - else |
|
| 457 | + } else |
|
| 394 | 458 | { |
| 395 | 459 | $itemLink = (string) $item['link']; |
| 396 | 460 | $itemTitle = (string) $item['title']; |
@@ -409,8 +473,7 @@ discard block |
||
| 409 | 473 | $itemCategory[] = (string) $cat; |
| 410 | 474 | } |
| 411 | 475 | } |
| 412 | - } |
|
| 413 | - else if ($rss->_format == 'atom') |
|
| 476 | + } else if ($rss->_format == 'atom') |
|
| 414 | 477 | { |
| 415 | 478 | if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) |
| 416 | 479 | { |
@@ -420,8 +483,7 @@ discard block |
||
| 420 | 483 | $itemPubDate = (string) $item['created']; |
| 421 | 484 | $itemId = (string) $item['id']; |
| 422 | 485 | $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']); |
| 423 | - } |
|
| 424 | - else |
|
| 486 | + } else |
|
| 425 | 487 | { |
| 426 | 488 | $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : ''); |
| 427 | 489 | $itemTitle = (string) $item['title']; |
@@ -430,8 +492,9 @@ discard block |
||
| 430 | 492 | $itemId = (string) $item['id']; |
| 431 | 493 | $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']); |
| 432 | 494 | } |
| 495 | + } else { |
|
| 496 | + print 'ErrorBadFeedFormat'; |
|
| 433 | 497 | } |
| 434 | - else print 'ErrorBadFeedFormat'; |
|
| 435 | 498 | |
| 436 | 499 | // Add record to result array |
| 437 | 500 | $this->_rssarray[$i] = array( |
@@ -446,13 +509,15 @@ discard block |
||
| 446 | 509 | |
| 447 | 510 | $i++; |
| 448 | 511 | |
| 449 | - if ($i > $maxNb) break; // We get all records we want |
|
| 512 | + if ($i > $maxNb) { |
|
| 513 | + break; |
|
| 514 | + } |
|
| 515 | + // We get all records we want |
|
| 450 | 516 | } |
| 451 | 517 | } |
| 452 | 518 | |
| 453 | 519 | return 1; |
| 454 | - } |
|
| 455 | - else |
|
| 520 | + } else |
|
| 456 | 521 | { |
| 457 | 522 | $this->error='ErrorFailedToLoadRSSFile'; |
| 458 | 523 | return -1; |
@@ -493,12 +558,10 @@ discard block |
||
| 493 | 558 | if ( $el == 'rdf' ) { |
| 494 | 559 | $this->_format = 'rss'; |
| 495 | 560 | $this->feed_version = '1.0'; |
| 496 | - } |
|
| 497 | - elseif ( $el == 'rss' ) { |
|
| 561 | + } elseif ( $el == 'rss' ) { |
|
| 498 | 562 | $this->_format = 'rss'; |
| 499 | 563 | $this->feed_version = $attrs['version']; |
| 500 | - } |
|
| 501 | - elseif ( $el == 'feed' ) { |
|
| 564 | + } elseif ( $el == 'feed' ) { |
|
| 502 | 565 | $this->_format = 'atom'; |
| 503 | 566 | $this->feed_version = $attrs['version']; |
| 504 | 567 | $this->inchannel = true; |
@@ -509,8 +572,7 @@ discard block |
||
| 509 | 572 | if ( $el == 'channel' ) |
| 510 | 573 | { |
| 511 | 574 | $this->inchannel = true; |
| 512 | - } |
|
| 513 | - elseif ($el == 'item' or $el == 'entry' ) |
|
| 575 | + } elseif ($el == 'item' or $el == 'entry' ) |
|
| 514 | 576 | { |
| 515 | 577 | $this->initem = true; |
| 516 | 578 | if ( isset($attrs['rdf:about']) ) { |
@@ -526,9 +588,7 @@ discard block |
||
| 526 | 588 | $el == 'textinput' ) |
| 527 | 589 | { |
| 528 | 590 | $this->intextinput = true; |
| 529 | - } |
|
| 530 | - |
|
| 531 | - elseif ( |
|
| 591 | + } elseif ( |
|
| 532 | 592 | $this->_format == 'rss' and |
| 533 | 593 | $this->current_namespace == '' and |
| 534 | 594 | $el == 'image' ) |
@@ -567,8 +627,7 @@ discard block |
||
| 567 | 627 | if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' ) |
| 568 | 628 | { |
| 569 | 629 | $link_el = 'link'; |
| 570 | - } |
|
| 571 | - else { |
|
| 630 | + } else { |
|
| 572 | 631 | $link_el = 'link_' . $attrs['rel']; |
| 573 | 632 | } |
| 574 | 633 | |
@@ -595,8 +654,7 @@ discard block |
||
| 595 | 654 | if ($this->_format == 'atom' and $this->incontent) |
| 596 | 655 | { |
| 597 | 656 | $this->append_content($text); |
| 598 | - } |
|
| 599 | - else |
|
| 657 | + } else |
|
| 600 | 658 | { |
| 601 | 659 | $current_el = join('_', array_reverse($this->stack)); |
| 602 | 660 | $this->append($current_el, $text); |
@@ -621,37 +679,30 @@ discard block |
||
| 621 | 679 | $this->items[] = $this->current_item; |
| 622 | 680 | $this->current_item = array(); |
| 623 | 681 | $this->initem = false; |
| 624 | - } |
|
| 625 | - elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' ) |
|
| 682 | + } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' ) |
|
| 626 | 683 | { |
| 627 | 684 | $this->intextinput = false; |
| 628 | - } |
|
| 629 | - elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' ) |
|
| 685 | + } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' ) |
|
| 630 | 686 | { |
| 631 | 687 | $this->inimage = false; |
| 632 | - } |
|
| 633 | - elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 688 | + } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) ) |
|
| 634 | 689 | { |
| 635 | 690 | $this->incontent = false; |
| 636 | - } |
|
| 637 | - elseif ($el == 'channel' or $el == 'feed' ) |
|
| 691 | + } elseif ($el == 'channel' or $el == 'feed' ) |
|
| 638 | 692 | { |
| 639 | 693 | $this->inchannel = false; |
| 640 | - } |
|
| 641 | - elseif ($this->_format == 'atom' and $this->incontent ) { |
|
| 694 | + } elseif ($this->_format == 'atom' and $this->incontent ) { |
|
| 642 | 695 | // balance tags properly |
| 643 | 696 | // note: i don't think this is actually neccessary |
| 644 | 697 | if ( $this->stack[0] == $el ) |
| 645 | 698 | { |
| 646 | 699 | $this->append_content("</$el>"); |
| 647 | - } |
|
| 648 | - else { |
|
| 700 | + } else { |
|
| 649 | 701 | $this->append_content("<$el />"); |
| 650 | 702 | } |
| 651 | 703 | |
| 652 | 704 | array_shift($this->stack); |
| 653 | - } |
|
| 654 | - else { |
|
| 705 | + } else { |
|
| 655 | 706 | array_shift($this->stack); |
| 656 | 707 | } |
| 657 | 708 | |
@@ -686,8 +737,7 @@ discard block |
||
| 686 | 737 | // phpcs:enable |
| 687 | 738 | if ( $this->initem ) { |
| 688 | 739 | $this->concat($this->current_item[ $this->incontent ], $text); |
| 689 | - } |
|
| 690 | - elseif ( $this->inchannel ) { |
|
| 740 | + } elseif ( $this->inchannel ) { |
|
| 691 | 741 | $this->concat($this->channel[ $this->incontent ], $text); |
| 692 | 742 | } |
| 693 | 743 | } |
@@ -708,28 +758,21 @@ discard block |
||
| 708 | 758 | { |
| 709 | 759 | if ( $this->initem ) { |
| 710 | 760 | $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text); |
| 711 | - } |
|
| 712 | - elseif ($this->inchannel) { |
|
| 761 | + } elseif ($this->inchannel) { |
|
| 713 | 762 | $this->concat($this->channel[ $this->current_namespace][ $el ], $text); |
| 714 | - } |
|
| 715 | - elseif ($this->intextinput) { |
|
| 763 | + } elseif ($this->intextinput) { |
|
| 716 | 764 | $this->concat($this->textinput[ $this->current_namespace][ $el ], $text); |
| 717 | - } |
|
| 718 | - elseif ($this->inimage) { |
|
| 765 | + } elseif ($this->inimage) { |
|
| 719 | 766 | $this->concat($this->image[ $this->current_namespace ][ $el ], $text); |
| 720 | 767 | } |
| 721 | - } |
|
| 722 | - else { |
|
| 768 | + } else { |
|
| 723 | 769 | if ( $this->initem ) { |
| 724 | 770 | $this->concat($this->current_item[ $el ], $text); |
| 725 | - } |
|
| 726 | - elseif ($this->intextinput) { |
|
| 771 | + } elseif ($this->intextinput) { |
|
| 727 | 772 | $this->concat($this->textinput[ $el ], $text); |
| 728 | - } |
|
| 729 | - elseif ($this->inimage) { |
|
| 773 | + } elseif ($this->inimage) { |
|
| 730 | 774 | $this->concat($this->image[ $el ], $text); |
| 731 | - } |
|
| 732 | - elseif ($this->inchannel) { |
|
| 775 | + } elseif ($this->inchannel) { |
|
| 733 | 776 | $this->concat($this->channel[ $el ], $text); |
| 734 | 777 | } |
| 735 | 778 | } |
@@ -767,13 +810,11 @@ discard block |
||
| 767 | 810 | $array[$key][] = $tmp; |
| 768 | 811 | $array[$key][] = $child; |
| 769 | 812 | $tab = true; |
| 770 | - } |
|
| 771 | - elseif($tab === true) |
|
| 813 | + } elseif($tab === true) |
|
| 772 | 814 | { |
| 773 | 815 | //Add an element in an existing array |
| 774 | 816 | $array[$key][] = $child; |
| 775 | - } |
|
| 776 | - else |
|
| 817 | + } else |
|
| 777 | 818 | { |
| 778 | 819 | //Add a simple element |
| 779 | 820 | $array[$key] = $child; |
@@ -120,7 +120,9 @@ |
||
| 120 | 120 | $nb=0; |
| 121 | 121 | foreach($this->liste as $val) |
| 122 | 122 | { |
| 123 | - if (! empty($val['enabled'])) $nb++; |
|
| 123 | + if (! empty($val['enabled'])) { |
|
| 124 | + $nb++; |
|
| 125 | + } |
|
| 124 | 126 | } |
| 125 | 127 | return $nb; |
| 126 | 128 | } |
@@ -125,7 +125,9 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $this->sendcontext = $sendcontext; |
| 127 | 127 | |
| 128 | - if (empty($replyto)) $replyto=$from; |
|
| 128 | + if (empty($replyto)) { |
|
| 129 | + $replyto=$from; |
|
| 130 | + } |
|
| 129 | 131 | |
| 130 | 132 | // Define this->sendmode |
| 131 | 133 | $this->sendmode = ''; |
@@ -133,8 +135,12 @@ discard block |
||
| 133 | 135 | { |
| 134 | 136 | $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING; |
| 135 | 137 | } |
| 136 | - if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE; |
|
| 137 | - if (empty($this->sendmode)) $this->sendmode='mail'; |
|
| 138 | + if (empty($this->sendmode)) { |
|
| 139 | + $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE; |
|
| 140 | + } |
|
| 141 | + if (empty($this->sendmode)) { |
|
| 142 | + $this->sendmode='mail'; |
|
| 143 | + } |
|
| 138 | 144 | |
| 139 | 145 | // We define end of line (RFC 821). |
| 140 | 146 | $this->eol="\r\n"; |
@@ -175,9 +181,10 @@ discard block |
||
| 175 | 181 | if ($msgishtml == -1) |
| 176 | 182 | { |
| 177 | 183 | $this->msgishtml = 0; |
| 178 | - if (dol_textishtml($msg)) $this->msgishtml = 1; |
|
| 179 | - } |
|
| 180 | - else |
|
| 184 | + if (dol_textishtml($msg)) { |
|
| 185 | + $this->msgishtml = 1; |
|
| 186 | + } |
|
| 187 | + } else |
|
| 181 | 188 | { |
| 182 | 189 | $this->msgishtml = $msgishtml; |
| 183 | 190 | } |
@@ -192,7 +199,10 @@ discard block |
||
| 192 | 199 | // Replace relative /viewimage to absolute path |
| 193 | 200 | $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep); |
| 194 | 201 | |
| 195 | - if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html. |
|
| 202 | + if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) { |
|
| 203 | + $this->msgishtml=1; |
|
| 204 | + } |
|
| 205 | + // To force to send everything with content type html. |
|
| 196 | 206 | |
| 197 | 207 | // Detect images |
| 198 | 208 | if ($this->msgishtml) |
@@ -232,7 +242,9 @@ discard block |
||
| 232 | 242 | } |
| 233 | 243 | |
| 234 | 244 | // Add autocopy to (Note: Adding bcc for specific modules are also done from pages) |
| 235 | - if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 245 | + if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) { |
|
| 246 | + $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO; |
|
| 247 | + } |
|
| 236 | 248 | |
| 237 | 249 | // Action according to choosed sending method |
| 238 | 250 | if ($this->sendmode == 'mail') |
@@ -257,7 +269,10 @@ discard block |
||
| 257 | 269 | $this->trackid = $trackid; |
| 258 | 270 | |
| 259 | 271 | $smtp_headers = $this->write_smtpheaders(); |
| 260 | - if (! empty($moreinheader)) $smtp_headers.=$moreinheader; // $moreinheader contains the \r\n |
|
| 272 | + if (! empty($moreinheader)) { |
|
| 273 | + $smtp_headers.=$moreinheader; |
|
| 274 | + } |
|
| 275 | + // $moreinheader contains the \r\n |
|
| 261 | 276 | |
| 262 | 277 | // Define mime_headers |
| 263 | 278 | $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list); |
@@ -293,8 +308,7 @@ discard block |
||
| 293 | 308 | $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol; |
| 294 | 309 | $this->message.= $text_body . $files_encoded; |
| 295 | 310 | $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol; |
| 296 | - } |
|
| 297 | - else if ($this->sendmode == 'smtps') |
|
| 311 | + } else if ($this->sendmode == 'smtps') |
|
| 298 | 312 | { |
| 299 | 313 | // Use SMTPS library |
| 300 | 314 | // ------------------------------------------ |
@@ -309,7 +323,9 @@ discard block |
||
| 309 | 323 | $smtps->setTrackId($trackid); |
| 310 | 324 | $smtps->setReplyTo($this->getValidAddress($replyto,0,1)); |
| 311 | 325 | |
| 312 | - if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader); |
|
| 326 | + if (! empty($moreinheader)) { |
|
| 327 | + $smtps->setMoreInHeader($moreinheader); |
|
| 328 | + } |
|
| 313 | 329 | |
| 314 | 330 | if (! empty($this->html)) |
| 315 | 331 | { |
@@ -322,8 +338,11 @@ discard block |
||
| 322 | 338 | $msg = $this->checkIfHTML($msg); |
| 323 | 339 | } |
| 324 | 340 | |
| 325 | - if ($this->msgishtml) $smtps->setBodyContent($msg,'html'); |
|
| 326 | - else $smtps->setBodyContent($msg,'plain'); |
|
| 341 | + if ($this->msgishtml) { |
|
| 342 | + $smtps->setBodyContent($msg,'html'); |
|
| 343 | + } else { |
|
| 344 | + $smtps->setBodyContent($msg,'plain'); |
|
| 345 | + } |
|
| 327 | 346 | |
| 328 | 347 | if ($this->atleastoneimage) |
| 329 | 348 | { |
@@ -348,8 +367,7 @@ discard block |
||
| 348 | 367 | $smtps->setDeliveryReceipt($deliveryreceipt); |
| 349 | 368 | |
| 350 | 369 | $this->smtps=$smtps; |
| 351 | - } |
|
| 352 | - else if ($this->sendmode == 'swiftmailer') |
|
| 370 | + } else if ($this->sendmode == 'swiftmailer') |
|
| 353 | 371 | { |
| 354 | 372 | // Use Swift Mailer library |
| 355 | 373 | // ------------------------------------------ |
@@ -474,12 +492,17 @@ discard block |
||
| 474 | 492 | } |
| 475 | 493 | } |
| 476 | 494 | |
| 477 | - if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 478 | - if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 495 | + if (! empty($addr_cc)) { |
|
| 496 | + $this->message->setCc($this->getArrayAddress($addr_cc)); |
|
| 497 | + } |
|
| 498 | + if (! empty($addr_bcc)) { |
|
| 499 | + $this->message->setBcc($this->getArrayAddress($addr_bcc)); |
|
| 500 | + } |
|
| 479 | 501 | //if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to); |
| 480 | - if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from)); |
|
| 481 | - } |
|
| 482 | - else |
|
| 502 | + if (isset($deliveryreceipt) && $deliveryreceipt == 1) { |
|
| 503 | + $this->message->setReadReceiptTo($this->getArrayAddress($from)); |
|
| 504 | + } |
|
| 505 | + } else |
|
| 483 | 506 | { |
| 484 | 507 | // Send mail method not correctly defined |
| 485 | 508 | // -------------------------------------- |
@@ -517,13 +540,17 @@ discard block |
||
| 517 | 540 | |
| 518 | 541 | return $reshook; |
| 519 | 542 | } |
| 520 | - if ($reshook == 1) // Hook replace standard code |
|
| 543 | + if ($reshook == 1) { |
|
| 544 | + // Hook replace standard code |
|
| 521 | 545 | { |
| 522 | 546 | return true; |
| 523 | 547 | } |
| 548 | + } |
|
| 524 | 549 | |
| 525 | 550 | // Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL |
| 526 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10; |
|
| 551 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) { |
|
| 552 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10; |
|
| 553 | + } |
|
| 527 | 554 | $tmparray1 = explode(',', $this->addr_to); |
| 528 | 555 | if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL) |
| 529 | 556 | { |
@@ -531,7 +558,9 @@ discard block |
||
| 531 | 558 | dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
| 532 | 559 | return false; |
| 533 | 560 | } |
| 534 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10; |
|
| 561 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) { |
|
| 562 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10; |
|
| 563 | + } |
|
| 535 | 564 | $tmparray2 = explode(',', $this->addr_cc); |
| 536 | 565 | if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL) |
| 537 | 566 | { |
@@ -539,7 +568,9 @@ discard block |
||
| 539 | 568 | dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
| 540 | 569 | return false; |
| 541 | 570 | } |
| 542 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10; |
|
| 571 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) { |
|
| 572 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10; |
|
| 573 | + } |
|
| 543 | 574 | $tmparray3 = explode(',', $this->addr_bcc); |
| 544 | 575 | if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL) |
| 545 | 576 | { |
@@ -547,7 +578,9 @@ discard block |
||
| 547 | 578 | dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING); |
| 548 | 579 | return false; |
| 549 | 580 | } |
| 550 | - if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10; |
|
| 581 | + if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) { |
|
| 582 | + $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10; |
|
| 583 | + } |
|
| 551 | 584 | if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL) |
| 552 | 585 | { |
| 553 | 586 | $this->error = 'Too much recipients in to:, cc:, bcc:'; |
@@ -590,13 +623,19 @@ discard block |
||
| 590 | 623 | // If Windows, sendmail_from must be defined |
| 591 | 624 | if (isset($_SERVER["WINDIR"])) |
| 592 | 625 | { |
| 593 | - if (empty($this->addr_from)) $this->addr_from = '[email protected]'; |
|
| 626 | + if (empty($this->addr_from)) { |
|
| 627 | + $this->addr_from = '[email protected]'; |
|
| 628 | + } |
|
| 594 | 629 | @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2)); |
| 595 | 630 | } |
| 596 | 631 | |
| 597 | 632 | // Force parameters |
| 598 | - if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver); |
|
| 599 | - if (! empty($conf->global->$keyforsmtpport)) ini_set('smtp_port',$conf->global->$keyforsmtpport); |
|
| 633 | + if (! empty($conf->global->$keyforsmtpserver)) { |
|
| 634 | + ini_set('SMTP',$conf->global->$keyforsmtpserver); |
|
| 635 | + } |
|
| 636 | + if (! empty($conf->global->$keyforsmtpport)) { |
|
| 637 | + ini_set('smtp_port',$conf->global->$keyforsmtpport); |
|
| 638 | + } |
|
| 600 | 639 | |
| 601 | 640 | $res=true; |
| 602 | 641 | if ($res && ! $this->subject) |
@@ -624,29 +663,43 @@ discard block |
||
| 624 | 663 | // Having this variable not defined may create problems with some other sendmail (option -f required) |
| 625 | 664 | $additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') ); |
| 626 | 665 | } |
| 627 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender |
|
| 666 | + if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) { |
|
| 667 | + // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender |
|
| 628 | 668 | { |
| 629 | 669 | $additionnalparam .= ($additionnalparam?' ':'').'-ba'; |
| 630 | 670 | } |
| 671 | + } |
|
| 631 | 672 | |
| 632 | - if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params |
|
| 673 | + if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) { |
|
| 674 | + $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; |
|
| 675 | + } |
|
| 676 | + // Use -U to add additionnal params |
|
| 633 | 677 | |
| 634 | 678 | dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG); |
| 635 | 679 | |
| 636 | 680 | $this->message=stripslashes($this->message); |
| 637 | 681 | |
| 638 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 682 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 683 | + $this->dump_mail(); |
|
| 684 | + } |
|
| 639 | 685 | |
| 640 | - if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 641 | - else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers); |
|
| 686 | + if (! empty($additionnalparam)) { |
|
| 687 | + $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam); |
|
| 688 | + } else { |
|
| 689 | + $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers); |
|
| 690 | + } |
|
| 642 | 691 | |
| 643 | 692 | if (! $res) |
| 644 | 693 | { |
| 645 | 694 | $langs->load("errors"); |
| 646 | 695 | $this->error="Failed to send mail with php mail"; |
| 647 | 696 | $linuxlike=1; |
| 648 | - if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; |
|
| 649 | - if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; |
|
| 697 | + if (preg_match('/^win/i',PHP_OS)) { |
|
| 698 | + $linuxlike=0; |
|
| 699 | + } |
|
| 700 | + if (preg_match('/^mac/i',PHP_OS)) { |
|
| 701 | + $linuxlike=0; |
|
| 702 | + } |
|
| 650 | 703 | if (! $linuxlike) |
| 651 | 704 | { |
| 652 | 705 | $this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems |
@@ -654,8 +707,7 @@ discard block |
||
| 654 | 707 | $this->error.=".<br>"; |
| 655 | 708 | $this->error.=$langs->trans("ErrorPhpMailDelivery"); |
| 656 | 709 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 657 | - } |
|
| 658 | - else |
|
| 710 | + } else |
|
| 659 | 711 | { |
| 660 | 712 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 661 | 713 | } |
@@ -667,10 +719,13 @@ discard block |
||
| 667 | 719 | } |
| 668 | 720 | |
| 669 | 721 | // Restore parameters |
| 670 | - if (! empty($conf->global->$keyforsmtpserver)) ini_restore('SMTP'); |
|
| 671 | - if (! empty($conf->global->$keyforsmtpport)) ini_restore('smtp_port'); |
|
| 672 | - } |
|
| 673 | - else if ($this->sendmode == 'smtps') |
|
| 722 | + if (! empty($conf->global->$keyforsmtpserver)) { |
|
| 723 | + ini_restore('SMTP'); |
|
| 724 | + } |
|
| 725 | + if (! empty($conf->global->$keyforsmtpport)) { |
|
| 726 | + ini_restore('smtp_port'); |
|
| 727 | + } |
|
| 728 | + } else if ($this->sendmode == 'smtps') |
|
| 674 | 729 | { |
| 675 | 730 | if (! is_object($this->smtps)) |
| 676 | 731 | { |
@@ -684,14 +739,22 @@ discard block |
||
| 684 | 739 | $this->smtps->setTransportType(0); // Only this method is coded in SMTPs library |
| 685 | 740 | |
| 686 | 741 | // Clean parameters |
| 687 | - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 688 | - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 742 | + if (empty($conf->global->$keyforsmtpserver)) { |
|
| 743 | + $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 744 | + } |
|
| 745 | + if (empty($conf->global->$keyforsmtpport)) { |
|
| 746 | + $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 747 | + } |
|
| 689 | 748 | |
| 690 | 749 | // If we use SSL/TLS |
| 691 | 750 | $server=$conf->global->$keyforsmtpserver; |
| 692 | 751 | $secure=''; |
| 693 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl'; |
|
| 694 | - if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls'; |
|
| 752 | + if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) { |
|
| 753 | + $secure='ssl'; |
|
| 754 | + } |
|
| 755 | + if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) { |
|
| 756 | + $secure='tls'; |
|
| 757 | + } |
|
| 695 | 758 | $server=($secure?$secure.'://':'').$server; |
| 696 | 759 | |
| 697 | 760 | $port=$conf->global->$keyforsmtpport; |
@@ -729,47 +792,63 @@ discard block |
||
| 729 | 792 | |
| 730 | 793 | if ($res) |
| 731 | 794 | { |
| 732 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true); |
|
| 795 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 796 | + $this->smtps->setDebug(true); |
|
| 797 | + } |
|
| 733 | 798 | |
| 734 | 799 | $result=$this->smtps->sendMsg(); |
| 735 | 800 | //print $result; |
| 736 | 801 | |
| 737 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 802 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 803 | + $this->dump_mail(); |
|
| 804 | + } |
|
| 738 | 805 | |
| 739 | 806 | $result=$this->smtps->getErrors(); |
| 740 | 807 | if (empty($this->error) && empty($result)) |
| 741 | 808 | { |
| 742 | 809 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 743 | 810 | $res=true; |
| 744 | - } |
|
| 745 | - else |
|
| 811 | + } else |
|
| 746 | 812 | { |
| 747 | - if (empty($this->error)) $this->error=$result; |
|
| 813 | + if (empty($this->error)) { |
|
| 814 | + $this->error=$result; |
|
| 815 | + } |
|
| 748 | 816 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 749 | 817 | $res=false; |
| 750 | 818 | } |
| 751 | 819 | } |
| 752 | - } |
|
| 753 | - else if ($this->sendmode == 'swiftmailer') |
|
| 820 | + } else if ($this->sendmode == 'swiftmailer') |
|
| 754 | 821 | { |
| 755 | 822 | // Use Swift Mailer library |
| 756 | 823 | // ------------------------------------------ |
| 757 | 824 | require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php'; |
| 758 | 825 | |
| 759 | 826 | // Clean parameters |
| 760 | - if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 761 | - if (empty($conf->global->$keyforsmtpport)) $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 827 | + if (empty($conf->global->$keyforsmtpserver)) { |
|
| 828 | + $conf->global->$keyforsmtpserver=ini_get('SMTP'); |
|
| 829 | + } |
|
| 830 | + if (empty($conf->global->$keyforsmtpport)) { |
|
| 831 | + $conf->global->$keyforsmtpport=ini_get('smtp_port'); |
|
| 832 | + } |
|
| 762 | 833 | |
| 763 | 834 | // If we use SSL/TLS |
| 764 | 835 | $server = $conf->global->$keyforsmtpserver; |
| 765 | 836 | $secure = ''; |
| 766 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl'; |
|
| 767 | - if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls'; |
|
| 837 | + if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) { |
|
| 838 | + $secure='ssl'; |
|
| 839 | + } |
|
| 840 | + if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) { |
|
| 841 | + $secure='tls'; |
|
| 842 | + } |
|
| 768 | 843 | |
| 769 | 844 | $this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure); |
| 770 | 845 | |
| 771 | - if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 772 | - if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 846 | + if (! empty($conf->global->$keyforsmtpid)) { |
|
| 847 | + $this->transport->setUsername($conf->global->$keyforsmtpid); |
|
| 848 | + } |
|
| 849 | + if (! empty($conf->global->$keyforsmtppw)) { |
|
| 850 | + $this->transport->setPassword($conf->global->$keyforsmtppw); |
|
| 851 | + } |
|
| 773 | 852 | //$smtps->_msgReplyTo = '[email protected]'; |
| 774 | 853 | |
| 775 | 854 | // Create the Mailer using your created Transport |
@@ -797,19 +876,19 @@ discard block |
||
| 797 | 876 | } catch (Exception $e) { |
| 798 | 877 | $this->error = $e->getMessage(); |
| 799 | 878 | } |
| 800 | - if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail(); |
|
| 879 | + if (! empty($conf->global->MAIN_MAIL_DEBUG)) { |
|
| 880 | + $this->dump_mail(); |
|
| 881 | + } |
|
| 801 | 882 | |
| 802 | 883 | $res = true; |
| 803 | 884 | if (! empty($this->error) || ! $result) { |
| 804 | 885 | dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR); |
| 805 | 886 | $res=false; |
| 806 | - } |
|
| 807 | - else |
|
| 887 | + } else |
|
| 808 | 888 | { |
| 809 | 889 | dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG); |
| 810 | 890 | } |
| 811 | - } |
|
| 812 | - else |
|
| 891 | + } else |
|
| 813 | 892 | { |
| 814 | 893 | // Send mail method not correctly defined |
| 815 | 894 | // -------------------------------------- |
@@ -826,8 +905,7 @@ discard block |
||
| 826 | 905 | |
| 827 | 906 | return $reshook; |
| 828 | 907 | } |
| 829 | - } |
|
| 830 | - else |
|
| 908 | + } else |
|
| 831 | 909 | { |
| 832 | 910 | $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS'; |
| 833 | 911 | dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING); |
@@ -867,8 +945,7 @@ discard block |
||
| 867 | 945 | $contents = file_get_contents($newsourcefile); // Need PHP 4.3 |
| 868 | 946 | $encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047 |
| 869 | 947 | return $encoded; |
| 870 | - } |
|
| 871 | - else |
|
| 948 | + } else |
|
| 872 | 949 | { |
| 873 | 950 | $this->error="Error: Can't read file '".$sourcefile."' into _encode_file"; |
| 874 | 951 | dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR); |
@@ -890,9 +967,11 @@ discard block |
||
| 890 | 967 | // phpcs:enable |
| 891 | 968 | global $conf,$dolibarr_main_data_root; |
| 892 | 969 | |
| 893 | - if (@is_writeable($dolibarr_main_data_root)) // Avoid fatal error on fopen with open_basedir |
|
| 970 | + if (@is_writeable($dolibarr_main_data_root)) { |
|
| 971 | + // Avoid fatal error on fopen with open_basedir |
|
| 894 | 972 | { |
| 895 | 973 | $outputfile=$dolibarr_main_data_root."/dolibarr_mail.log"; |
| 974 | + } |
|
| 896 | 975 | $fp = fopen($outputfile,"w"); |
| 897 | 976 | |
| 898 | 977 | if ($this->sendmode == 'mail') |
@@ -900,19 +979,18 @@ discard block |
||
| 900 | 979 | fputs($fp, $this->headers); |
| 901 | 980 | fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log |
| 902 | 981 | fputs($fp, $this->message); |
| 903 | - } |
|
| 904 | - elseif ($this->sendmode == 'smtps') |
|
| 982 | + } elseif ($this->sendmode == 'smtps') |
|
| 905 | 983 | { |
| 906 | 984 | fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on |
| 907 | - } |
|
| 908 | - elseif ($this->sendmode == 'swiftmailer') |
|
| 985 | + } elseif ($this->sendmode == 'swiftmailer') |
|
| 909 | 986 | { |
| 910 | 987 | fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on |
| 911 | 988 | } |
| 912 | 989 | |
| 913 | 990 | fclose($fp); |
| 914 | - if (! empty($conf->global->MAIN_UMASK)) |
|
| 915 | - @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 991 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
| 992 | + @chmod($outputfile, octdec($conf->global->MAIN_UMASK)); |
|
| 993 | + } |
|
| 916 | 994 | } |
| 917 | 995 | } |
| 918 | 996 | |
@@ -928,14 +1006,17 @@ discard block |
||
| 928 | 1006 | if (!preg_match('/^[\s\t]*<html/i',$msg)) |
| 929 | 1007 | { |
| 930 | 1008 | $out = "<html><head><title></title>"; |
| 931 | - if (!empty($this->styleCSS)) $out.= $this->styleCSS; |
|
| 1009 | + if (!empty($this->styleCSS)) { |
|
| 1010 | + $out.= $this->styleCSS; |
|
| 1011 | + } |
|
| 932 | 1012 | $out.= "</head><body"; |
| 933 | - if (!empty($this->bodyCSS)) $out.= $this->bodyCSS; |
|
| 1013 | + if (!empty($this->bodyCSS)) { |
|
| 1014 | + $out.= $this->bodyCSS; |
|
| 1015 | + } |
|
| 934 | 1016 | $out.= ">"; |
| 935 | 1017 | $out.= $msg; |
| 936 | 1018 | $out.= "</body></html>"; |
| 937 | - } |
|
| 938 | - else |
|
| 1019 | + } else |
|
| 939 | 1020 | { |
| 940 | 1021 | $out = $msg; |
| 941 | 1022 | } |
@@ -995,15 +1076,26 @@ discard block |
||
| 995 | 1076 | } |
| 996 | 1077 | // Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that. |
| 997 | 1078 | $out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2; |
| 998 | - if (isset($this->reply_to) && $this->reply_to) $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2; |
|
| 999 | - if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2; |
|
| 1079 | + if (isset($this->reply_to) && $this->reply_to) { |
|
| 1080 | + $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2; |
|
| 1081 | + } |
|
| 1082 | + if (isset($this->errors_to) && $this->errors_to) { |
|
| 1083 | + $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2; |
|
| 1084 | + } |
|
| 1000 | 1085 | |
| 1001 | 1086 | // Receiver |
| 1002 | - if (isset($this->addr_cc) && $this->addr_cc) $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2; |
|
| 1003 | - if (isset($this->addr_bcc) && $this->addr_bcc) $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? |
|
| 1087 | + if (isset($this->addr_cc) && $this->addr_cc) { |
|
| 1088 | + $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2; |
|
| 1089 | + } |
|
| 1090 | + if (isset($this->addr_bcc) && $this->addr_bcc) { |
|
| 1091 | + $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2; |
|
| 1092 | + } |
|
| 1093 | + // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ? |
|
| 1004 | 1094 | |
| 1005 | 1095 | // Delivery receipt |
| 1006 | - if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2; |
|
| 1096 | + if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) { |
|
| 1097 | + $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2; |
|
| 1098 | + } |
|
| 1007 | 1099 | |
| 1008 | 1100 | //$out.= "X-Priority: 3".$this->eol2; |
| 1009 | 1101 | |
@@ -1016,13 +1108,14 @@ discard block |
||
| 1016 | 1108 | $out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; // Uppercase seems replaced by phpmail |
| 1017 | 1109 | $out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2; |
| 1018 | 1110 | $out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2; |
| 1019 | - } |
|
| 1020 | - else |
|
| 1111 | + } else |
|
| 1021 | 1112 | { |
| 1022 | 1113 | $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2; |
| 1023 | 1114 | } |
| 1024 | 1115 | |
| 1025 | - if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2; |
|
| 1116 | + if (! empty($_SERVER['REMOTE_ADDR'])) { |
|
| 1117 | + $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2; |
|
| 1118 | + } |
|
| 1026 | 1119 | $out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2; |
| 1027 | 1120 | $out.= "Mime-Version: 1.0".$this->eol2; |
| 1028 | 1121 | |
@@ -1057,7 +1150,9 @@ discard block |
||
| 1057 | 1150 | { |
| 1058 | 1151 | if ($filename_list[$i]) |
| 1059 | 1152 | { |
| 1060 | - if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1153 | + if ($mimefilename_list[$i]) { |
|
| 1154 | + $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1155 | + } |
|
| 1061 | 1156 | $out.= "X-attachments: $filename_list[$i]".$this->eol2; |
| 1062 | 1157 | } |
| 1063 | 1158 | } |
@@ -1127,9 +1222,11 @@ discard block |
||
| 1127 | 1222 | $out.= "--" . $this->related_boundary . $this->eol; |
| 1128 | 1223 | } |
| 1129 | 1224 | |
| 1130 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part before html part |
|
| 1225 | + if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
| 1226 | + // Add plain text message part before html part |
|
| 1131 | 1227 | { |
| 1132 | 1228 | $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol; |
| 1229 | + } |
|
| 1133 | 1230 | $out.= $this->eol; |
| 1134 | 1231 | $out.= "--" . $this->alternative_boundary . $this->eol; |
| 1135 | 1232 | $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
@@ -1142,12 +1239,13 @@ discard block |
||
| 1142 | 1239 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; // TODO Use base64 |
| 1143 | 1240 | $out.= $this->eol.$strContent.$this->eol; |
| 1144 | 1241 | |
| 1145 | - if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) // Add plain text message part after html part |
|
| 1242 | + if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) { |
|
| 1243 | + // Add plain text message part after html part |
|
| 1146 | 1244 | { |
| 1147 | 1245 | $out.= "--" . $this->alternative_boundary . "--". $this->eol; |
| 1148 | 1246 | } |
| 1149 | - } |
|
| 1150 | - else |
|
| 1247 | + } |
|
| 1248 | + } else |
|
| 1151 | 1249 | { |
| 1152 | 1250 | $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol; |
| 1153 | 1251 | //$out.= "Content-Transfer-Encoding: 7bit".$this->eol; |
@@ -1192,7 +1290,9 @@ discard block |
||
| 1192 | 1290 | $encoded = $this->_encode_file($filename_list[$i]); |
| 1193 | 1291 | if ($encoded >= 0) |
| 1194 | 1292 | { |
| 1195 | - if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1293 | + if ($mimefilename_list[$i]) { |
|
| 1294 | + $filename_list[$i] = $mimefilename_list[$i]; |
|
| 1295 | + } |
|
| 1196 | 1296 | if (! $mimetype_list[$i]) { |
| 1197 | 1297 | $mimetype_list[$i] = "application/octet-stream"; |
| 1198 | 1298 | } |
@@ -1206,8 +1306,7 @@ discard block |
||
| 1206 | 1306 | $out.= $encoded; |
| 1207 | 1307 | $out.= $this->eol; |
| 1208 | 1308 | //$out.= $this->eol; |
| 1209 | - } |
|
| 1210 | - else |
|
| 1309 | + } else |
|
| 1211 | 1310 | { |
| 1212 | 1311 | return $encoded; |
| 1213 | 1312 | } |
@@ -1286,7 +1385,9 @@ discard block |
||
| 1286 | 1385 | } |
| 1287 | 1386 | |
| 1288 | 1387 | // If we use SSL/TLS |
| 1289 | - if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host; |
|
| 1388 | + if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) { |
|
| 1389 | + $host='ssl://'.$host; |
|
| 1390 | + } |
|
| 1290 | 1391 | // tls smtp start with no encryption |
| 1291 | 1392 | //if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host; |
| 1292 | 1393 | |
@@ -1298,17 +1399,20 @@ discard block |
||
| 1298 | 1399 | $errno, // actual system level error |
| 1299 | 1400 | $errstr, // and any text that goes with the error |
| 1300 | 1401 | $timeout |
| 1301 | - )) // timeout for reading/writing data over the socket |
|
| 1402 | + )) { |
|
| 1403 | + // timeout for reading/writing data over the socket |
|
| 1302 | 1404 | { |
| 1303 | 1405 | // Windows still does not have support for this timeout function |
| 1304 | 1406 | if (function_exists('stream_set_timeout')) stream_set_timeout($socket, $timeout, 0); |
| 1407 | + } |
|
| 1305 | 1408 | |
| 1306 | 1409 | dol_syslog("Now we wait for answer 220"); |
| 1307 | 1410 | |
| 1308 | 1411 | // Check response from Server |
| 1309 | - if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket; |
|
| 1310 | - } |
|
| 1311 | - else |
|
| 1412 | + if ( $_retVal = $this->server_parse($socket, "220") ) { |
|
| 1413 | + $_retVal = $socket; |
|
| 1414 | + } |
|
| 1415 | + } else |
|
| 1312 | 1416 | { |
| 1313 | 1417 | $this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr); |
| 1314 | 1418 | } |
@@ -1369,9 +1473,11 @@ discard block |
||
| 1369 | 1473 | foreach ($matches[1] as $full) |
| 1370 | 1474 | { |
| 1371 | 1475 | |
| 1372 | - if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) // If xxx is 'file=aaa' |
|
| 1476 | + if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) { |
|
| 1477 | + // If xxx is 'file=aaa' |
|
| 1373 | 1478 | { |
| 1374 | 1479 | $img = $regs[1]; |
| 1480 | + } |
|
| 1375 | 1481 | |
| 1376 | 1482 | if (file_exists($images_dir.'/'.$img)) |
| 1377 | 1483 | { |
@@ -1430,15 +1536,13 @@ discard block |
||
| 1430 | 1536 | } |
| 1431 | 1537 | $i++; |
| 1432 | 1538 | } |
| 1433 | - } |
|
| 1434 | - else |
|
| 1539 | + } else |
|
| 1435 | 1540 | { |
| 1436 | 1541 | return -1; |
| 1437 | 1542 | } |
| 1438 | 1543 | |
| 1439 | 1544 | return 1; |
| 1440 | - } |
|
| 1441 | - else |
|
| 1545 | + } else |
|
| 1442 | 1546 | { |
| 1443 | 1547 | return 0; |
| 1444 | 1548 | } |
@@ -1473,8 +1577,7 @@ discard block |
||
| 1473 | 1577 | { |
| 1474 | 1578 | $name = trim($regs[1]); |
| 1475 | 1579 | $email = trim($regs[2]); |
| 1476 | - } |
|
| 1477 | - else |
|
| 1580 | + } else |
|
| 1478 | 1581 | { |
| 1479 | 1582 | $name = ''; |
| 1480 | 1583 | $email = trim($val); |
@@ -1499,9 +1602,13 @@ discard block |
||
| 1499 | 1602 | } |
| 1500 | 1603 | if ($format == 0 || $format == 3) |
| 1501 | 1604 | { |
| 1502 | - if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>'; |
|
| 1503 | - elseif (! $name) $newemail='<'.$email.'>'; |
|
| 1504 | - else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>'; |
|
| 1605 | + if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) { |
|
| 1606 | + $newemail='<'.$email.'>'; |
|
| 1607 | + } elseif (! $name) { |
|
| 1608 | + $newemail='<'.$email.'>'; |
|
| 1609 | + } else { |
|
| 1610 | + $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>'; |
|
| 1611 | + } |
|
| 1505 | 1612 | } |
| 1506 | 1613 | |
| 1507 | 1614 | $ret=($ret ? $ret.',' : '').$newemail; |
@@ -1509,7 +1616,9 @@ discard block |
||
| 1509 | 1616 | // Stop if we have too much records |
| 1510 | 1617 | if ($maxnumberofemail && $i >= $maxnumberofemail) |
| 1511 | 1618 | { |
| 1512 | - if (count($arrayaddress) > $maxnumberofemail) $ret.='...'; |
|
| 1619 | + if (count($arrayaddress) > $maxnumberofemail) { |
|
| 1620 | + $ret.='...'; |
|
| 1621 | + } |
|
| 1513 | 1622 | break; |
| 1514 | 1623 | } |
| 1515 | 1624 | } |
@@ -1539,8 +1648,7 @@ discard block |
||
| 1539 | 1648 | { |
| 1540 | 1649 | $name = trim($regs[1]); |
| 1541 | 1650 | $email = trim($regs[2]); |
| 1542 | - } |
|
| 1543 | - else |
|
| 1651 | + } else |
|
| 1544 | 1652 | { |
| 1545 | 1653 | $name = null; |
| 1546 | 1654 | $email = trim($val); |
@@ -176,8 +176,7 @@ |
||
| 176 | 176 | } |
| 177 | 177 | $out .= "</select>"; |
| 178 | 178 | $out .= ajax_combobox("select_".$htmlname); |
| 179 | - } |
|
| 180 | - else { |
|
| 179 | + } else { |
|
| 181 | 180 | dol_print_error($this->db); |
| 182 | 181 | } |
| 183 | 182 | return $out; |