Passed
Push — master ( 65bdac...4e88da )
by Alxarafe
32:38
created
Controllers/Categories.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
     {
47 47
 
48 48
 // Load translation files required by the page
49
-       Globals::$langs->load("categories");
49
+        Globals::$langs->load("categories");
50 50
 
51 51
 // Security check
52 52
         $socid = DolUtils::GETPOST('socid', 'int');
Please login to merge, or discard this patch.
Helpers/DolUtils2.php 1 patch
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 {
37 37
 
38 38
     /**
39
- * Same function than javascript unescape() function but in PHP.
40
- *
41
- * @param 	string	$source		String to decode
42
- * @return	string				Unescaped string
43
- */
39
+     * Same function than javascript unescape() function but in PHP.
40
+     *
41
+     * @param 	string	$source		String to decode
42
+     * @return	string				Unescaped string
43
+     */
44 44
 function jsUnEscape($source)
45 45
 {
46 46
     $decodedStr = "";
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
     $selected='EUA4';
132 132
     if (!$outputlangs) {
133
-    	$outputlangs=$langs;
133
+        $outputlangs=$langs;
134 134
     }
135 135
 
136 136
     if ($outputlangs->defaultlang == 'ca_CA') $selected='CAP4';        // Canada
@@ -234,15 +234,15 @@  discard block
 block discarded – undo
234 234
         else print ': ';
235 235
         if (is_object($object->user_creation))
236 236
         {
237
-        	if ($object->user_creation->id) print $object->user_creation->getNomUrl(1, '', 0, 0, 0);
238
-        	else print $langs->trans("Unknown");
237
+            if ($object->user_creation->id) print $object->user_creation->getNomUrl(1, '', 0, 0, 0);
238
+            else print $langs->trans("Unknown");
239 239
         }
240 240
         else
241 241
         {
242 242
             $userstatic=new User($db);
243 243
             $userstatic->fetch($object->user_creation_id ? $object->user_creation_id : $object->user_creation);
244 244
             if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
245
-        	else print $langs->trans("Unknown");
245
+            else print $langs->trans("Unknown");
246 246
         }
247 247
         if ($usetable) print '</td></tr>';
248 248
         else print '<br>';
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
         else print ': ';
271 271
         if (is_object($object->user_modification))
272 272
         {
273
-        	if ($object->user_modification->id) print $object->user_modification->getNomUrl(1, '', 0, 0, 0);
274
-        	else print $langs->trans("Unknown");
273
+            if ($object->user_modification->id) print $object->user_modification->getNomUrl(1, '', 0, 0, 0);
274
+            else print $langs->trans("Unknown");
275 275
         }
276 276
         else
277 277
         {
278 278
             $userstatic=new User($db);
279 279
             $userstatic->fetch($object->user_modification_id ? $object->user_modification_id : $object->user_modification);
280 280
             if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
281
-        	else print $langs->trans("Unknown");
281
+            else print $langs->trans("Unknown");
282 282
         }
283 283
         if ($usetable) print '</td></tr>';
284 284
         else print '<br>';
@@ -307,14 +307,14 @@  discard block
 block discarded – undo
307 307
         if (is_object($object->user_validation))
308 308
         {
309 309
             if ($object->user_validation->id) print $object->user_validation->getNomUrl(1, '', 0, 0, 0);
310
-        	else print $langs->trans("Unknown");
310
+            else print $langs->trans("Unknown");
311 311
         }
312 312
         else
313 313
         {
314 314
             $userstatic=new User($db);
315 315
             $userstatic->fetch($object->user_validation_id ? $object->user_validation_id : $object->user_validation);
316
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
317
-        	else print $langs->trans("Unknown");
316
+            if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
317
+            else print $langs->trans("Unknown");
318 318
         }
319 319
         if ($usetable) print '</td></tr>';
320 320
         else print '<br>';
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
         if (is_object($object->user_approve))
344 344
         {
345 345
             if ($object->user_approve->id) print $object->user_approve->getNomUrl(1, '', 0, 0, 0);
346
-        	else print $langs->trans("Unknown");
346
+            else print $langs->trans("Unknown");
347 347
         }
348 348
         else
349 349
         {
350 350
             $userstatic=new User($db);
351 351
             $userstatic->fetch($object->user_approve_id ? $object->user_approve_id : $object->user_approve);
352
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
353
-        	else print $langs->trans("Unknown");
352
+            if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
353
+            else print $langs->trans("Unknown");
354 354
         }
355 355
         if ($usetable) print '</td></tr>';
356 356
         else print '<br>';
@@ -406,15 +406,15 @@  discard block
 block discarded – undo
406 406
         else print ': ';
407 407
         if (is_object($object->user_cloture))
408 408
         {
409
-			if ($object->user_cloture->id) print $object->user_cloture->getNomUrl(1, '', 0, 0, 0);
410
-        	else print $langs->trans("Unknown");
409
+            if ($object->user_cloture->id) print $object->user_cloture->getNomUrl(1, '', 0, 0, 0);
410
+            else print $langs->trans("Unknown");
411 411
         }
412 412
         else
413 413
         {
414 414
             $userstatic=new User($db);
415 415
             $userstatic->fetch($object->user_cloture);
416
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
417
-        	else print $langs->trans("Unknown");
416
+            if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
417
+            else print $langs->trans("Unknown");
418 418
         }
419 419
         if ($usetable) print '</td></tr>';
420 420
         else print '<br>';
@@ -442,15 +442,15 @@  discard block
 block discarded – undo
442 442
         else print ': ';
443 443
         if (is_object($object->user_rappro))
444 444
         {
445
-			if ($object->user_rappro->id) print $object->user_rappro->getNomUrl(1, '', 0, 0, 0);
446
-        	else print $langs->trans("Unknown");
445
+            if ($object->user_rappro->id) print $object->user_rappro->getNomUrl(1, '', 0, 0, 0);
446
+            else print $langs->trans("Unknown");
447 447
         }
448 448
         else
449 449
         {
450 450
             $userstatic=new User($db);
451 451
             $userstatic->fetch($object->user_rappro);
452
-			if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
453
-        	else print $langs->trans("Unknown");
452
+            if ($userstatic->id) print $userstatic->getNomUrl(1, '', 0, 0, 0);
453
+            else print $langs->trans("Unknown");
454 454
         }
455 455
         if ($usetable) print '</td></tr>';
456 456
         else print '<br>';
@@ -496,8 +496,8 @@  discard block
 block discarded – undo
496 496
  */
497 497
 function dolAddEmailTrackId($email, $trackingid)
498 498
 {
499
-	$tmp=explode('@',$email);
500
-	return $tmp[0].'+'.$trackingid.'@'.(isset($tmp[1])?$tmp[1]:'');
499
+    $tmp=explode('@',$email);
500
+    return $tmp[0].'+'.$trackingid.'@'.(isset($tmp[1])?$tmp[1]:'');
501 501
 }
502 502
 
503 503
 /**
@@ -623,33 +623,33 @@  discard block
 block discarded – undo
623 623
  */
624 624
 function dolObfuscateEmail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true)
625 625
 {
626
-	if(!isValidEmail($mail))return '';
627
-	$tab = explode('@', $mail);
628
-	$tab2 = explode('.',$tab[1]);
629
-	$string_replace = '';
630
-	$mail_name = $tab[0];
631
-	$mail_domaine = $tab2[0];
632
-	$mail_tld = '';
633
-
634
-	$nbofelem = count($tab2);
635
-	for($i=1; $i < $nbofelem && $displaytld; $i++)
636
-	{
637
-		$mail_tld .= '.'.$tab2[$i];
638
-	}
639
-
640
-	for($i=0; $i < $nbreplace; $i++){
641
-		$string_replace .= $replace;
642
-	}
643
-
644
-	if(strlen($mail_name) > $nbdisplaymail){
645
-		$mail_name = substr($mail_name, 0, $nbdisplaymail);
646
-	}
647
-
648
-	if(strlen($mail_domaine) > $nbdisplaydomain){
649
-		$mail_domaine = substr($mail_domaine, strlen($mail_domaine)-$nbdisplaydomain);
650
-	}
651
-
652
-	return $mail_name . $string_replace . $mail_domaine . $mail_tld;
626
+    if(!isValidEmail($mail))return '';
627
+    $tab = explode('@', $mail);
628
+    $tab2 = explode('.',$tab[1]);
629
+    $string_replace = '';
630
+    $mail_name = $tab[0];
631
+    $mail_domaine = $tab2[0];
632
+    $mail_tld = '';
633
+
634
+    $nbofelem = count($tab2);
635
+    for($i=1; $i < $nbofelem && $displaytld; $i++)
636
+    {
637
+        $mail_tld .= '.'.$tab2[$i];
638
+    }
639
+
640
+    for($i=0; $i < $nbreplace; $i++){
641
+        $string_replace .= $replace;
642
+    }
643
+
644
+    if(strlen($mail_name) > $nbdisplaymail){
645
+        $mail_name = substr($mail_name, 0, $nbdisplaymail);
646
+    }
647
+
648
+    if(strlen($mail_domaine) > $nbdisplaydomain){
649
+        $mail_domaine = substr($mail_domaine, strlen($mail_domaine)-$nbdisplaydomain);
650
+    }
651
+
652
+    return $mail_name . $string_replace . $mail_domaine . $mail_tld;
653 653
 }
654 654
 
655 655
 
@@ -787,24 +787,24 @@  discard block
 block discarded – undo
787 787
     }
788 788
     else
789 789
     {
790
-    	$masktype='';
791
-    	$masktype_value='';
790
+        $masktype='';
791
+        $masktype_value='';
792 792
     }
793 793
 
794 794
     // Extract value for user
795 795
     if (preg_match('/\{(u+)\}/i',$mask,$regType))
796 796
     {
797
-    	$lastname = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
798
-    	if (is_object($objuser)) $lastname = $objuser->lastname;
797
+        $lastname = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
798
+        if (is_object($objuser)) $lastname = $objuser->lastname;
799 799
 
800
-    	$maskuser=$regType[1];
801
-    	$maskuser_value=substr($lastname,0,dol_strlen($regType[1]));// get n first characters of user firstname (where n is length in mask)
802
-    	$maskuser_value=str_pad($maskuser_value,dol_strlen($regType[1]),"#",STR_PAD_RIGHT);				 // we fill on right with # to have same number of char than into mask
800
+        $maskuser=$regType[1];
801
+        $maskuser_value=substr($lastname,0,dol_strlen($regType[1]));// get n first characters of user firstname (where n is length in mask)
802
+        $maskuser_value=str_pad($maskuser_value,dol_strlen($regType[1]),"#",STR_PAD_RIGHT);				 // we fill on right with # to have same number of char than into mask
803 803
     }
804 804
     else
805 805
     {
806
-    	$maskuser='';
807
-    	$maskuser_value='';
806
+        $maskuser='';
807
+        $maskuser_value='';
808 808
     }
809 809
 
810 810
     // Personalized field {XXX-1} à {XXX-9}
@@ -820,12 +820,12 @@  discard block
 block discarded – undo
820 820
 
821 821
     if (strstr($mask,'user_extra_'))
822 822
     {
823
-			$start = "{user_extra_";
824
-			$end = "\}";
825
-			$extra= get_string_between($mask, "user_extra_", "}");
826
-			if(!empty($user->array_options['options_'.$extra])){
827
-				$mask =  preg_replace('#('.$start.')(.*?)('.$end.')#si', $user->array_options['options_'.$extra], $mask);
828
-			}
823
+            $start = "{user_extra_";
824
+            $end = "\}";
825
+            $extra= get_string_between($mask, "user_extra_", "}");
826
+            if(!empty($user->array_options['options_'.$extra])){
827
+                $mask =  preg_replace('#('.$start.')(.*?)('.$end.')#si', $user->array_options['options_'.$extra], $mask);
828
+            }
829 829
     }
830 830
     $maskwithonlyymcode=$mask;
831 831
     $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$maskcounter,$maskwithonlyymcode);
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
         else // if reset is for a specific month in year, we need year
887 887
         {
888 888
             if (preg_match('/^(.*)\{(m+)\}\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=3; $posm=2; }
889
-        	else if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
889
+            else if (preg_match('/^(.*)\{(y+)\}\{(m+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=3; }
890 890
             else if (preg_match('/^(.*)\{(y+)\}/i',$maskwithonlyymcode,$reg)) { $posy=2; $posm=0; }
891 891
             else return 'ErrorCantUseRazIfNoYearInMask';
892 892
         }
@@ -894,11 +894,11 @@  discard block
 block discarded – undo
894 894
         $yearlen = $posy?dol_strlen($reg[$posy]):0;
895 895
         $monthlen = $posm?dol_strlen($reg[$posm]):0;
896 896
         // Define pos
897
-       	$yearpos = (dol_strlen($reg[1])+1);
897
+            $yearpos = (dol_strlen($reg[1])+1);
898 898
         $monthpos = ($yearpos+$yearlen);
899 899
         if ($posy == 3 && $posm == 2) {		// if month is before year
900
-          	$monthpos = (dol_strlen($reg[1])+1);
901
-           	$yearpos = ($monthpos+$monthlen);
900
+                $monthpos = (dol_strlen($reg[1])+1);
901
+                $yearpos = ($monthpos+$monthlen);
902 902
         }
903 903
         //print "xxx ".$maskwithonlyymcode." maskraz=".$maskraz." posy=".$posy." yearlen=".$yearlen." yearpos=".$yearpos." posm=".$posm." monthlen=".$monthlen." monthpos=".$monthpos." yearoffsettype=".$yearoffsettype." resetEveryMonth=".$resetEveryMonth."\n";
904 904
 
@@ -908,20 +908,20 @@  discard block
 block discarded – undo
908 908
 
909 909
         if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=')	// $yearoffsettype is - or +
910 910
         {
911
-        	$currentyear=date("Y", $date);
912
-        	$fiscaldate=dol_mktime('0','0','0',$maskraz,'1',$currentyear);
913
-        	$newyeardate=dol_mktime('0','0','0','1','1',$currentyear);
914
-        	$nextnewyeardate=dol_mktime('0','0','0','1','1',$currentyear+1);
915
-        	//echo 'currentyear='.$currentyear.' date='.dol_print_date($date, 'day').' fiscaldate='.dol_print_date($fiscaldate, 'day').'<br>';
916
-
917
-        	// If after or equal of current fiscal date
918
-        	if ($date >= $fiscaldate)
919
-        	{
920
-        		// If before of next new year date
921
-        		if ($date < $nextnewyeardate && $yearoffsettype == '+') $yearoffset=1;
922
-        	}
923
-        	// If after or equal of current new year date
924
-        	else if ($date >= $newyeardate && $yearoffsettype == '-') $yearoffset=-1;
911
+            $currentyear=date("Y", $date);
912
+            $fiscaldate=dol_mktime('0','0','0',$maskraz,'1',$currentyear);
913
+            $newyeardate=dol_mktime('0','0','0','1','1',$currentyear);
914
+            $nextnewyeardate=dol_mktime('0','0','0','1','1',$currentyear+1);
915
+            //echo 'currentyear='.$currentyear.' date='.dol_print_date($date, 'day').' fiscaldate='.dol_print_date($fiscaldate, 'day').'<br>';
916
+
917
+            // If after or equal of current fiscal date
918
+            if ($date >= $fiscaldate)
919
+            {
920
+                // If before of next new year date
921
+                if ($date < $nextnewyeardate && $yearoffsettype == '+') $yearoffset=1;
922
+            }
923
+            // If after or equal of current new year date
924
+            else if ($date >= $newyeardate && $yearoffsettype == '-') $yearoffset=-1;
925 925
         }
926 926
         // For backward compatibility
927 927
         else if (date("m",$date) < $maskraz && empty($resetEveryMonth)) { $yearoffset=-1; }	// If current month lower that month of return to zero, year is previous year
@@ -942,11 +942,11 @@  discard block
 block discarded – undo
942 942
             $sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") < '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."') ";
943 943
             $sqlwhere.=')';
944 944
         }
945
-		else if ($resetEveryMonth)
946
-		{
947
-			$sqlwhere.="(SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
945
+        else if ($resetEveryMonth)
946
+        {
947
+            $sqlwhere.="(SUBSTRING(".$field.", ".$yearpos.", ".$yearlen.") = '".$yearcomp."'";
948 948
             $sqlwhere.=" AND SUBSTRING(".$field.", ".$monthpos.", ".$monthlen.") = '".str_pad($monthcomp, $monthlen, '0', STR_PAD_LEFT)."')";
949
-		}
949
+        }
950 950
         else   // reset is done on january
951 951
         {
952 952
             $sqlwhere.='(SUBSTRING('.$field.', '.$yearpos.', '.$yearlen.") = '".$yearcomp."')";
@@ -957,13 +957,13 @@  discard block
 block discarded – undo
957 957
 
958 958
     // Define $sqlstring
959 959
     if (function_exists('mb_strrpos'))
960
-    	{
961
-    	$posnumstart=mb_strrpos($maskwithnocode,$maskcounter, 'UTF-8');
962
-	}
963
-	else
964
-	{
965
-    	$posnumstart=strrpos($maskwithnocode,$maskcounter);
966
-	}	// Pos of counter in final string (from 0 to ...)
960
+        {
961
+        $posnumstart=mb_strrpos($maskwithnocode,$maskcounter, 'UTF-8');
962
+    }
963
+    else
964
+    {
965
+        $posnumstart=strrpos($maskwithnocode,$maskcounter);
966
+    }	// Pos of counter in final string (from 0 to ...)
967 967
     if ($posnumstart < 0) return 'ErrorBadMaskFailedToLocatePosOfSequence';
968 968
     $sqlstring='SUBSTRING('.$field.', '.($posnumstart+1).', '.dol_strlen($maskcounter).')';
969 969
 
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
     if ($maskuser) $maskLike = str_replace(dol_string_nospecial('{'.$maskuser.'}'),$maskuser_value,$maskLike);
983 983
     foreach($maskperso as $key => $val)
984 984
     {
985
-    	$maskLike = str_replace(dol_string_nospecial($maskperso[$key]),$maskpersonew[$key],$maskLike);
985
+        $maskLike = str_replace(dol_string_nospecial($maskperso[$key]),$maskpersonew[$key],$maskLike);
986 986
     }
987 987
 
988 988
     // Get counter in database
@@ -990,11 +990,11 @@  discard block
 block discarded – undo
990 990
     $sql = "SELECT MAX(".$sqlstring.") as val";
991 991
     $sql.= " FROM ".MAIN_DB_PREFIX.$table;
992 992
     $sql.= " WHERE ".$field." LIKE '".$maskLike."'";
993
-	$sql.= " AND ".$field." NOT LIKE '(PROV%)'";
993
+    $sql.= " AND ".$field." NOT LIKE '(PROV%)'";
994 994
     if ($bentityon) // only if entity enable
995
-    	$sql.= " AND entity IN (".getEntity($sharetable).")";
995
+        $sql.= " AND entity IN (".getEntity($sharetable).")";
996 996
     else if (! empty($forceentity))
997
-    	$sql.= " AND entity IN (".$forceentity.")";
997
+        $sql.= " AND entity IN (".$forceentity.")";
998 998
     if ($where) $sql.=$where;
999 999
     if ($sqlwhere) $sql.=' AND '.$sqlwhere;
1000 1000
 
@@ -1012,8 +1012,8 @@  discard block
 block discarded – undo
1012 1012
     if (empty($counter)) $counter=$maskoffset;
1013 1013
     else if (preg_match('/[^0-9]/i',$counter))
1014 1014
     {
1015
-    	$counter=0;
1016
-    	dol_syslog("Error, the last counter found is '".$counter."' so is not a numeric value. We will restart to 1.", LOG_ERR);
1015
+        $counter=0;
1016
+        dol_syslog("Error, the last counter found is '".$counter."' so is not a numeric value. We will restart to 1.", LOG_ERR);
1017 1017
     }
1018 1018
     else if ($counter < $maskoffset && empty($conf->global->MAIN_NUMBERING_OFFSET_ONLY_FOR_FIRST)) $counter=$maskoffset;
1019 1019
 
@@ -1039,11 +1039,11 @@  discard block
 block discarded – undo
1039 1039
         $sql = "SELECT ".$field." as ref";
1040 1040
         $sql.= " FROM ".MAIN_DB_PREFIX.$table;
1041 1041
         $sql.= " WHERE ".$field." LIKE '".$maskLike."'";
1042
-    	$sql.= " AND ".$field." NOT LIKE '%PROV%'";
1043
-    	if ($bentityon) // only if entity enable
1044
-        	$sql.= " AND entity IN (".getEntity($sharetable).")";
1042
+        $sql.= " AND ".$field." NOT LIKE '%PROV%'";
1043
+        if ($bentityon) // only if entity enable
1044
+            $sql.= " AND entity IN (".getEntity($sharetable).")";
1045 1045
         else if (! empty($forceentity))
1046
-        	$sql.= " AND entity IN (".$forceentity.")";
1046
+            $sql.= " AND entity IN (".$forceentity.")";
1047 1047
         if ($where) $sql.=$where;
1048 1048
         if ($sqlwhere) $sql.=' AND '.$sqlwhere;
1049 1049
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         // If value for $counter has a length higher than $maskcounter chars
1066 1066
         if ($counter >= pow(10, dol_strlen($maskcounter)))
1067 1067
         {
1068
-        	$counter='ErrorMaxNumberReachForThisMask';
1068
+            $counter='ErrorMaxNumberReachForThisMask';
1069 1069
         }
1070 1070
 
1071 1071
         if (! empty($maskrefclient_maskcounter))
@@ -1097,9 +1097,9 @@  discard block
 block discarded – undo
1097 1097
             //$sql.= " WHERE ".$field." not like '(%'";
1098 1098
             $maskrefclient_sql.= " WHERE ".$field." LIKE '".$maskrefclient_maskLike."'";
1099 1099
             if ($bentityon) // only if entity enable
1100
-            	$maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")";
1100
+                $maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")";
1101 1101
             else if (! empty($forceentity))
1102
-            	$sql.= " AND entity IN (".$forceentity.")";
1102
+                $sql.= " AND entity IN (".$forceentity.")";
1103 1103
             if ($where) $maskrefclient_sql.=$where; //use the same optional where as general mask
1104 1104
             if ($sqlwhere) $maskrefclient_sql.=' AND '.$sqlwhere; //use the same sqlwhere as general mask
1105 1105
             $maskrefclient_sql.=' AND (SUBSTRING('.$field.', '.(strpos($maskwithnocode,$maskrefclient)+1).', '.dol_strlen($maskrefclient_maskclientcode).")='".$maskrefclient_clientcode."')";
@@ -1114,25 +1114,25 @@  discard block
 block discarded – undo
1114 1114
             else dol_print_error($db);
1115 1115
 
1116 1116
             if (empty($maskrefclient_counter) || preg_match('/[^0-9]/i',$maskrefclient_counter)) $maskrefclient_counter=$maskrefclient_maskoffset;
1117
-			$maskrefclient_counter++;
1117
+            $maskrefclient_counter++;
1118 1118
         }
1119 1119
 
1120 1120
         // Build numFinal
1121 1121
         $numFinal = $mask;
1122 1122
 
1123 1123
         // We replace special codes except refclient
1124
-		if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=')	// yearoffsettype is - or +, so we don't want current year
1125
-		{
1126
-	        $numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date)+$yearoffset, $numFinal);
1127
-        	$numFinal = preg_replace('/\{yy\}/i',  date("y",$date)+$yearoffset, $numFinal);
1128
-        	$numFinal = preg_replace('/\{y\}/i',   substr(date("y",$date),1,1)+$yearoffset, $numFinal);
1129
-		}
1130
-		else	// we want yyyy to be current year
1131
-		{
1132
-        	$numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date), $numFinal);
1133
-        	$numFinal = preg_replace('/\{yy\}/i',  date("y",$date), $numFinal);
1134
-        	$numFinal = preg_replace('/\{y\}/i',   substr(date("y",$date),1,1), $numFinal);
1135
-		}
1124
+        if (! empty($yearoffsettype) && ! is_numeric($yearoffsettype) && $yearoffsettype != '=')	// yearoffsettype is - or +, so we don't want current year
1125
+        {
1126
+            $numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date)+$yearoffset, $numFinal);
1127
+            $numFinal = preg_replace('/\{yy\}/i',  date("y",$date)+$yearoffset, $numFinal);
1128
+            $numFinal = preg_replace('/\{y\}/i',   substr(date("y",$date),1,1)+$yearoffset, $numFinal);
1129
+        }
1130
+        else	// we want yyyy to be current year
1131
+        {
1132
+            $numFinal = preg_replace('/\{yyyy\}/i',date("Y",$date), $numFinal);
1133
+            $numFinal = preg_replace('/\{yy\}/i',  date("y",$date), $numFinal);
1134
+            $numFinal = preg_replace('/\{y\}/i',   substr(date("y",$date),1,1), $numFinal);
1135
+        }
1136 1136
         $numFinal = preg_replace('/\{mm\}/i',  date("m",$date), $numFinal);
1137 1137
         $numFinal = preg_replace('/\{dd\}/i',  date("d",$date), $numFinal);
1138 1138
 
@@ -1162,9 +1162,9 @@  discard block
 block discarded – undo
1162 1162
         // Now we replace the user
1163 1163
         if ($maskuser)
1164 1164
         {
1165
-        	$maskuser_maskbefore='{'.$maskuser.'}';
1166
-        	$maskuser_maskafter=$maskuser_value;
1167
-        	$numFinal = str_replace($maskuser_maskbefore,$maskuser_maskafter,$numFinal);
1165
+            $maskuser_maskbefore='{'.$maskuser.'}';
1166
+            $maskuser_maskafter=$maskuser_value;
1167
+            $numFinal = str_replace($maskuser_maskbefore,$maskuser_maskafter,$numFinal);
1168 1168
         }
1169 1169
     }
1170 1170
 
@@ -1183,11 +1183,11 @@  discard block
 block discarded – undo
1183 1183
 function get_string_between($string, $start, $end)
1184 1184
 {
1185 1185
     $string = " ".$string;
1186
-     $ini = strpos($string,$start);
1187
-     if ($ini == 0) return "";
1188
-     $ini += strlen($start);
1189
-     $len = strpos($string,$end,$ini) - $ini;
1190
-     return substr($string,$ini,$len);
1186
+        $ini = strpos($string,$start);
1187
+        if ($ini == 0) return "";
1188
+        $ini += strlen($start);
1189
+        $len = strpos($string,$end,$ini) - $ini;
1190
+        return substr($string,$ini,$len);
1191 1191
 }
1192 1192
 
1193 1193
 /**
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
     }
1536 1536
     else
1537 1537
     {
1538
-    	$string = vatrate($reduction,true);
1538
+        $string = vatrate($reduction,true);
1539 1539
     }
1540 1540
 
1541 1541
     return $string;
@@ -1628,7 +1628,7 @@  discard block
 block discarded – undo
1628 1628
                 //irtoscan.=($dirtoscan?',':'').preg_replace('/[\r\n]+/',',',trim($conf->global->$const));
1629 1629
                 $dirtoscan= preg_replace('/[\r\n]+/',',',trim($conf->global->$const));
1630 1630
 
1631
-		$listoffiles=array();
1631
+        $listoffiles=array();
1632 1632
 
1633 1633
                 // Now we add models found in directories scanned
1634 1634
                 $listofdir=explode(',',$dirtoscan);
@@ -1639,8 +1639,8 @@  discard block
 block discarded – undo
1639 1639
                     if (! $tmpdir) { unset($listofdir[$key]); continue; }
1640 1640
                     if (is_dir($tmpdir))
1641 1641
                     {
1642
-			// all type of template is allowed
1643
-			$tmpfiles=dol_dir_list($tmpdir, 'files', 0, '', '', 'name', SORT_ASC, 0);
1642
+            // all type of template is allowed
1643
+            $tmpfiles=dol_dir_list($tmpdir, 'files', 0, '', '', 'name', SORT_ASC, 0);
1644 1644
                         if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles);
1645 1645
                     }
1646 1646
                 }
@@ -1696,19 +1696,19 @@  discard block
 block discarded – undo
1696 1696
  */
1697 1697
 function is_ip($ip)
1698 1698
 {
1699
-	// First we test if it is a valid IPv4
1700
-	if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
1699
+    // First we test if it is a valid IPv4
1700
+    if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
1701 1701
 
1702
-		// Then we test if it is a private range
1703
-		if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) return 2;
1702
+        // Then we test if it is a private range
1703
+        if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE)) return 2;
1704 1704
 
1705
-		// Then we test if it is a reserved range
1706
-		if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) return 0;
1705
+        // Then we test if it is a reserved range
1706
+        if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_RES_RANGE)) return 0;
1707 1707
 
1708
-		return 1;
1709
-	}
1708
+        return 1;
1709
+    }
1710 1710
 
1711
-	return 0;
1711
+    return 0;
1712 1712
 }
1713 1713
 
1714 1714
 /**
@@ -1748,25 +1748,25 @@  discard block
 block discarded – undo
1748 1748
     if ($proxyuse)
1749 1749
     {
1750 1750
         $params=array('connection_timeout'=>$timeout,
1751
-                      'response_timeout'=>$response_timeout,
1752
-                      'proxy_use'      => 1,
1753
-                      'proxy_host'     => $proxyhost,
1754
-                      'proxy_port'     => $proxyport,
1755
-                      'proxy_login'    => $proxyuser,
1756
-                      'proxy_password' => $proxypass,
1757
-                      'trace'		   => 1
1751
+                        'response_timeout'=>$response_timeout,
1752
+                        'proxy_use'      => 1,
1753
+                        'proxy_host'     => $proxyhost,
1754
+                        'proxy_port'     => $proxyport,
1755
+                        'proxy_login'    => $proxyuser,
1756
+                        'proxy_password' => $proxypass,
1757
+                        'trace'		   => 1
1758 1758
         );
1759 1759
     }
1760 1760
     else
1761 1761
     {
1762 1762
         $params=array('connection_timeout'=>$timeout,
1763
-                      'response_timeout'=>$response_timeout,
1764
-                      'proxy_use'      => 0,
1765
-                      'proxy_host'     => false,
1766
-                      'proxy_port'     => false,
1767
-                      'proxy_login'    => false,
1768
-                      'proxy_password' => false,
1769
-                      'trace'		   => 1
1763
+                        'response_timeout'=>$response_timeout,
1764
+                        'proxy_use'      => 0,
1765
+                        'proxy_host'     => false,
1766
+                        'proxy_port'     => false,
1767
+                        'proxy_login'    => false,
1768
+                        'proxy_password' => false,
1769
+                        'trace'		   => 1
1770 1770
         );
1771 1771
     }
1772 1772
     return $params;
@@ -1784,118 +1784,118 @@  discard block
 block discarded – undo
1784 1784
  */
1785 1785
 function dolGetElementUrl($objectid,$objecttype,$withpicto=0,$option='')
1786 1786
 {
1787
-	global $db, $conf, $langs;
1788
-
1789
-	$ret='';
1790
-
1791
-	// Parse element/subelement (ex: project_task)
1792
-	$module = $element = $subelement = $objecttype;
1793
-	if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
1794
-	{
1795
-		$module = $element = $regs[1];
1796
-		$subelement = $regs[2];
1797
-	}
1798
-
1799
-	$classpath = $element.'/class';
1800
-
1801
-	// To work with non standard path
1802
-	if ($objecttype == 'facture' || $objecttype == 'invoice') {
1803
-		$classpath = 'compta/facture/class';
1804
-		$module='facture';
1805
-		$subelement='facture';
1806
-	}
1807
-	if ($objecttype == 'commande' || $objecttype == 'order') {
1808
-		$classpath = 'commande/class';
1809
-		$module='commande';
1810
-		$subelement='commande';
1811
-	}
1812
-	if ($objecttype == 'propal')  {
1813
-		$classpath = 'comm/propal/class';
1814
-	}
1815
-	if ($objecttype == 'supplier_proposal')  {
1816
-		$classpath = 'supplier_proposal/class';
1817
-	}
1818
-	if ($objecttype == 'shipping') {
1819
-		$classpath = 'expedition/class';
1820
-		$subelement = 'expedition';
1821
-		$module = 'expedition_bon';
1822
-	}
1823
-	if ($objecttype == 'delivery') {
1824
-		$classpath = 'livraison/class';
1825
-		$subelement = 'livraison';
1826
-		$module = 'livraison_bon';
1827
-	}
1828
-	if ($objecttype == 'contract') {
1829
-		$classpath = 'contrat/class';
1830
-		$module='contrat';
1831
-		$subelement='contrat';
1832
-	}
1833
-	if ($objecttype == 'member') {
1834
-		$classpath = 'adherents/class';
1835
-		$module='adherent';
1836
-		$subelement='adherent';
1837
-	}
1838
-	if ($objecttype == 'cabinetmed_cons') {
1839
-		$classpath = 'cabinetmed/class';
1840
-		$module='cabinetmed';
1841
-		$subelement='cabinetmedcons';
1842
-	}
1843
-	if ($objecttype == 'fichinter') {
1844
-		$classpath = 'fichinter/class';
1845
-		$module='ficheinter';
1846
-		$subelement='fichinter';
1847
-	}
1848
-	if ($objecttype == 'task') {
1849
-		$classpath = 'projet/class';
1850
-		$module='projet';
1851
-		$subelement='task';
1852
-	}
1853
-	if ($objecttype == 'stock') {
1854
-		$classpath = 'product/stock/class';
1855
-		$module='stock';
1856
-		$subelement='stock';
1857
-	}
1858
-
1859
-	//print "objecttype=".$objecttype." module=".$module." subelement=".$subelement;
1860
-
1861
-	$classfile = strtolower($subelement); $classname = ucfirst($subelement);
1862
-	if ($objecttype == 'invoice_supplier') {
1863
-		$classfile = 'fournisseur.facture';
1864
-		$classname='FactureFournisseur';
1865
-		$classpath = 'fourn/class';
1866
-		$module='fournisseur';
1867
-	}
1868
-	elseif ($objecttype == 'order_supplier')   {
1869
-		$classfile = 'fournisseur.commande';
1870
-		$classname='CommandeFournisseur';
1871
-		$classpath = 'fourn/class';
1872
-		$module='fournisseur';
1873
-	}
1874
-	elseif ($objecttype == 'stock')   {
1875
-		$classpath = 'product/stock/class';
1876
-		$classfile='entrepot';
1877
-		$classname='Entrepot';
1878
-	}
1879
-	if (! empty($conf->$module->enabled))
1880
-	{
1881
-		$res=dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
1882
-		if ($res)
1883
-		{
1884
-			if (class_exists($classname))
1885
-			{
1886
-				$object = new $classname($db);
1887
-				$res=$object->fetch($objectid);
1888
-				if ($res > 0) {
1889
-					$ret=$object->getNomUrl($withpicto,$option);
1890
-				} elseif($res==0) {
1891
-					$ret=$langs->trans('Deleted');
1892
-				}
1893
-				unset($object);
1894
-			}
1895
-			else dol_syslog("Class with classname ".$classname." is unknown even after the include", LOG_ERR);
1896
-		}
1897
-	}
1898
-	return $ret;
1787
+    global $db, $conf, $langs;
1788
+
1789
+    $ret='';
1790
+
1791
+    // Parse element/subelement (ex: project_task)
1792
+    $module = $element = $subelement = $objecttype;
1793
+    if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs))
1794
+    {
1795
+        $module = $element = $regs[1];
1796
+        $subelement = $regs[2];
1797
+    }
1798
+
1799
+    $classpath = $element.'/class';
1800
+
1801
+    // To work with non standard path
1802
+    if ($objecttype == 'facture' || $objecttype == 'invoice') {
1803
+        $classpath = 'compta/facture/class';
1804
+        $module='facture';
1805
+        $subelement='facture';
1806
+    }
1807
+    if ($objecttype == 'commande' || $objecttype == 'order') {
1808
+        $classpath = 'commande/class';
1809
+        $module='commande';
1810
+        $subelement='commande';
1811
+    }
1812
+    if ($objecttype == 'propal')  {
1813
+        $classpath = 'comm/propal/class';
1814
+    }
1815
+    if ($objecttype == 'supplier_proposal')  {
1816
+        $classpath = 'supplier_proposal/class';
1817
+    }
1818
+    if ($objecttype == 'shipping') {
1819
+        $classpath = 'expedition/class';
1820
+        $subelement = 'expedition';
1821
+        $module = 'expedition_bon';
1822
+    }
1823
+    if ($objecttype == 'delivery') {
1824
+        $classpath = 'livraison/class';
1825
+        $subelement = 'livraison';
1826
+        $module = 'livraison_bon';
1827
+    }
1828
+    if ($objecttype == 'contract') {
1829
+        $classpath = 'contrat/class';
1830
+        $module='contrat';
1831
+        $subelement='contrat';
1832
+    }
1833
+    if ($objecttype == 'member') {
1834
+        $classpath = 'adherents/class';
1835
+        $module='adherent';
1836
+        $subelement='adherent';
1837
+    }
1838
+    if ($objecttype == 'cabinetmed_cons') {
1839
+        $classpath = 'cabinetmed/class';
1840
+        $module='cabinetmed';
1841
+        $subelement='cabinetmedcons';
1842
+    }
1843
+    if ($objecttype == 'fichinter') {
1844
+        $classpath = 'fichinter/class';
1845
+        $module='ficheinter';
1846
+        $subelement='fichinter';
1847
+    }
1848
+    if ($objecttype == 'task') {
1849
+        $classpath = 'projet/class';
1850
+        $module='projet';
1851
+        $subelement='task';
1852
+    }
1853
+    if ($objecttype == 'stock') {
1854
+        $classpath = 'product/stock/class';
1855
+        $module='stock';
1856
+        $subelement='stock';
1857
+    }
1858
+
1859
+    //print "objecttype=".$objecttype." module=".$module." subelement=".$subelement;
1860
+
1861
+    $classfile = strtolower($subelement); $classname = ucfirst($subelement);
1862
+    if ($objecttype == 'invoice_supplier') {
1863
+        $classfile = 'fournisseur.facture';
1864
+        $classname='FactureFournisseur';
1865
+        $classpath = 'fourn/class';
1866
+        $module='fournisseur';
1867
+    }
1868
+    elseif ($objecttype == 'order_supplier')   {
1869
+        $classfile = 'fournisseur.commande';
1870
+        $classname='CommandeFournisseur';
1871
+        $classpath = 'fourn/class';
1872
+        $module='fournisseur';
1873
+    }
1874
+    elseif ($objecttype == 'stock')   {
1875
+        $classpath = 'product/stock/class';
1876
+        $classfile='entrepot';
1877
+        $classname='Entrepot';
1878
+    }
1879
+    if (! empty($conf->$module->enabled))
1880
+    {
1881
+        $res=dol_include_once('/'.$classpath.'/'.$classfile.'.class.php');
1882
+        if ($res)
1883
+        {
1884
+            if (class_exists($classname))
1885
+            {
1886
+                $object = new $classname($db);
1887
+                $res=$object->fetch($objectid);
1888
+                if ($res > 0) {
1889
+                    $ret=$object->getNomUrl($withpicto,$option);
1890
+                } elseif($res==0) {
1891
+                    $ret=$langs->trans('Deleted');
1892
+                }
1893
+                unset($object);
1894
+            }
1895
+            else dol_syslog("Class with classname ".$classname." is unknown even after the include", LOG_ERR);
1896
+        }
1897
+    }
1898
+    return $ret;
1899 1899
 }
1900 1900
 
1901 1901
 
@@ -1909,113 +1909,113 @@  discard block
 block discarded – undo
1909 1909
  */
1910 1910
 function cleanCorruptedTree($db, $tabletocleantree, $fieldfkparent)
1911 1911
 {
1912
-	$totalnb=0;
1913
-	$listofid=array();
1914
-	$listofparentid=array();
1915
-
1916
-	// Get list of all id in array listofid and all parents in array listofparentid
1917
-	$sql='SELECT rowid, '.$fieldfkparent.' as parent_id FROM '.MAIN_DB_PREFIX.$tabletocleantree;
1918
-	$resql = $db->query($sql);
1919
-	if ($resql)
1920
-	{
1921
-		$num = $db->num_rows($resql);
1922
-		$i = 0;
1923
-		while ($i < $num)
1924
-		{
1925
-			$obj = $db->fetch_object($resql);
1926
-			$listofid[]=$obj->rowid;
1927
-			if ($obj->parent_id > 0) $listofparentid[$obj->rowid]=$obj->parent_id;
1928
-			$i++;
1929
-		}
1930
-	}
1931
-	else
1932
-	{
1933
-		dol_print_error($db);
1934
-	}
1935
-
1936
-	if (count($listofid))
1937
-	{
1938
-		print 'Code requested to clean tree (may be to solve data corruption), so we check/clean orphelins and loops.'."<br>\n";
1939
-
1940
-		// Check loops on each other
1941
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree." SET ".$fieldfkparent." = 0 WHERE ".$fieldfkparent." = rowid";	// So we update only records linked to themself
1942
-		$resql = $db->query($sql);
1943
-		if ($resql)
1944
-		{
1945
-			$nb=$db->affected_rows($sql);
1946
-			if ($nb > 0)
1947
-			{
1948
-				print '<br>Some record that were parent of themself were cleaned.';
1949
-			}
1950
-
1951
-			$totalnb+=$nb;
1952
-		}
1953
-		//else dol_print_error($db);
1954
-
1955
-		// Check other loops
1956
-		$listofidtoclean=array();
1957
-		foreach($listofparentid as $id => $pid)
1958
-		{
1959
-			// Check depth
1960
-			//print 'Analyse record id='.$id.' with parent '.$pid.'<br>';
1961
-
1962
-			$cursor=$id; $arrayidparsed=array();	// We start from child $id
1963
-			while ($cursor > 0)
1964
-			{
1965
-				$arrayidparsed[$cursor]=1;
1966
-				if ($arrayidparsed[$listofparentid[$cursor]])	// We detect a loop. A record with a parent that was already into child
1967
-				{
1968
-					print 'Found a loop between id '.$id.' - '.$cursor.'<br>';
1969
-					unset($arrayidparsed);
1970
-					$listofidtoclean[$cursor]=$id;
1971
-					break;
1972
-				}
1973
-				$cursor=$listofparentid[$cursor];
1974
-			}
1975
-
1976
-			if (count($listofidtoclean)) break;
1977
-		}
1978
-
1979
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
1980
-		$sql.= " SET ".$fieldfkparent." = 0";
1981
-		$sql.= " WHERE rowid IN (".join(',',$listofidtoclean).")";	// So we update only records detected wrong
1982
-		$resql = $db->query($sql);
1983
-		if ($resql)
1984
-		{
1985
-			$nb=$db->affected_rows($sql);
1986
-			if ($nb > 0)
1987
-			{
1988
-				// Removed orphelins records
1989
-				print '<br>Some records were detected to have parent that is a child, we set them as root record for id: ';
1990
-				print join(',',$listofidtoclean);
1991
-			}
1992
-
1993
-			$totalnb+=$nb;
1994
-		}
1995
-		//else dol_print_error($db);
1996
-
1997
-		// Check and clean orphelins
1998
-		$sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
1999
-		$sql.= " SET ".$fieldfkparent." = 0";
2000
-		$sql.= " WHERE ".$fieldfkparent." NOT IN (".join(',',$listofid).")";	// So we update only records linked to a non existing parent
2001
-		$resql = $db->query($sql);
2002
-		if ($resql)
2003
-		{
2004
-			$nb=$db->affected_rows($sql);
2005
-			if ($nb > 0)
2006
-			{
2007
-				// Removed orphelins records
2008
-				print '<br>Some orphelins were found and modified to be parent so records are visible again for id: ';
2009
-				print join(',',$listofid);
2010
-			}
2011
-
2012
-			$totalnb+=$nb;
2013
-		}
2014
-		//else dol_print_error($db);
2015
-
2016
-		print '<br>We fixed '.$totalnb.' record(s). Some records may still be corrupted. New check may be required.';
2017
-		return $totalnb;
2018
-	}
1912
+    $totalnb=0;
1913
+    $listofid=array();
1914
+    $listofparentid=array();
1915
+
1916
+    // Get list of all id in array listofid and all parents in array listofparentid
1917
+    $sql='SELECT rowid, '.$fieldfkparent.' as parent_id FROM '.MAIN_DB_PREFIX.$tabletocleantree;
1918
+    $resql = $db->query($sql);
1919
+    if ($resql)
1920
+    {
1921
+        $num = $db->num_rows($resql);
1922
+        $i = 0;
1923
+        while ($i < $num)
1924
+        {
1925
+            $obj = $db->fetch_object($resql);
1926
+            $listofid[]=$obj->rowid;
1927
+            if ($obj->parent_id > 0) $listofparentid[$obj->rowid]=$obj->parent_id;
1928
+            $i++;
1929
+        }
1930
+    }
1931
+    else
1932
+    {
1933
+        dol_print_error($db);
1934
+    }
1935
+
1936
+    if (count($listofid))
1937
+    {
1938
+        print 'Code requested to clean tree (may be to solve data corruption), so we check/clean orphelins and loops.'."<br>\n";
1939
+
1940
+        // Check loops on each other
1941
+        $sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree." SET ".$fieldfkparent." = 0 WHERE ".$fieldfkparent." = rowid";	// So we update only records linked to themself
1942
+        $resql = $db->query($sql);
1943
+        if ($resql)
1944
+        {
1945
+            $nb=$db->affected_rows($sql);
1946
+            if ($nb > 0)
1947
+            {
1948
+                print '<br>Some record that were parent of themself were cleaned.';
1949
+            }
1950
+
1951
+            $totalnb+=$nb;
1952
+        }
1953
+        //else dol_print_error($db);
1954
+
1955
+        // Check other loops
1956
+        $listofidtoclean=array();
1957
+        foreach($listofparentid as $id => $pid)
1958
+        {
1959
+            // Check depth
1960
+            //print 'Analyse record id='.$id.' with parent '.$pid.'<br>';
1961
+
1962
+            $cursor=$id; $arrayidparsed=array();	// We start from child $id
1963
+            while ($cursor > 0)
1964
+            {
1965
+                $arrayidparsed[$cursor]=1;
1966
+                if ($arrayidparsed[$listofparentid[$cursor]])	// We detect a loop. A record with a parent that was already into child
1967
+                {
1968
+                    print 'Found a loop between id '.$id.' - '.$cursor.'<br>';
1969
+                    unset($arrayidparsed);
1970
+                    $listofidtoclean[$cursor]=$id;
1971
+                    break;
1972
+                }
1973
+                $cursor=$listofparentid[$cursor];
1974
+            }
1975
+
1976
+            if (count($listofidtoclean)) break;
1977
+        }
1978
+
1979
+        $sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
1980
+        $sql.= " SET ".$fieldfkparent." = 0";
1981
+        $sql.= " WHERE rowid IN (".join(',',$listofidtoclean).")";	// So we update only records detected wrong
1982
+        $resql = $db->query($sql);
1983
+        if ($resql)
1984
+        {
1985
+            $nb=$db->affected_rows($sql);
1986
+            if ($nb > 0)
1987
+            {
1988
+                // Removed orphelins records
1989
+                print '<br>Some records were detected to have parent that is a child, we set them as root record for id: ';
1990
+                print join(',',$listofidtoclean);
1991
+            }
1992
+
1993
+            $totalnb+=$nb;
1994
+        }
1995
+        //else dol_print_error($db);
1996
+
1997
+        // Check and clean orphelins
1998
+        $sql = "UPDATE ".MAIN_DB_PREFIX.$tabletocleantree;
1999
+        $sql.= " SET ".$fieldfkparent." = 0";
2000
+        $sql.= " WHERE ".$fieldfkparent." NOT IN (".join(',',$listofid).")";	// So we update only records linked to a non existing parent
2001
+        $resql = $db->query($sql);
2002
+        if ($resql)
2003
+        {
2004
+            $nb=$db->affected_rows($sql);
2005
+            if ($nb > 0)
2006
+            {
2007
+                // Removed orphelins records
2008
+                print '<br>Some orphelins were found and modified to be parent so records are visible again for id: ';
2009
+                print join(',',$listofid);
2010
+            }
2011
+
2012
+            $totalnb+=$nb;
2013
+        }
2014
+        //else dol_print_error($db);
2015
+
2016
+        print '<br>We fixed '.$totalnb.' record(s). Some records may still be corrupted. New check may be required.';
2017
+        return $totalnb;
2018
+    }
2019 2019
 }
2020 2020
 
2021 2021
 /**
@@ -2147,21 +2147,21 @@  discard block
 block discarded – undo
2147 2147
 function fetchObjectByElement($element_id, $element_type, $element_ref='')
2148 2148
 {
2149 2149
     global $conf;
2150
-	global $db,$conf;
2150
+    global $db,$conf;
2151 2151
 
2152 2152
     $element_prop = getElementProperties($element_type);
2153 2153
     if (is_array($element_prop) && $conf->{$element_prop['module']}->enabled)
2154 2154
     {
2155 2155
         dol_include_once('/'.$element_prop['classpath'].'/'.$element_prop['classfile'].'.class.php');
2156 2156
 
2157
-		$objecttmp = new $element_prop['classname']($db);
2158
-		$ret = $objecttmp->fetch($element_id, $element_ref);
2159
-		if ($ret >= 0)
2160
-		{
2161
-			return $objecttmp;
2162
-		}
2163
-	}
2164
-	return 0;
2157
+        $objecttmp = new $element_prop['classname']($db);
2158
+        $ret = $objecttmp->fetch($element_id, $element_ref);
2159
+        if ($ret >= 0)
2160
+        {
2161
+            return $objecttmp;
2162
+        }
2163
+    }
2164
+    return 0;
2165 2165
 }
2166 2166
 
2167 2167
 
@@ -2176,9 +2176,9 @@  discard block
 block discarded – undo
2176 2176
  */
2177 2177
 function colorArrayToHex($arraycolor,$colorifnotfound='888888')
2178 2178
 {
2179
-	if (! is_array($arraycolor)) return $colorifnotfound;
2180
-	if (empty($arraycolor)) return $colorifnotfound;
2181
-	return sprintf("%02s",dechex($arraycolor[0])).sprintf("%02s",dechex($arraycolor[1])).sprintf("%02s",dechex($arraycolor[2]));
2179
+    if (! is_array($arraycolor)) return $colorifnotfound;
2180
+    if (empty($arraycolor)) return $colorifnotfound;
2181
+    return sprintf("%02s",dechex($arraycolor[0])).sprintf("%02s",dechex($arraycolor[1])).sprintf("%02s",dechex($arraycolor[2]));
2182 2182
 }
2183 2183
 
2184 2184
 /**
@@ -2193,15 +2193,15 @@  discard block
 block discarded – undo
2193 2193
  */
2194 2194
 static function colorStringToArray($stringcolor, $colorifnotfound = array(88, 88, 88))
2195 2195
     {
2196
-	if (is_array($stringcolor)) return $stringcolor;	// If already into correct output format, we return as is
2197
-	$tmp=preg_match('/^#?([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])$/',$stringcolor,$reg);
2198
-	if (! $tmp)
2199
-	{
2200
-		$tmp=explode(',',$stringcolor);
2201
-		if (count($tmp) < 3) return $colorifnotfound;
2202
-		return $tmp;
2203
-	}
2204
-	return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
2196
+    if (is_array($stringcolor)) return $stringcolor;	// If already into correct output format, we return as is
2197
+    $tmp=preg_match('/^#?([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])$/',$stringcolor,$reg);
2198
+    if (! $tmp)
2199
+    {
2200
+        $tmp=explode(',',$stringcolor);
2201
+        if (count($tmp) < 3) return $colorifnotfound;
2202
+        return $tmp;
2203
+    }
2204
+    return array(hexdec($reg[1]),hexdec($reg[2]),hexdec($reg[3]));
2205 2205
 }
2206 2206
 
2207 2207
 /**
@@ -2247,7 +2247,7 @@  discard block
 block discarded – undo
2247 2247
     if ($moduledirforclass != 'api') $moduledirforclass = preg_replace('/api$/i','',$moduledirforclass);
2248 2248
 
2249 2249
     if ($module == 'contracts') {
2250
-    	$moduledirforclass = 'contrat';
2250
+        $moduledirforclass = 'contrat';
2251 2251
     }
2252 2252
     elseif (in_array($module, array('admin', 'login', 'setup', 'access', 'status', 'tools', 'documents'))) {
2253 2253
         $moduledirforclass = 'api';
@@ -2274,7 +2274,7 @@  discard block
 block discarded – undo
2274 2274
         $moduledirforclass = 'commande';
2275 2275
     }
2276 2276
     elseif ($module == 'shipments') {
2277
-    	$moduledirforclass = 'expedition';
2277
+        $moduledirforclass = 'expedition';
2278 2278
     }
2279 2279
     elseif ($module == 'facture' || $module == 'invoice' || $module == 'invoices') {
2280 2280
         $moduledirforclass = 'compta/facture';
@@ -2292,7 +2292,7 @@  discard block
 block discarded – undo
2292 2292
         $moduledirforclass = 'product/stock';
2293 2293
     }
2294 2294
     elseif ($module == 'supplierproposals' || $module == 'supplierproposal' || $module == 'supplier_proposal') {
2295
-    	$moduledirforclass = 'supplier_proposal';
2295
+        $moduledirforclass = 'supplier_proposal';
2296 2296
     }
2297 2297
     elseif ($module == 'fournisseur' || $module == 'supplierinvoices' || $module == 'supplierorders') {
2298 2298
         $moduledirforclass = 'fourn';
@@ -2304,10 +2304,10 @@  discard block
 block discarded – undo
2304 2304
         $moduledirforclass = 'user';
2305 2305
     }
2306 2306
     elseif ($module == 'ficheinter' || $module == 'interventions') {
2307
-    	$moduledirforclass = 'fichinter';
2307
+        $moduledirforclass = 'fichinter';
2308 2308
     }
2309 2309
     elseif ($module == 'tickets') {
2310
-    	$moduledirforclass = 'ticket';
2310
+        $moduledirforclass = 'ticket';
2311 2311
     }
2312 2312
 
2313 2313
     return $moduledirforclass;
Please login to merge, or discard this patch.
Helpers/NoValeConfig.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 {
58 58
     $db=getDoliDBInstance($conf->db->type,$conf->db->host,$conf->db->user,$conf->db->pass,$conf->db->name,$conf->db->port);
59 59
 
60
-	if ($db->error)
61
-	{
62
-		dol_print_error($db,"host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
63
-		exit;
64
-	}
60
+    if ($db->error)
61
+    {
62
+        dol_print_error($db,"host=".$conf->db->host.", port=".$conf->db->port.", user=".$conf->db->user.", databasename=".$conf->db->name.", ".$db->error);
63
+        exit;
64
+    }
65 65
 }
66 66
 
67 67
 // Now database connexion is known, so we can forget password
@@ -80,19 +80,19 @@  discard block
 block discarded – undo
80 80
 // By default conf->entity is 1, but we change this if we ask another value.
81 81
 if (session_id() && ! empty($_SESSION["dol_entity"]))			// Entity inside an opened session
82 82
 {
83
-	$conf->entity = $_SESSION["dol_entity"];
83
+    $conf->entity = $_SESSION["dol_entity"];
84 84
 }
85 85
 else if (! empty($_ENV["dol_entity"]))							// Entity inside a CLI script
86 86
 {
87
-	$conf->entity = $_ENV["dol_entity"];
87
+    $conf->entity = $_ENV["dol_entity"];
88 88
 }
89 89
 else if (isset($_POST["loginfunction"]) && GETPOST("entity",'int'))	// Just after a login page
90 90
 {
91
-	$conf->entity = GETPOST("entity",'int');
91
+    $conf->entity = GETPOST("entity",'int');
92 92
 }
93 93
 else if (defined('DOLENTITY') && is_numeric(DOLENTITY))			// For public page with MultiCompany module
94 94
 {
95
-	$conf->entity = DOLENTITY;
95
+    $conf->entity = DOLENTITY;
96 96
 }
97 97
 
98 98
 // Sanitize entity
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
 
101 101
 if (! defined('NOREQUIREDB'))
102 102
 {
103
-	//print "Will work with data into entity instance number '".$conf->entity."'";
103
+    //print "Will work with data into entity instance number '".$conf->entity."'";
104 104
 
105
-	// Here we read database (llx_const table) and define $conf->global->XXX var.
106
-	$conf->setValues($db);
105
+    // Here we read database (llx_const table) and define $conf->global->XXX var.
106
+    $conf->setValues($db);
107 107
 }
108 108
 
109 109
 // Overwrite database value
110 110
 if (! empty($conf->file->mailing_limit_sendbyweb))
111 111
 {
112
-	$conf->global->MAILING_LIMIT_SENDBYWEB = $conf->file->mailing_limit_sendbyweb;
112
+    $conf->global->MAILING_LIMIT_SENDBYWEB = $conf->file->mailing_limit_sendbyweb;
113 113
 }
114 114
 if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
115 115
 {
@@ -127,41 +127,41 @@  discard block
 block discarded – undo
127 127
 // If software has been locked. Only login $conf->global->MAIN_ONLY_LOGIN_ALLOWED is allowed.
128 128
 if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
129 129
 {
130
-	$ok=0;
131
-	if ((! session_id() || ! isset($_SESSION["dol_login"])) && ! isset($_POST["username"]) && ! empty($_SERVER["GATEWAY_INTERFACE"])) $ok=1;	// We let working pages if not logged and inside a web browser (login form, to allow login by admin)
132
-	elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1;				// We let working pages that is a login submission (login submit, to allow login by admin)
133
-	elseif (defined('NOREQUIREDB'))   $ok=1;				// We let working pages that don't need database access (xxx.css.php)
134
-	elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) $ok=1;	// We let working pages that ask to work even if only login enabled (logout.php)
135
-	elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1;	// We let working if user is allowed admin
136
-	if (! $ok)
137
-	{
138
-		if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED)
139
-		{
140
-			print 'Sorry, your application is offline.'."\n";
141
-			print 'You are logged with user "'.$_SESSION["dol_login"].'" and only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
142
-			$nexturl=DOL_URL_ROOT.'/user/logout.php';
143
-			print 'Please try later or <a href="'.$nexturl.'">click here to disconnect and change login user</a>...'."\n";
144
-		}
145
-		else
146
-		{
147
-			print 'Sorry, your application is offline. Only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
148
-			$nexturl=DOL_URL_ROOT.'/';
149
-			print 'Please try later or <a href="'.$nexturl.'">click here to change login user</a>...'."\n";
150
-		}
151
-		exit;
152
-	}
130
+    $ok=0;
131
+    if ((! session_id() || ! isset($_SESSION["dol_login"])) && ! isset($_POST["username"]) && ! empty($_SERVER["GATEWAY_INTERFACE"])) $ok=1;	// We let working pages if not logged and inside a web browser (login form, to allow login by admin)
132
+    elseif (isset($_POST["username"]) && $_POST["username"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1;				// We let working pages that is a login submission (login submit, to allow login by admin)
133
+    elseif (defined('NOREQUIREDB'))   $ok=1;				// We let working pages that don't need database access (xxx.css.php)
134
+    elseif (defined('EVEN_IF_ONLY_LOGIN_ALLOWED')) $ok=1;	// We let working pages that ask to work even if only login enabled (logout.php)
135
+    elseif (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] == $conf->global->MAIN_ONLY_LOGIN_ALLOWED) $ok=1;	// We let working if user is allowed admin
136
+    if (! $ok)
137
+    {
138
+        if (session_id() && isset($_SESSION["dol_login"]) && $_SESSION["dol_login"] != $conf->global->MAIN_ONLY_LOGIN_ALLOWED)
139
+        {
140
+            print 'Sorry, your application is offline.'."\n";
141
+            print 'You are logged with user "'.$_SESSION["dol_login"].'" and only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
142
+            $nexturl=DOL_URL_ROOT.'/user/logout.php';
143
+            print 'Please try later or <a href="'.$nexturl.'">click here to disconnect and change login user</a>...'."\n";
144
+        }
145
+        else
146
+        {
147
+            print 'Sorry, your application is offline. Only administrator user "'.$conf->global->MAIN_ONLY_LOGIN_ALLOWED.'" is allowed to connect for the moment.'."\n";
148
+            $nexturl=DOL_URL_ROOT.'/';
149
+            print 'Please try later or <a href="'.$nexturl.'">click here to change login user</a>...'."\n";
150
+        }
151
+        exit;
152
+    }
153 153
 }
154 154
 
155 155
 // Create object $mysoc (A thirdparty object that contains properties of companies managed by Dolibarr.
156 156
 if (! defined('NOREQUIREDB') && ! defined('NOREQUIRESOC'))
157 157
 {
158
-	require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php';
158
+    require_once DOL_DOCUMENT_ROOT .'/societe/class/societe.class.php';
159 159
 
160
-	$mysoc=new Societe($db);
161
-	$mysoc->setMysoc($conf);
160
+    $mysoc=new Societe($db);
161
+    $mysoc->setMysoc($conf);
162 162
 
163
-	// For some countries, we need to invert our address with customer address
164
-	if ($mysoc->country_code == 'DE' && ! isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT=1;
163
+    // For some countries, we need to invert our address with customer address
164
+    if ($mysoc->country_code == 'DE' && ! isset($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $conf->global->MAIN_INVERT_SENDER_RECIPIENT=1;
165 165
 }
166 166
 
167 167
 
Please login to merge, or discard this patch.
Helpers/login/functions_ldap.php 1 patch
Indentation   +195 added lines, -195 removed lines patch added patch discarded remove patch
@@ -34,190 +34,190 @@  discard block
 block discarded – undo
34 34
  */
35 35
 function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest)
36 36
 {
37
-	global $db,$conf,$langs;
38
-	global $_POST;
39
-	global $dolibarr_main_auth_ldap_host,$dolibarr_main_auth_ldap_port;
40
-	global $dolibarr_main_auth_ldap_version,$dolibarr_main_auth_ldap_servertype;
41
-	global $dolibarr_main_auth_ldap_login_attribute,$dolibarr_main_auth_ldap_dn;
42
-	global $dolibarr_main_auth_ldap_admin_login,$dolibarr_main_auth_ldap_admin_pass;
43
-	global $dolibarr_main_auth_ldap_filter;
44
-	global $dolibarr_main_auth_ldap_debug;
45
-
46
-	// Force master entity in transversal mode
47
-	$entity=$entitytotest;
48
-	if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1;
49
-
50
-	$login='';
51
-	$resultFetchUser='';
52
-
53
-	if (! function_exists("ldap_connect"))
54
-	{
55
-		dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP. LDAP functions are disabled on this PHP");
56
-		sleep(1);
57
-
58
-		// Load translation files required by the page
37
+    global $db,$conf,$langs;
38
+    global $_POST;
39
+    global $dolibarr_main_auth_ldap_host,$dolibarr_main_auth_ldap_port;
40
+    global $dolibarr_main_auth_ldap_version,$dolibarr_main_auth_ldap_servertype;
41
+    global $dolibarr_main_auth_ldap_login_attribute,$dolibarr_main_auth_ldap_dn;
42
+    global $dolibarr_main_auth_ldap_admin_login,$dolibarr_main_auth_ldap_admin_pass;
43
+    global $dolibarr_main_auth_ldap_filter;
44
+    global $dolibarr_main_auth_ldap_debug;
45
+
46
+    // Force master entity in transversal mode
47
+    $entity=$entitytotest;
48
+    if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1;
49
+
50
+    $login='';
51
+    $resultFetchUser='';
52
+
53
+    if (! function_exists("ldap_connect"))
54
+    {
55
+        dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP. LDAP functions are disabled on this PHP");
56
+        sleep(1);
57
+
58
+        // Load translation files required by the page
59 59
         $langs->loadLangs(array('main', 'other'));
60 60
 
61
-		$_SESSION["dol_loginmesg"]=$langs->trans("ErrorLDAPFunctionsAreDisabledOnThisPHP").' '.$langs->trans("TryAnotherConnectionMode");
62
-		return;
63
-	}
64
-
65
-	if ($usertotest)
66
-	{
67
-		dol_syslog("functions_ldap::check_user_password_ldap usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest);
68
-
69
-		// If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko
70
-		$ldaphost=$dolibarr_main_auth_ldap_host;
71
-		$ldapport=$dolibarr_main_auth_ldap_port;
72
-		$ldapversion=$dolibarr_main_auth_ldap_version;
73
-		$ldapservertype=(empty($dolibarr_main_auth_ldap_servertype) ? 'openldap' : $dolibarr_main_auth_ldap_servertype);
74
-
75
-		$ldapuserattr=$dolibarr_main_auth_ldap_login_attribute;
76
-		$ldapdn=$dolibarr_main_auth_ldap_dn;
77
-		$ldapadminlogin=$dolibarr_main_auth_ldap_admin_login;
78
-		$ldapadminpass=$dolibarr_main_auth_ldap_admin_pass;
79
-		$ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true);
80
-
81
-		if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n";
82
-
83
-		require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
84
-		$ldap=new Ldap();
85
-		$ldap->server=explode(',',$ldaphost);
86
-		$ldap->serverPort=$ldapport;
87
-		$ldap->ldapProtocolVersion=$ldapversion;
88
-		$ldap->serverType=$ldapservertype;
89
-		$ldap->searchUser=$ldapadminlogin;
90
-		$ldap->searchPassword=$ldapadminpass;
91
-
92
-		if ($ldapdebug)
93
-		{
94
-			dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType);
95
-			dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword);
96
-			print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n";
97
-			print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."<br>\n";
98
-		}
99
-
100
-		$resultFetchLdapUser=0;
101
-
102
-		// Define $userSearchFilter
103
-		$userSearchFilter = "";
104
-		if (empty($dolibarr_main_auth_ldap_filter)) {
105
-			$userSearchFilter = "(" . $ldapuserattr . "=" . $usertotest . ")";
106
-		} else {
107
-			$userSearchFilter = str_replace('%1%', $usertotest, $dolibarr_main_auth_ldap_filter);
108
-		}
109
-
110
-		// If admin login provided
111
-		// Code to get user in LDAP from an admin connection (may differ from user connection, done later)
112
-		if ($ldapadminlogin)
113
-		{
114
-			$result=$ldap->connect_bind();
115
-			if ($result > 0)
116
-			{
117
-				$resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter);
118
-				//dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser);
119
-				if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset
120
-				{
121
-					dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon');
122
-					if ($ldapdebug) print "DEBUG: User ".$usertotest." must change password<br>\n";
123
-					$ldap->close();
124
-					sleep(1);
125
-					$langs->load('ldap');
126
-					$_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN);
127
-					return '';
128
-				}
129
-			}
130
-			else
131
-			{
132
-				 if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n";
133
-			}
134
-			$ldap->close();
135
-		}
136
-
137
-		// Forge LDAP user and password to test with them
138
-		// If LDAP need a dn with login like "uid=jbloggs,ou=People,dc=foo,dc=com", default dn may work even if previous code with
139
-		// admin login no exectued.
140
-		$ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn;  // Default dn (will work if LDAP accept a dn with login value inside)
141
-		// But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have
142
-		// dn detected into ldapUserDN.
143
-		if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN;
144
-		$ldap->searchPassword=$passwordtotest;
145
-
146
-		// Test with this->seachUser and this->searchPassword
147
-		//print $resultFetchLdapUser."-".$ldap->ldapUserDN."-".$ldap->searchUser.'-'.$ldap->searchPassword;exit;
148
-		$result=$ldap->connect_bind();
149
-		if ($result > 0)
150
-		{
151
-			if ($result == 2)	// Connection is ok for user/pass into LDAP
152
-			{
153
-				dol_syslog("functions_ldap::check_user_password_ldap Authentification ok");
154
-				$login=$usertotest;
155
-
156
-				// ldap2dolibarr synchronisation
157
-				if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')	// ldap2dolibarr synchronisation
158
-				{
159
-						dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr");
160
-
161
-						// On charge les attributs du user ldap
162
-						if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n";
163
-						$resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter);
164
-
165
-						if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n";
166
-						if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n";
167
-						if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n";
168
-
169
-						// On recherche le user dolibarr en fonction de son SID ldap
170
-						$sid = $ldap->getObjectSid($login);
171
-						if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n";
172
-
173
-						$usertmp=new User($db);
174
-						$resultFetchUser=$usertmp->fetch('',$login,$sid);
175
-						if ($resultFetchUser > 0)
176
-						{
177
-							dol_syslog("functions_ldap::check_user_password_ldap Sync user found user id=".$usertmp->id);
178
-							// On verifie si le login a change et on met a jour les attributs dolibarr
179
-
180
-							if ($usertmp->login != $ldap->login && $ldap->login)
181
-							{
182
-								$usertmp->login = $ldap->login;
183
-								$usertmp->update($usertmp);
184
-								// TODO Que faire si update echoue car on update avec un login deja existant.
185
-							}
186
-
187
-							//$resultUpdate = $usertmp->update_ldap2dolibarr($ldap);
188
-						}
189
-						unset($usertmp);
190
-				}
191
-
192
-				if (! empty($conf->multicompany->enabled))	// We must check entity (even if sync is not active)
193
-				{
194
-					global $mc;
195
-
196
-					$usertmp=new User($db);
197
-					$usertmp->fetch('',$login);
198
-					$ret=$mc->checkRight($usertmp->id, $entitytotest);
199
-					if ($ret < 0)
200
-					{
201
-						dol_syslog("functions_ldap::check_user_password_ldap Authentification ko entity '".$entitytotest."' not allowed for user '".$usertmp->id."'");
202
-						$login=''; // force authentication failure
203
-					}
204
-					unset($usertmp);
205
-				}
206
-			}
207
-			if ($result == 1)
208
-			{
209
-				dol_syslog("functions_ldap::check_user_password_ldap Authentification ko bad user/password for '".$usertotest."'");
210
-				sleep(1);
211
-
212
-				// Load translation files required by the page
61
+        $_SESSION["dol_loginmesg"]=$langs->trans("ErrorLDAPFunctionsAreDisabledOnThisPHP").' '.$langs->trans("TryAnotherConnectionMode");
62
+        return;
63
+    }
64
+
65
+    if ($usertotest)
66
+    {
67
+        dol_syslog("functions_ldap::check_user_password_ldap usertotest=".$usertotest." passwordtotest=".preg_replace('/./','*',$passwordtotest)." entitytotest=".$entitytotest);
68
+
69
+        // If test username/password asked, we define $test=false and $login var if ok, set $_SESSION["dol_loginmesg"] if ko
70
+        $ldaphost=$dolibarr_main_auth_ldap_host;
71
+        $ldapport=$dolibarr_main_auth_ldap_port;
72
+        $ldapversion=$dolibarr_main_auth_ldap_version;
73
+        $ldapservertype=(empty($dolibarr_main_auth_ldap_servertype) ? 'openldap' : $dolibarr_main_auth_ldap_servertype);
74
+
75
+        $ldapuserattr=$dolibarr_main_auth_ldap_login_attribute;
76
+        $ldapdn=$dolibarr_main_auth_ldap_dn;
77
+        $ldapadminlogin=$dolibarr_main_auth_ldap_admin_login;
78
+        $ldapadminpass=$dolibarr_main_auth_ldap_admin_pass;
79
+        $ldapdebug=(empty($dolibarr_main_auth_ldap_debug) || $dolibarr_main_auth_ldap_debug=="false" ? false : true);
80
+
81
+        if ($ldapdebug) print "DEBUG: Logging LDAP steps<br>\n";
82
+
83
+        require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
84
+        $ldap=new Ldap();
85
+        $ldap->server=explode(',',$ldaphost);
86
+        $ldap->serverPort=$ldapport;
87
+        $ldap->ldapProtocolVersion=$ldapversion;
88
+        $ldap->serverType=$ldapservertype;
89
+        $ldap->searchUser=$ldapadminlogin;
90
+        $ldap->searchPassword=$ldapadminpass;
91
+
92
+        if ($ldapdebug)
93
+        {
94
+            dol_syslog("functions_ldap::check_user_password_ldap Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType);
95
+            dol_syslog("functions_ldap::check_user_password_ldap uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword);
96
+            print "DEBUG: Server:".join(',',$ldap->server).", Port:".$ldap->serverPort.", Protocol:".$ldap->ldapProtocolVersion.", Type:".$ldap->serverType."<br>\n";
97
+            print "DEBUG: uid/samacountname=".$ldapuserattr.", dn=".$ldapdn.", Admin:".$ldap->searchUser.", Pass:".$ldap->searchPassword."<br>\n";
98
+        }
99
+
100
+        $resultFetchLdapUser=0;
101
+
102
+        // Define $userSearchFilter
103
+        $userSearchFilter = "";
104
+        if (empty($dolibarr_main_auth_ldap_filter)) {
105
+            $userSearchFilter = "(" . $ldapuserattr . "=" . $usertotest . ")";
106
+        } else {
107
+            $userSearchFilter = str_replace('%1%', $usertotest, $dolibarr_main_auth_ldap_filter);
108
+        }
109
+
110
+        // If admin login provided
111
+        // Code to get user in LDAP from an admin connection (may differ from user connection, done later)
112
+        if ($ldapadminlogin)
113
+        {
114
+            $result=$ldap->connect_bind();
115
+            if ($result > 0)
116
+            {
117
+                $resultFetchLdapUser = $ldap->fetch($usertotest,$userSearchFilter);
118
+                //dol_syslog('functions_ldap::check_user_password_ldap resultFetchLdapUser='.$resultFetchLdapUser);
119
+                if ($resultFetchLdapUser > 0 && $ldap->pwdlastset == 0) // If ok but password need to be reset
120
+                {
121
+                    dol_syslog('functions_ldap::check_user_password_ldap '.$usertotest.' must change password next logon');
122
+                    if ($ldapdebug) print "DEBUG: User ".$usertotest." must change password<br>\n";
123
+                    $ldap->close();
124
+                    sleep(1);
125
+                    $langs->load('ldap');
126
+                    $_SESSION["dol_loginmesg"]=$langs->trans("YouMustChangePassNextLogon",$usertotest,$ldap->domainFQDN);
127
+                    return '';
128
+                }
129
+            }
130
+            else
131
+            {
132
+                    if ($ldapdebug) print "DEBUG: ".$ldap->error."<br>\n";
133
+            }
134
+            $ldap->close();
135
+        }
136
+
137
+        // Forge LDAP user and password to test with them
138
+        // If LDAP need a dn with login like "uid=jbloggs,ou=People,dc=foo,dc=com", default dn may work even if previous code with
139
+        // admin login no exectued.
140
+        $ldap->searchUser=$ldapuserattr."=".$usertotest.",".$ldapdn;  // Default dn (will work if LDAP accept a dn with login value inside)
141
+        // But if LDAP need a dn with name like "cn=Jhon Bloggs,ou=People,dc=foo,dc=com", previous part must have been executed to have
142
+        // dn detected into ldapUserDN.
143
+        if ($resultFetchLdapUser && !empty($ldap->ldapUserDN)) $ldap->searchUser = $ldap->ldapUserDN;
144
+        $ldap->searchPassword=$passwordtotest;
145
+
146
+        // Test with this->seachUser and this->searchPassword
147
+        //print $resultFetchLdapUser."-".$ldap->ldapUserDN."-".$ldap->searchUser.'-'.$ldap->searchPassword;exit;
148
+        $result=$ldap->connect_bind();
149
+        if ($result > 0)
150
+        {
151
+            if ($result == 2)	// Connection is ok for user/pass into LDAP
152
+            {
153
+                dol_syslog("functions_ldap::check_user_password_ldap Authentification ok");
154
+                $login=$usertotest;
155
+
156
+                // ldap2dolibarr synchronisation
157
+                if ($login && ! empty($conf->ldap->enabled) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr')	// ldap2dolibarr synchronisation
158
+                {
159
+                        dol_syslog("functions_ldap::check_user_password_ldap Sync ldap2dolibarr");
160
+
161
+                        // On charge les attributs du user ldap
162
+                        if ($ldapdebug) print "DEBUG: login ldap = ".$login."<br>\n";
163
+                        $resultFetchLdapUser = $ldap->fetch($login,$userSearchFilter);
164
+
165
+                        if ($ldapdebug) print "DEBUG: UACF = ".join(',',$ldap->uacf)."<br>\n";
166
+                        if ($ldapdebug) print "DEBUG: pwdLastSet = ".dol_print_date($ldap->pwdlastset,'day')."<br>\n";
167
+                        if ($ldapdebug) print "DEBUG: badPasswordTime = ".dol_print_date($ldap->badpwdtime,'day')."<br>\n";
168
+
169
+                        // On recherche le user dolibarr en fonction de son SID ldap
170
+                        $sid = $ldap->getObjectSid($login);
171
+                        if ($ldapdebug) print "DEBUG: sid = ".$sid."<br>\n";
172
+
173
+                        $usertmp=new User($db);
174
+                        $resultFetchUser=$usertmp->fetch('',$login,$sid);
175
+                        if ($resultFetchUser > 0)
176
+                        {
177
+                            dol_syslog("functions_ldap::check_user_password_ldap Sync user found user id=".$usertmp->id);
178
+                            // On verifie si le login a change et on met a jour les attributs dolibarr
179
+
180
+                            if ($usertmp->login != $ldap->login && $ldap->login)
181
+                            {
182
+                                $usertmp->login = $ldap->login;
183
+                                $usertmp->update($usertmp);
184
+                                // TODO Que faire si update echoue car on update avec un login deja existant.
185
+                            }
186
+
187
+                            //$resultUpdate = $usertmp->update_ldap2dolibarr($ldap);
188
+                        }
189
+                        unset($usertmp);
190
+                }
191
+
192
+                if (! empty($conf->multicompany->enabled))	// We must check entity (even if sync is not active)
193
+                {
194
+                    global $mc;
195
+
196
+                    $usertmp=new User($db);
197
+                    $usertmp->fetch('',$login);
198
+                    $ret=$mc->checkRight($usertmp->id, $entitytotest);
199
+                    if ($ret < 0)
200
+                    {
201
+                        dol_syslog("functions_ldap::check_user_password_ldap Authentification ko entity '".$entitytotest."' not allowed for user '".$usertmp->id."'");
202
+                        $login=''; // force authentication failure
203
+                    }
204
+                    unset($usertmp);
205
+                }
206
+            }
207
+            if ($result == 1)
208
+            {
209
+                dol_syslog("functions_ldap::check_user_password_ldap Authentification ko bad user/password for '".$usertotest."'");
210
+                sleep(1);
211
+
212
+                // Load translation files required by the page
213 213
                 $langs->loadLangs(array('main', 'other'));
214 214
 
215
-				$_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword");
216
-			}
217
-		}
218
-		else
219
-		{
220
-			/* Login failed. Return false, together with the error code and text from
215
+                $_SESSION["dol_loginmesg"]=$langs->trans("ErrorBadLoginPassword");
216
+            }
217
+        }
218
+        else
219
+        {
220
+            /* Login failed. Return false, together with the error code and text from
221 221
              ** the LDAP server. The common error codes and reasons are listed below :
222 222
              ** (for iPlanet, other servers may differ)
223 223
              ** 19 - Account locked out (too many invalid login attempts)
@@ -225,24 +225,24 @@  discard block
 block discarded – undo
225 225
              ** 49 - Wrong password
226 226
              ** 53 - Account inactive (manually locked out by administrator)
227 227
              */
228
-			dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'");
229
-			if (is_resource($ldap->connection))    // If connection ok but bind ko
230
-			{
231
-				$ldap->ldapErrorCode = ldap_errno($ldap->connection);
232
-				$ldap->ldapErrorText = ldap_error($ldap->connection);
233
-				dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText);
234
-			}
235
-			sleep(2);      // Anti brut force protection
236
-
237
-			// Load translation files required by the page
228
+            dol_syslog("functions_ldap::check_user_password_ldap Authentification ko failed to connect to LDAP for '".$usertotest."'");
229
+            if (is_resource($ldap->connection))    // If connection ok but bind ko
230
+            {
231
+                $ldap->ldapErrorCode = ldap_errno($ldap->connection);
232
+                $ldap->ldapErrorText = ldap_error($ldap->connection);
233
+                dol_syslog("functions_ldap::check_user_password_ldap ".$ldap->ldapErrorCode." ".$ldap->ldapErrorText);
234
+            }
235
+            sleep(2);      // Anti brut force protection
236
+
237
+            // Load translation files required by the page
238 238
             $langs->loadLangs(array('main', 'other', 'errors'));
239 239
 ;
240
-			$_SESSION["dol_loginmesg"]=($ldap->error?$ldap->error:$langs->trans("ErrorBadLoginPassword"));
241
-		}
240
+            $_SESSION["dol_loginmesg"]=($ldap->error?$ldap->error:$langs->trans("ErrorBadLoginPassword"));
241
+        }
242 242
 
243
-		$ldap->close();
244
-	}
243
+        $ldap->close();
244
+    }
245 245
 
246
-	return $login;
246
+    return $login;
247 247
 }
248 248
 
Please login to merge, or discard this patch.
Helpers/login/functions_forceuser.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,16 +34,16 @@
 block discarded – undo
34 34
  */
35 35
 function check_user_password_forceuser($usertotest,$passwordtotest,$entitytotest)
36 36
 {
37
-	// Variable dolibarr_auto_user must be defined in conf.php file
38
-	global $dolibarr_auto_user;
37
+    // Variable dolibarr_auto_user must be defined in conf.php file
38
+    global $dolibarr_auto_user;
39 39
 
40
-	dol_syslog("functions_forceuser::check_user_password_forceuser");
40
+    dol_syslog("functions_forceuser::check_user_password_forceuser");
41 41
 
42
-	$login=$dolibarr_auto_user;
43
-	if (empty($login)) $login='auto';
42
+    $login=$dolibarr_auto_user;
43
+    if (empty($login)) $login='auto';
44 44
 
45
-	if ($_SESSION["dol_loginmesg"]) $login='';
45
+    if ($_SESSION["dol_loginmesg"]) $login='';
46 46
 
47
-	dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login);
48
-	return $login;
47
+    dol_syslog("functions_forceuser::check_user_password_forceuser ok. forced user = ".$login);
48
+    return $login;
49 49
 }
Please login to merge, or discard this patch.
Helpers/login/functions_http.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -12,13 +12,13 @@
 block discarded – undo
12 12
 */
13 13
 function check_user_password_http($usertotest,$passwordtotest,$entitytotest)
14 14
 {
15
-	DolUtils::dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=" . (empty($_SERVER["REMOTE_USER"]) ? '' : $_SERVER["REMOTE_USER"]));
15
+    DolUtils::dol_syslog("functions_http::check_user_password_http _SERVER[REMOTE_USER]=" . (empty($_SERVER["REMOTE_USER"]) ? '' : $_SERVER["REMOTE_USER"]));
16 16
 
17 17
     $login='';
18
-	if (! empty($_SERVER["REMOTE_USER"]))
19
-	{
20
-		$login=$_SERVER["REMOTE_USER"];
21
-	}
18
+    if (! empty($_SERVER["REMOTE_USER"]))
19
+    {
20
+        $login=$_SERVER["REMOTE_USER"];
21
+    }
22 22
 
23
-	return $login;
23
+    return $login;
24 24
 }
Please login to merge, or discard this patch.
Helpers/login/functions_empty.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@
 block discarded – undo
33 33
  */
34 34
 function check_user_password_empty($usertotest,$passwordtotest,$entitytotest)
35 35
 {
36
-	global $langs;
36
+    global $langs;
37 37
 
38
-	dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest);
38
+    dol_syslog("functions_empty::check_user_password_empty usertotest=".$usertotest);
39 39
 
40
-	$login='';
41
-	$_SESSION["dol_loginmesg"]=$langs->trans("FailedToLogin");
40
+    $login='';
41
+    $_SESSION["dol_loginmesg"]=$langs->trans("FailedToLogin");
42 42
 
43
-	return $login;
43
+    return $login;
44 44
 }
Please login to merge, or discard this patch.
Helpers/DolUtils.php 1 patch
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
      */
259 259
     static function dol_shutdown()
260 260
     {
261
-       // global Globals::$conf, $user, $langs, $db;
261
+        // global Globals::$conf, $user, $langs, $db;
262 262
         $disconnectdone = false;
263 263
         $depth = 0;
264 264
         if (is_object($db) && !empty($db->connected)) {
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
      */
306 306
     static function GETPOST($paramname, $check = 'none', $method = 0, $filter = null, $options = null, $noreplace = 0)
307 307
     {
308
-       // global $mysoc, $user, Globals::$conf;
308
+        // global $mysoc, $user, Globals::$conf;
309 309
 
310 310
         if (empty($paramname))
311 311
             return 'BadFirstParameterForDolUtils::GETPOST';
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
             elseif (!isset($_GET['sortfield'])) { // If we did a click on a field to sort, we do no apply default values. Same if option MAIN_ENABLE_DEFAULT_VALUES is not set
365 365
                 if (!empty($_GET['action']) && $_GET['action'] == 'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
366 366
                     // Search default value from $object->field
367
-                   // global $object;
367
+                    // global $object;
368 368
                     if (is_object($object) && isset($object->fields[$paramname]['default'])) {
369 369
                         $out = $object->fields[$paramname]['default'];
370 370
                     }
@@ -707,7 +707,7 @@  discard block
 block discarded – undo
707 707
      */
708 708
     static function dol_include_once($relpath, $classname = '')
709 709
     {
710
-       // global Globals::$conf, $langs, $user, $mysoc;   // Do not remove this. They must be defined for files we include. Other globals var must be retreived with $GLOBALS['var']
710
+        // global Globals::$conf, $langs, $user, $mysoc;   // Do not remove this. They must be defined for files we include. Other globals var must be retreived with $GLOBALS['var']
711 711
 
712 712
         $fullpath = dol_buildpath($relpath);
713 713
 
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
      */
736 736
     static function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
737 737
     {
738
-       // global Globals::$conf;
738
+        // global Globals::$conf;
739 739
 
740 740
         $path = preg_replace('/^\//', '', $path);
741 741
 
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
             foreach (Globals::$conf->file->dol_document_root as $key => $dirroot) { // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...)
778 778
                 if ($key == 'main') {
779 779
                     if ($type == 3) {
780
-                       // global $dolibarr_main_url_root;
780
+                        // global $dolibarr_main_url_root;
781 781
                         // Define $urlwithroot
782 782
 
783 783
                         // $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_BASE_URI, '/') . '$/i', '', trim($dolibarr_main_url_root));
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
                             $res = (preg_match('/^http/i', Globals::$conf->file->dol_url_root[$key]) ? '' : DOL_MAIN_URL_ROOT) . Globals::$conf->file->dol_url_root[$key] . '/' . $path;
802 802
                         }
803 803
                         if ($type == 3) {
804
-                           // global $dolibarr_main_url_root;
804
+                            // global $dolibarr_main_url_root;
805 805
                             // Define $urlwithroot
806 806
                             $urlwithouturlroot = preg_replace('/' . preg_quote(DOL_BASE_URI, '/') . '$/i', '', trim($dolibarr_main_url_root));
807 807
                             $urlwithroot = $urlwithouturlroot . DOL_BASE_URI;  // This is to use external domain name found into config file
@@ -1071,7 +1071,7 @@  discard block
 block discarded – undo
1071 1071
      */
1072 1072
     static function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '')
1073 1073
     {
1074
-       // global Globals::$conf, $user;
1074
+        // global Globals::$conf, $user;
1075 1075
 // If syslog module enabled
1076 1076
         if (empty(Globals::$conf->syslog->enabled))
1077 1077
             return;
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
      */
1178 1178
     static function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab = 0, $picto = '', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '')
1179 1179
     {
1180
-       // global Globals::$conf, $langs, $hookmanager;
1180
+        // global Globals::$conf, $langs, $hookmanager;
1181 1181
 
1182 1182
         $out = "\n" . '<div class="tabs" data-role="controlgroup" data-type="horizontal">' . "\n";
1183 1183
 
@@ -1360,7 +1360,7 @@  discard block
 block discarded – undo
1360 1360
      */
1361 1361
     static function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldid = 'rowid', $fieldref = 'ref', $morehtmlref = '', $moreparam = '', $nodbprefix = 0, $morehtmlleft = '', $morehtmlstatus = '', $onlybanner = 0, $morehtmlright = '')
1362 1362
     {
1363
-       // global Globals::$conf, $form, $user, $langs;
1363
+        // global Globals::$conf, $form, $user, $langs;
1364 1364
 
1365 1365
         $error = 0;
1366 1366
 
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
      */
1640 1640
     static function fieldLabel($langkey, $fieldkey, $fieldrequired = 0)
1641 1641
     {
1642
-       // global Globals::$conf, $langs;
1642
+        // global Globals::$conf, $langs;
1643 1643
         $ret = '';
1644 1644
         if ($fieldrequired)
1645 1645
             $ret .= '<span class="fieldrequired">';
@@ -1662,7 +1662,7 @@  discard block
 block discarded – undo
1662 1662
      */
1663 1663
     static function dol_bc($var, $moreclass = '')
1664 1664
     {
1665
-       // global $bc;
1665
+        // global $bc;
1666 1666
         $ret = ' ' . $bc[$var];
1667 1667
         if ($moreclass)
1668 1668
             $ret = preg_replace('/class=\"/', 'class="' . $moreclass . ' ', $ret);
@@ -1682,7 +1682,7 @@  discard block
 block discarded – undo
1682 1682
      */
1683 1683
     static function dol_format_address($object, $withcountry = 0, $sep = "\n", $outputlangs = '', $mode = 0)
1684 1684
     {
1685
-       // global Globals::$conf, $langs;
1685
+        // global Globals::$conf, $langs;
1686 1686
 
1687 1687
         $ret = '';
1688 1688
         $countriesusingstate = array('AU', 'CA', 'US', 'IN', 'GB', 'ES', 'UK', 'TR');    // See also MAIN_FORCE_STATE_INTO_ADDRESS
@@ -1773,7 +1773,7 @@  discard block
 block discarded – undo
1773 1773
      */
1774 1774
     static function dol_print_date($time, $format = '', $tzoutput = 'tzserver', $outputlangs = '', $encodetooutput = false)
1775 1775
     {
1776
-       // global Globals::$conf, $langs;
1776
+        // global Globals::$conf, $langs;
1777 1777
 // Clean parameters
1778 1778
         $to_gmt = false;
1779 1779
         $offsettz = $offsetdst = 0;
@@ -1984,7 +1984,7 @@  discard block
 block discarded – undo
1984 1984
      */
1985 1985
     static function dol_getdate($timestamp, $fast = false)
1986 1986
     {
1987
-       // global Globals::$conf;
1987
+        // global Globals::$conf;
1988 1988
 
1989 1989
         $usealternatemethod = false;
1990 1990
         if ($timestamp <= 0)
@@ -2022,7 +2022,7 @@  discard block
 block discarded – undo
2022 2022
      */
2023 2023
     static function dol_mktime($hour, $minute, $second, $month, $day, $year, $gm = false, $check = 1)
2024 2024
     {
2025
-       // global Globals::$conf;
2025
+        // global Globals::$conf;
2026 2026
 //print "- ".$hour.",".$minute.",".$second.",".$month.",".$day.",".$year.",".$_SERVER["WINDIR"]." -";
2027 2027
 // Clean parameters
2028 2028
         if ($hour == -1 || empty($hour))
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
      */
2135 2135
     static function dol_print_size($size, $shortvalue = 0, $shortunit = 0)
2136 2136
     {
2137
-       // global Globals::$conf, $langs;
2137
+        // global Globals::$conf, $langs;
2138 2138
         $level = 1024;
2139 2139
 
2140 2140
         if (!empty(Globals::$conf->dol_optimize_smallscreen))
@@ -2171,7 +2171,7 @@  discard block
 block discarded – undo
2171 2171
      */
2172 2172
     static function dol_print_url($url, $target = '_blank', $max = 32, $withpicto = 0)
2173 2173
     {
2174
-       // global $langs;
2174
+        // global $langs;
2175 2175
 
2176 2176
         if (empty($url))
2177 2177
             return '';
@@ -2205,7 +2205,7 @@  discard block
 block discarded – undo
2205 2205
      */
2206 2206
     static function dol_print_email($email, $cid = 0, $socid = 0, $addlink = 0, $max = 64, $showinvalid = 1, $withpicto = 0)
2207 2207
     {
2208
-       // global Globals::$conf, $user, $langs, $hookmanager;
2208
+        // global Globals::$conf, $user, $langs, $hookmanager;
2209 2209
 
2210 2210
         $newemail = $email;
2211 2211
 
@@ -2262,7 +2262,7 @@  discard block
 block discarded – undo
2262 2262
      */
2263 2263
     static function dol_print_socialnetworks($value, $cid, $socid, $type)
2264 2264
     {
2265
-       // global Globals::$conf, $user, $langs;
2265
+        // global Globals::$conf, $user, $langs;
2266 2266
 
2267 2267
         $newskype = $value;
2268 2268
 
@@ -2317,7 +2317,7 @@  discard block
 block discarded – undo
2317 2317
      */
2318 2318
     static function dol_print_phone($phone, $countrycode = '', $cid = 0, $socid = 0, $addlink = '', $separ = "&nbsp;", $withpicto = '', $titlealt = '', $adddivfloat = 0)
2319 2319
     {
2320
-       // global Globals::$conf, $user, $langs, $mysoc, $hookmanager;
2320
+        // global Globals::$conf, $user, $langs, $mysoc, $hookmanager;
2321 2321
 // Clean phone parameter
2322 2322
         $phone = preg_replace("/[\s.-]/", "", trim($phone));
2323 2323
         if (empty($phone)) {
@@ -2581,7 +2581,7 @@  discard block
 block discarded – undo
2581 2581
      */
2582 2582
     static function dol_print_ip($ip, $mode = 0)
2583 2583
     {
2584
-       // global Globals::$conf, $langs;
2584
+        // global Globals::$conf, $langs;
2585 2585
 
2586 2586
         $ret = '';
2587 2587
 
@@ -2626,7 +2626,7 @@  discard block
 block discarded – undo
2626 2626
      */
2627 2627
     static function dolGetCountryCodeFromIp($ip)
2628 2628
     {
2629
-       // global Globals::$conf;
2629
+        // global Globals::$conf;
2630 2630
 
2631 2631
         $countrycode = '';
2632 2632
 
@@ -2653,7 +2653,7 @@  discard block
 block discarded – undo
2653 2653
      */
2654 2654
     static function dol_user_country()
2655 2655
     {
2656
-       // global Globals::$conf, $langs, $user;
2656
+        // global Globals::$conf, $langs, $user;
2657 2657
 //$ret=$user->xxx;
2658 2658
         $ret = '';
2659 2659
         if (!empty(Globals::$conf->geoipmaxmind->enabled)) {
@@ -2683,7 +2683,7 @@  discard block
 block discarded – undo
2683 2683
      */
2684 2684
     static function dol_print_address($address, $htmlid, $mode, $id, $noprint = 0, $charfornl = '')
2685 2685
     {
2686
-       // global Globals::$conf, $user, $langs, $hookmanager;
2686
+        // global Globals::$conf, $user, $langs, $hookmanager;
2687 2687
 
2688 2688
         $out = '';
2689 2689
 
@@ -2815,7 +2815,7 @@  discard block
 block discarded – undo
2815 2815
      */
2816 2816
     static function dol_substr($string, $start, $length, $stringencoding = '', $trunconbytes = 0)
2817 2817
     {
2818
-       // global $langs;
2818
+        // global $langs;
2819 2819
 
2820 2820
         if (empty($stringencoding))
2821 2821
             $stringencoding = $langs->charset_output;
@@ -2852,7 +2852,7 @@  discard block
 block discarded – undo
2852 2852
      */
2853 2853
     static function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF-8', $nodot = 0, $display = 0)
2854 2854
     {
2855
-       // global Globals::$conf;
2855
+        // global Globals::$conf;
2856 2856
 
2857 2857
         if ($size == 0 || !empty(Globals::$conf->global->MAIN_DISABLE_TRUNC))
2858 2858
             return $string;
@@ -2918,7 +2918,7 @@  discard block
 block discarded – undo
2918 2918
      */
2919 2919
     static function img_picto($titlealt, $picto, $moreatt = '', $pictoisfullpath = false, $srconly = 0, $notitle = 0, $alt = '', $morecss = '')
2920 2920
     {
2921
-       // global Globals::$conf, $langs;
2921
+        // global Globals::$conf, $langs;
2922 2922
 // We forge fullpathpicto for image to $path/img/$picto. By default, we take DOL_BASE_URI/theme/$conf->theme/img/$picto
2923 2923
 //$url = DOL_BASE_URI;
2924 2924
         $url = DOL_BASE_URI;
@@ -3103,7 +3103,7 @@  discard block
 block discarded – undo
3103 3103
      */
3104 3104
     static function img_weather($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0)
3105 3105
     {
3106
-       // global Globals::$conf;
3106
+        // global Globals::$conf;
3107 3107
 
3108 3108
         if (!preg_match('/(\.png|\.gif)$/i', $picto))
3109 3109
             $picto .= '.png';
@@ -3126,7 +3126,7 @@  discard block
 block discarded – undo
3126 3126
      */
3127 3127
     static function img_picto_common($titlealt, $picto, $moreatt = '', $pictoisfullpath = 0)
3128 3128
     {
3129
-       // global Globals::$conf;
3129
+        // global Globals::$conf;
3130 3130
 
3131 3131
         if (!preg_match('/(\.png|\.gif)$/i', $picto))
3132 3132
             $picto .= '.png';
@@ -3157,7 +3157,7 @@  discard block
 block discarded – undo
3157 3157
      */
3158 3158
     static function img_action($titlealt, $numaction)
3159 3159
     {
3160
-       // global Globals::$conf, $langs;
3160
+        // global Globals::$conf, $langs;
3161 3161
 
3162 3162
         if (empty($titlealt) || $titlealt == 'default') {
3163 3163
             if ($numaction == '-1' || $numaction == 'ST_NO') {
@@ -3195,7 +3195,7 @@  discard block
 block discarded – undo
3195 3195
      */
3196 3196
     static function img_pdf($titlealt = 'default', $size = 3)
3197 3197
     {
3198
-       // global Globals::$conf, $langs;
3198
+        // global Globals::$conf, $langs;
3199 3199
 
3200 3200
         if ($titlealt == 'default')
3201 3201
             $titlealt = $langs->trans('Show');
@@ -3212,7 +3212,7 @@  discard block
 block discarded – undo
3212 3212
      */
3213 3213
     static function img_edit_add($titlealt = 'default', $other = '')
3214 3214
     {
3215
-       // global Globals::$conf, $langs;
3215
+        // global Globals::$conf, $langs;
3216 3216
 
3217 3217
         if ($titlealt == 'default')
3218 3218
             $titlealt = $langs->trans('Add');
@@ -3229,7 +3229,7 @@  discard block
 block discarded – undo
3229 3229
      */
3230 3230
     static function img_edit_remove($titlealt = 'default', $other = '')
3231 3231
     {
3232
-       // global Globals::$conf, $langs;
3232
+        // global Globals::$conf, $langs;
3233 3233
 
3234 3234
         if ($titlealt == 'default')
3235 3235
             $titlealt = $langs->trans('Remove');
@@ -3247,7 +3247,7 @@  discard block
 block discarded – undo
3247 3247
      */
3248 3248
     static function img_edit($titlealt = 'default', $float = 0, $other = 'class="pictoedit"')
3249 3249
     {
3250
-       // global Globals::$conf, $langs;
3250
+        // global Globals::$conf, $langs;
3251 3251
 
3252 3252
         if ($titlealt == 'default')
3253 3253
             $titlealt = $langs->trans('Modify');
@@ -3265,7 +3265,7 @@  discard block
 block discarded – undo
3265 3265
      */
3266 3266
     static function img_view($titlealt = 'default', $float = 0, $other = '')
3267 3267
     {
3268
-       // global Globals::$conf, $langs;
3268
+        // global Globals::$conf, $langs;
3269 3269
 
3270 3270
         if ($titlealt == 'default')
3271 3271
             $titlealt = $langs->trans('View');
@@ -3284,7 +3284,7 @@  discard block
 block discarded – undo
3284 3284
      */
3285 3285
     static function img_delete($titlealt = 'default', $other = 'class="pictodelete"')
3286 3286
     {
3287
-       // global Globals::$conf, $langs;
3287
+        // global Globals::$conf, $langs;
3288 3288
 
3289 3289
         if ($titlealt == 'default')
3290 3290
             $titlealt = $langs->trans('Delete');
@@ -3302,7 +3302,7 @@  discard block
 block discarded – undo
3302 3302
      */
3303 3303
     static function img_printer($titlealt = "default", $other = '')
3304 3304
     {
3305
-       // global Globals::$conf, $langs;
3305
+        // global Globals::$conf, $langs;
3306 3306
         if ($titlealt == "default")
3307 3307
             $titlealt = $langs->trans("Print");
3308 3308
         return img_picto($titlealt, 'printer.png', $other);
@@ -3317,7 +3317,7 @@  discard block
 block discarded – undo
3317 3317
      */
3318 3318
     static function img_split($titlealt = 'default', $other = 'class="pictosplit"')
3319 3319
     {
3320
-       // global Globals::$conf, $langs;
3320
+        // global Globals::$conf, $langs;
3321 3321
 
3322 3322
         if ($titlealt == 'default')
3323 3323
             $titlealt = $langs->trans('Split');
@@ -3334,7 +3334,7 @@  discard block
 block discarded – undo
3334 3334
      */
3335 3335
     static function img_help($usehelpcursor = 1, $usealttitle = 1)
3336 3336
     {
3337
-       // global Globals::$conf, $langs;
3337
+        // global Globals::$conf, $langs;
3338 3338
 
3339 3339
         if ($usealttitle) {
3340 3340
             if (is_string($usealttitle))
@@ -3354,7 +3354,7 @@  discard block
 block discarded – undo
3354 3354
      */
3355 3355
     static function img_info($titlealt = 'default')
3356 3356
     {
3357
-       // global Globals::$conf, $langs;
3357
+        // global Globals::$conf, $langs;
3358 3358
 
3359 3359
         if ($titlealt == 'default')
3360 3360
             $titlealt = $langs->trans('Informations');
@@ -3371,7 +3371,7 @@  discard block
 block discarded – undo
3371 3371
      */
3372 3372
     static function img_warning($titlealt = 'default', $moreatt = '')
3373 3373
     {
3374
-       // global Globals::$conf, $langs;
3374
+        // global Globals::$conf, $langs;
3375 3375
 
3376 3376
         if ($titlealt == 'default')
3377 3377
             $titlealt = $langs->trans('Warning');
@@ -3388,7 +3388,7 @@  discard block
 block discarded – undo
3388 3388
      */
3389 3389
     static function img_error($titlealt = 'default')
3390 3390
     {
3391
-       // global Globals::$conf, $langs;
3391
+        // global Globals::$conf, $langs;
3392 3392
 
3393 3393
         if ($titlealt == 'default')
3394 3394
             $titlealt = $langs->trans('Error');
@@ -3405,7 +3405,7 @@  discard block
 block discarded – undo
3405 3405
      */
3406 3406
     static function img_next($titlealt = 'default', $moreatt = '')
3407 3407
     {
3408
-       // global Globals::$conf, $langs;
3408
+        // global Globals::$conf, $langs;
3409 3409
 
3410 3410
         if ($titlealt == 'default')
3411 3411
             $titlealt = $langs->trans('Next');
@@ -3423,7 +3423,7 @@  discard block
 block discarded – undo
3423 3423
      */
3424 3424
     static function img_previous($titlealt = 'default', $moreatt = '')
3425 3425
     {
3426
-       // global Globals::$conf, $langs;
3426
+        // global Globals::$conf, $langs;
3427 3427
 
3428 3428
         if ($titlealt == 'default')
3429 3429
             $titlealt = $langs->trans('Previous');
@@ -3442,7 +3442,7 @@  discard block
 block discarded – undo
3442 3442
      */
3443 3443
     static function img_down($titlealt = 'default', $selected = 0, $moreclass = '')
3444 3444
     {
3445
-       // global Globals::$conf, $langs;
3445
+        // global Globals::$conf, $langs;
3446 3446
 
3447 3447
         if ($titlealt == 'default')
3448 3448
             $titlealt = $langs->trans('Down');
@@ -3460,7 +3460,7 @@  discard block
 block discarded – undo
3460 3460
      */
3461 3461
     static function img_up($titlealt = 'default', $selected = 0, $moreclass = '')
3462 3462
     {
3463
-       // global Globals::$conf, $langs;
3463
+        // global Globals::$conf, $langs;
3464 3464
 
3465 3465
         if ($titlealt == 'default')
3466 3466
             $titlealt = $langs->trans('Up');
@@ -3478,7 +3478,7 @@  discard block
 block discarded – undo
3478 3478
      */
3479 3479
     static function img_left($titlealt = 'default', $selected = 0, $moreatt = '')
3480 3480
     {
3481
-       // global Globals::$conf, $langs;
3481
+        // global Globals::$conf, $langs;
3482 3482
 
3483 3483
         if ($titlealt == 'default')
3484 3484
             $titlealt = $langs->trans('Left');
@@ -3496,7 +3496,7 @@  discard block
 block discarded – undo
3496 3496
      */
3497 3497
     static function img_right($titlealt = 'default', $selected = 0, $moreatt = '')
3498 3498
     {
3499
-       // global Globals::$conf, $langs;
3499
+        // global Globals::$conf, $langs;
3500 3500
 
3501 3501
         if ($titlealt == 'default')
3502 3502
             $titlealt = $langs->trans('Right');
@@ -3513,7 +3513,7 @@  discard block
 block discarded – undo
3513 3513
      */
3514 3514
     static function img_allow($allow, $titlealt = 'default')
3515 3515
     {
3516
-       // global Globals::$conf, $langs;
3516
+        // global Globals::$conf, $langs;
3517 3517
 
3518 3518
         if ($titlealt == 'default')
3519 3519
             $titlealt = $langs->trans('Active');
@@ -3588,7 +3588,7 @@  discard block
 block discarded – undo
3588 3588
     {
3589 3589
         dol_syslog(__FUNCTION__ . " is deprecated", LOG_WARNING);
3590 3590
 
3591
-       // global Globals::$conf, $langs;
3591
+        // global Globals::$conf, $langs;
3592 3592
 
3593 3593
         if ($titlealt == 'default')
3594 3594
             $titlealt = $langs->trans('Call');
@@ -3610,7 +3610,7 @@  discard block
 block discarded – undo
3610 3610
      */
3611 3611
     static function img_search($titlealt = 'default', $other = '')
3612 3612
     {
3613
-       // global Globals::$conf, $langs;
3613
+        // global Globals::$conf, $langs;
3614 3614
 
3615 3615
         if ($titlealt == 'default')
3616 3616
             $titlealt = $langs->trans('Search');
@@ -3632,7 +3632,7 @@  discard block
 block discarded – undo
3632 3632
      */
3633 3633
     static function img_searchclear($titlealt = 'default', $other = '')
3634 3634
     {
3635
-       // global Globals::$conf, $langs;
3635
+        // global Globals::$conf, $langs;
3636 3636
 
3637 3637
         if ($titlealt == 'default')
3638 3638
             $titlealt = $langs->trans('Search');
@@ -3657,7 +3657,7 @@  discard block
 block discarded – undo
3657 3657
      */
3658 3658
     static function info_admin($text, $infoonimgalt = 0, $nodiv = 0, $admin = '1', $morecss = '')
3659 3659
     {
3660
-       // global Globals::$conf, $langs;
3660
+        // global Globals::$conf, $langs;
3661 3661
 
3662 3662
         if ($infoonimgalt) {
3663 3663
             return img_picto($text, 'info', 'class="hideonsmartphone' . ($morecss ? ' ' . $morecss : '') . '"');
@@ -3680,7 +3680,7 @@  discard block
 block discarded – undo
3680 3680
      */
3681 3681
     static function dol_print_error($db = '', $error = '', $errors = null)
3682 3682
     {
3683
-       // global Globals::$conf, $langs, $argv;
3683
+        // global Globals::$conf, $langs, $argv;
3684 3684
         // global $dolibarr_main_prod;
3685 3685
 
3686 3686
         $out = '';
@@ -3799,7 +3799,7 @@  discard block
 block discarded – undo
3799 3799
      */
3800 3800
     static function dol_print_error_email($prefixcode, $errormessage = '', $errormessages = array(), $morecss = 'error', $email = '')
3801 3801
     {
3802
-       // global $langs, Globals::$conf;
3802
+        // global $langs, Globals::$conf;
3803 3803
 
3804 3804
         if (empty($email))
3805 3805
             $email = Globals::$conf->global->MAIN_INFO_SOCIETE_MAIL;
@@ -3858,7 +3858,7 @@  discard block
 block discarded – undo
3858 3858
      */
3859 3859
     static function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin = "", $moreparam = "", $moreattrib = "", $sortfield = "", $sortorder = "", $prefix = "", $disablesortlink = 0, $tooltip = '')
3860 3860
     {
3861
-       // global Globals::$conf, $langs, $form;
3861
+        // global Globals::$conf, $langs, $form;
3862 3862
 //print "$name, $file, $field, $begin, $options, $moreattrib, $sortfield, $sortorder<br>\n";
3863 3863
 
3864 3864
         $sortorder = strtoupper($sortorder);
@@ -3997,7 +3997,7 @@  discard block
 block discarded – undo
3997 3997
      */
3998 3998
     static function load_fiche_titre($titre, $morehtmlright = '', $picto = 'title_generic.png', $pictoisfullpath = 0, $id = '', $morecssontable = '', $morehtmlcenter = '')
3999 3999
     {
4000
-       // global Globals::$conf;
4000
+        // global Globals::$conf;
4001 4001
 
4002 4002
         $return = '';
4003 4003
 
@@ -4047,7 +4047,7 @@  discard block
 block discarded – undo
4047 4047
      */
4048 4048
     static function print_barre_liste($titre, $page, $file, $options = '', $sortfield = '', $sortorder = '', $morehtmlcenter = '', $num = -1, $totalnboflines = '', $picto = 'title_generic.png', $pictoisfullpath = 0, $morehtmlright = '', $morecss = '', $limit = -1, $hideselectlimit = 0, $hidenavigation = 0)
4049 4049
     {
4050
-       // global Globals::$conf, $langs;
4050
+        // global Globals::$conf, $langs;
4051 4051
 
4052 4052
         $savlimit = $limit;
4053 4053
         $savtotalnboflines = $totalnboflines;
@@ -4160,7 +4160,7 @@  discard block
 block discarded – undo
4160 4160
      */
4161 4161
     static function print_fleche_navigation($page, $file, $options = '', $nextpage = 0, $betweenarrows = '', $afterarrows = '', $limit = -1, $totalnboflines = 0, $hideselectlimit = 0)
4162 4162
     {
4163
-       // global Globals::$conf, $langs;
4163
+        // global Globals::$conf, $langs;
4164 4164
 
4165 4165
         print '<div class="pagination"><ul>';
4166 4166
         if ((int) $limit >= 0 && empty($hideselectlimit)) {
@@ -4283,7 +4283,7 @@  discard block
 block discarded – undo
4283 4283
      */
4284 4284
     static function price($amount, $form = 0, $outlangs = '', $trunc = 1, $rounding = -1, $forcerounding = -1, $currency_code = '')
4285 4285
     {
4286
-       // global $langs, Globals::$conf;
4286
+        // global $langs, Globals::$conf;
4287 4287
 // Clean parameters
4288 4288
         if (empty($amount))
4289 4289
             $amount = 0; // To have a numeric value if amount not defined or = ''
@@ -4376,7 +4376,7 @@  discard block
 block discarded – undo
4376 4376
      */
4377 4377
     static function price2num($amount, $rounding = '', $alreadysqlnb = 0)
4378 4378
     {
4379
-       // global $langs, Globals::$conf;
4379
+        // global $langs, Globals::$conf;
4380 4380
 // Round PHP static function does not allow number like '1,234.56' nor '1.234,56' nor '1 234,56'
4381 4381
 // Numbers must be '1234.56'
4382 4382
 // Decimal delimiter for PHP and database SQL requests must be '.'
@@ -4499,7 +4499,7 @@  discard block
 block discarded – undo
4499 4499
      */
4500 4500
     static function get_localtax($vatrate, $local, $thirdparty_buyer = "", $thirdparty_seller = "", $vatnpr = 0)
4501 4501
     {
4502
-       // global $db, Globals::$conf, $mysoc;
4502
+        // global $db, Globals::$conf, $mysoc;
4503 4503
 
4504 4504
         if (empty($thirdparty_seller) || !is_object($thirdparty_seller))
4505 4505
             $thirdparty_seller = $mysoc;
@@ -4639,7 +4639,7 @@  discard block
 block discarded – undo
4639 4639
      */
4640 4640
     static function get_localtax_by_third($local)
4641 4641
     {
4642
-       // global $db, $mysoc;
4642
+        // global $db, $mysoc;
4643 4643
         $sql = "SELECT t.localtax1, t.localtax2 ";
4644 4644
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_tva as t inner join " . MAIN_DB_PREFIX . "c_country as c ON c.rowid=t.fk_pays";
4645 4645
         $sql .= " WHERE c.code = '" . $mysoc->country_code . "' AND t.active = 1 AND t.taux=(";
@@ -4672,7 +4672,7 @@  discard block
 block discarded – undo
4672 4672
      */
4673 4673
     static function getTaxesFromId($vatrate, $buyer = null, $seller = null, $firstparamisid = 1)
4674 4674
     {
4675
-       // global $db, $mysoc;
4675
+        // global $db, $mysoc;
4676 4676
 
4677 4677
         dol_syslog("getTaxesFromId vat id or rate = " . $vatrate);
4678 4678
 
@@ -4729,7 +4729,7 @@  discard block
 block discarded – undo
4729 4729
      */
4730 4730
     static function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid = 0)
4731 4731
     {
4732
-       // global $db, $mysoc;
4732
+        // global $db, $mysoc;
4733 4733
 
4734 4734
         dol_syslog("getLocalTaxesFromRate vatrate=" . $vatrate . " local=" . $local);
4735 4735
 
@@ -4783,7 +4783,7 @@  discard block
 block discarded – undo
4783 4783
      */
4784 4784
     static function get_product_vat_for_country($idprod, $thirdparty_seller, $idprodfournprice = 0)
4785 4785
     {
4786
-       // global $db, Globals::$conf, $mysoc;
4786
+        // global $db, Globals::$conf, $mysoc;
4787 4787
 
4788 4788
         require_once DOL_BASE_PATH . '/product/class/product.class.php';
4789 4789
 
@@ -4854,7 +4854,7 @@  discard block
 block discarded – undo
4854 4854
      */
4855 4855
     static function get_product_localtax_for_country($idprod, $local, $thirdparty_seller)
4856 4856
     {
4857
-       // global $db, $mysoc;
4857
+        // global $db, $mysoc;
4858 4858
 
4859 4859
         if (!class_exists('Product')) {
4860 4860
             require_once DOL_BASE_PATH . 'product/class/product.class.php';
@@ -4922,7 +4922,7 @@  discard block
 block discarded – undo
4922 4922
      */
4923 4923
     static function get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod = 0, $idprodfournprice = 0)
4924 4924
     {
4925
-       // global Globals::$conf;
4925
+        // global Globals::$conf;
4926 4926
 
4927 4927
         require_once DOL_BASE_PATH . '/core/lib/company.lib.php';
4928 4928
 
@@ -4997,7 +4997,7 @@  discard block
 block discarded – undo
4997 4997
      */
4998 4998
     static function get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod = 0, $idprodfournprice = 0)
4999 4999
     {
5000
-       // global $db;
5000
+        // global $db;
5001 5001
 
5002 5002
         if ($idprodfournprice > 0) {
5003 5003
             if (!class_exists('ProductFournisseur'))
@@ -5032,7 +5032,7 @@  discard block
 block discarded – undo
5032 5032
      */
5033 5033
     static function get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $idprod = 0)
5034 5034
     {
5035
-       // global $mysoc;
5035
+        // global $mysoc;
5036 5036
 
5037 5037
         if (!is_object($thirdparty_seller))
5038 5038
             return -1;
@@ -5077,7 +5077,7 @@  discard block
 block discarded – undo
5077 5077
      */
5078 5078
     static function yn($yesno, $case = 1, $color = 0)
5079 5079
     {
5080
-       // global $langs;
5080
+        // global $langs;
5081 5081
         $result = 'unknown';
5082 5082
         $classname = '';
5083 5083
         if ($yesno == 1 || strtolower($yesno) == 'yes' || strtolower($yesno) == 'true') {  // A mettre avant test sur no a cause du == 0
@@ -5127,7 +5127,7 @@  discard block
 block discarded – undo
5127 5127
      */
5128 5128
     static function get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
5129 5129
     {
5130
-       // global Globals::$conf;
5130
+        // global Globals::$conf;
5131 5131
 
5132 5132
         $path = '';
5133 5133
 
@@ -5175,7 +5175,7 @@  discard block
 block discarded – undo
5175 5175
      */
5176 5176
     static function dol_mkdir($dir, $dataroot = '', $newmask = null)
5177 5177
     {
5178
-       // global Globals::$conf;
5178
+        // global Globals::$conf;
5179 5179
 
5180 5180
         dol_syslog("functions.lib::dol_mkdir: dir=" . $dir, LOG_INFO);
5181 5181
 
@@ -5722,7 +5722,7 @@  discard block
 block discarded – undo
5722 5722
      */
5723 5723
     static function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $object = null)
5724 5724
     {
5725
-       // global $db, Globals::$conf, $mysoc, $user, $extrafields;
5725
+        // global $db, Globals::$conf, $mysoc, $user, $extrafields;
5726 5726
 
5727 5727
         $substitutionarray = array();
5728 5728
 
@@ -6028,7 +6028,7 @@  discard block
 block discarded – undo
6028 6028
      */
6029 6029
     static function make_substitutions($text, $substitutionarray, $outputlangs = null)
6030 6030
     {
6031
-       // global Globals::$conf, $langs;
6031
+        // global Globals::$conf, $langs;
6032 6032
 
6033 6033
         if (!is_array($substitutionarray))
6034 6034
             return 'ErrorBadParameterSubstitutionArrayWhenCalling_make_substitutions';
@@ -6094,7 +6094,7 @@  discard block
 block discarded – undo
6094 6094
      */
6095 6095
     static function complete_substitutions_array(&$substitutionarray, $outputlangs, $object = null, $parameters = null, $callfunc = "completesubstitutionarray")
6096 6096
     {
6097
-       // global Globals::$conf, $user;
6097
+        // global Globals::$conf, $user;
6098 6098
 
6099 6099
         require_once DOL_BASE_PATH . '/core/lib/files.lib.php';
6100 6100
 
@@ -6164,7 +6164,7 @@  discard block
 block discarded – undo
6164 6164
      */
6165 6165
     static function get_date_range($date_start, $date_end, $format = '', $outputlangs = '', $withparenthesis = 1)
6166 6166
     {
6167
-       // global $langs;
6167
+        // global $langs;
6168 6168
 
6169 6169
         $out = '';
6170 6170
 
@@ -6194,7 +6194,7 @@  discard block
 block discarded – undo
6194 6194
      */
6195 6195
     static function dolGetFirstLastname($firstname, $lastname, $nameorder = -1)
6196 6196
     {
6197
-       // global Globals::$conf;
6197
+        // global Globals::$conf;
6198 6198
 
6199 6199
         $ret = '';
6200 6200
 // If order not defined, we use the setup
@@ -6318,7 +6318,7 @@  discard block
 block discarded – undo
6318 6318
      */
6319 6319
     static function get_htmloutput_mesg($mesgstring = '', $mesgarray = '', $style = 'ok', $keepembedded = 0)
6320 6320
     {
6321
-       // global Globals::$conf, $langs;
6321
+        // global Globals::$conf, $langs;
6322 6322
 
6323 6323
         $ret = 0;
6324 6324
         $return = '';
@@ -6554,7 +6554,7 @@  discard block
 block discarded – undo
6554 6554
      */
6555 6555
     function dol_osencode($str)
6556 6556
     {
6557
-       // global Globals::$conf;
6557
+        // global Globals::$conf;
6558 6558
 
6559 6559
         $tmp = ini_get("unicode.filesystem_encoding");      // Disponible avec PHP 6.0
6560 6560
         if (empty($tmp) && !empty($_SERVER["WINDIR"]))
@@ -6584,7 +6584,7 @@  discard block
 block discarded – undo
6584 6584
      */
6585 6585
     static function dol_getIdFromCode($db, $key, $tablename, $fieldkey = 'code', $fieldid = 'id', $entityfilter = 0)
6586 6586
     {
6587
-       // global $cache_codes;
6587
+        // global $cache_codes;
6588 6588
 // If key empty
6589 6589
         if ($key == '')
6590 6590
             return '';
@@ -6625,7 +6625,7 @@  discard block
 block discarded – undo
6625 6625
      */
6626 6626
     static function verifCond($strRights)
6627 6627
     {
6628
-       // global $user, Globals::$conf, $langs;
6628
+        // global $user, Globals::$conf, $langs;
6629 6629
         // global $leftmenu;
6630 6630
         // global $rights;    // To export to dol_eval function
6631 6631
 //print $strRights."<br>\n";
@@ -6691,7 +6691,7 @@  discard block
 block discarded – undo
6691 6691
      */
6692 6692
     static function picto_from_langcode($codelang, $moreatt = '')
6693 6693
     {
6694
-       // global $langs;
6694
+        // global $langs;
6695 6695
 
6696 6696
         if (empty($codelang))
6697 6697
             return '';
@@ -6726,7 +6726,7 @@  discard block
 block discarded – undo
6726 6726
      */
6727 6727
     static function getLanguageCodeFromCountryCode($countrycode)
6728 6728
     {
6729
-       // global $mysoc;
6729
+        // global $mysoc;
6730 6730
 
6731 6731
         if (strtoupper($countrycode) == 'MQ')
6732 6732
             return 'fr_CA';
@@ -6960,7 +6960,7 @@  discard block
 block discarded – undo
6960 6960
      */
6961 6961
     static function complete_head_from_modules($conf, $langs, $object, &$head, &$h, $type, $mode = 'add')
6962 6962
     {
6963
-       // global $hookmanager;
6963
+        // global $hookmanager;
6964 6964
 
6965 6965
         if (isset(Globals::$conf->modules_parts['tabs'][$type]) && is_array(Globals::$conf->modules_parts['tabs'][$type])) {
6966 6966
             foreach (Globals::$conf->modules_parts['tabs'][$type] as $value) {
@@ -7049,7 +7049,7 @@  discard block
 block discarded – undo
7049 7049
      */
7050 7050
     static function printCommonFooter($zone = 'private')
7051 7051
     {
7052
-       // global Globals::$conf, $hookmanager, $user;
7052
+        // global Globals::$conf, $hookmanager, $user;
7053 7053
         // global $action;
7054 7054
         // global $micro_start_time;
7055 7055
 
@@ -7289,7 +7289,7 @@  discard block
 block discarded – undo
7289 7289
      */
7290 7290
     static function natural_search($fields, $value, $mode = 0, $nofirstand = 0)
7291 7291
     {
7292
-       // global $db, $langs;
7292
+        // global $db, $langs;
7293 7293
 
7294 7294
         $value = trim($value);
7295 7295
 
@@ -7422,7 +7422,7 @@  discard block
 block discarded – undo
7422 7422
      */
7423 7423
     static function showDirectDownloadLink($object)
7424 7424
     {
7425
-       // global Globals::$conf, $langs;
7425
+        // global Globals::$conf, $langs;
7426 7426
 
7427 7427
         $out = '';
7428 7428
         $url = $object->getLastMainDocLink($object->element);
@@ -7484,7 +7484,7 @@  discard block
 block discarded – undo
7484 7484
      */
7485 7485
     static function getAdvancedPreviewUrl($modulepart, $relativepath, $alldata = 0, $param = '')
7486 7486
     {
7487
-       // global Globals::$conf, $langs;
7487
+        // global Globals::$conf, $langs;
7488 7488
 
7489 7489
         if (empty(Globals::$conf->use_javascript_ajax))
7490 7490
             return '';
@@ -7517,7 +7517,7 @@  discard block
 block discarded – undo
7517 7517
      */
7518 7518
     static function ajax_autoselect($htmlname, $addlink = '')
7519 7519
     {
7520
-       // global $langs;
7520
+        // global $langs;
7521 7521
         $out = '<script type="text/javascript">
7522 7522
                jQuery(document).ready(static function () {
7523 7523
 				    jQuery("#' . $htmlname . '").click(function() { jQuery(this).select(); } );
@@ -7901,7 +7901,7 @@  discard block
 block discarded – undo
7901 7901
      */
7902 7902
     static function getDictvalue($tablename, $field, $id, $checkentity = false, $rowidfield = 'rowid')
7903 7903
     {
7904
-       // global $dictvalues, $db, $langs;
7904
+        // global $dictvalues, $db, $langs;
7905 7905
 
7906 7906
         if (!isset($dictvalues[$tablename])) {
7907 7907
             $dictvalues[$tablename] = array();
@@ -7969,7 +7969,7 @@  discard block
 block discarded – undo
7969 7969
      */
7970 7970
     static function isVisibleToUserType($type_user, &$menuentry, &$listofmodulesforexternal)
7971 7971
     {
7972
-       // global Globals::$conf;
7972
+        // global Globals::$conf;
7973 7973
 //print 'type_user='.$type_user.' module='.$menuentry['module'].' enabled='.$menuentry['enabled'].' perms='.$menuentry['perms'];
7974 7974
 //print 'ok='.in_array($menuentry['module'], $listofmodulesforexternal);
7975 7975
         if (empty($menuentry['enabled']))
Please login to merge, or discard this patch.
Helpers/triggers/interface_50_modLdap_Ldapsynchro.class.php 1 patch
Indentation   +771 added lines, -771 removed lines patch added patch discarded remove patch
@@ -31,781 +31,781 @@
 block discarded – undo
31 31
  */
32 32
 class InterfaceLdapsynchro extends DolibarrTriggers
33 33
 {
34
-	public $family = 'ldap';
35
-	public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database.";
36
-
37
-	/**
38
-	 * Version of the trigger
39
-	 * @var string
40
-	 */
41
-	public $version = self::VERSION_DOLIBARR;
42
-
43
-	/**
44
-	 * @var string Image of the trigger
45
-	 */
46
-	public $picto = 'technic';
47
-
48
-	/**
49
-	 * Function called when a Dolibarrr business event is done.
50
-	 * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
51
-	 *
52
-	 * @param string		$action		Event action code
53
-	 * @param Object		$object     Object
54
-	 * @param User		    $user       Object user
55
-	 * @param Translate 	$langs      Object langs
56
-	 * @param conf		    $conf       Object conf
57
-	 * @return int         				<0 if KO, 0 if no triggered ran, >0 if OK
58
-	 */
59
-	public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
60
-	{
61
-		if (empty($conf->ldap->enabled)) return 0;		// Module not active, we do nothing
62
-		if (defined('DISABLE_LDAP_SYNCHRO')) return 0;	// If constant defined, we do nothing
63
-
64
-		if (! function_exists('ldap_connect'))
65
-		{
66
-			dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING);
67
-			return 0;
68
-		}
69
-
70
-		require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
71
-		require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
72
-
73
-		$result=0;
74
-
75
-		// Users
76
-		if ($action == 'USER_CREATE')
77
-		{
78
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
79
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
80
-			{
81
-				$ldap=new Ldap();
82
-				$result=$ldap->connect_bind();
83
-
84
-				if ($result > 0)
85
-				{
86
-					$info=$object->_load_ldap_info();
87
-					$dn=$object->_load_ldap_dn($info);
88
-
89
-					$result=$ldap->add($dn,$info,$user);
90
-				}
91
-
92
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
93
-			}
94
-		}
95
-		elseif ($action == 'USER_MODIFY')
96
-		{
97
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
98
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
99
-			{
100
-				$ldap=new Ldap();
101
-				$result=$ldap->connect_bind();
102
-
103
-				if ($result > 0)
104
-				{
105
-					if (empty($object->oldcopy) || ! is_object($object->oldcopy))
106
-					{
107
-						dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
108
-						$object->oldcopy = clone $object;
109
-					}
110
-
111
-					$oldinfo=$object->oldcopy->_load_ldap_info();
112
-					$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
113
-
114
-					// Verify if entry exist
115
-					$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
116
-					$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
117
-					$records=$ldap->search($container,$search);
118
-					if (count($records) && $records['count'] == 0)
119
-					{
120
-						$olddn = '';
121
-					}
122
-
123
-					$info=$object->_load_ldap_info();
124
-					$dn=$object->_load_ldap_dn($info);
125
-					$newrdn=$object->_load_ldap_dn($info,2);
126
-					$newparent=$object->_load_ldap_dn($info,1);
127
-
128
-					$result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent);
129
-				}
130
-
131
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
132
-			}
133
-		}
134
-		elseif ($action == 'USER_NEW_PASSWORD')
135
-		{
136
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
137
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
138
-			{
139
-				$ldap=new Ldap();
140
-				$result=$ldap->connect_bind();
141
-
142
-				if ($result > 0)
143
-				{
144
-					if (empty($object->oldcopy) || ! is_object($object->oldcopy))
145
-					{
146
-						dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
147
-						$object->oldcopy = clone $object;
148
-					}
149
-
150
-					$oldinfo=$object->oldcopy->_load_ldap_info();
151
-					$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
152
-
153
-					// Verify if entry exist
154
-					$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
155
-					$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
156
-					$records=$ldap->search($container,$search);
157
-					if (count($records) && $records['count'] == 0)
158
-					{
159
-						$olddn = '';
160
-					}
161
-
162
-					$info=$object->_load_ldap_info();
163
-					$dn=$object->_load_ldap_dn($info);
164
-
165
-					$result=$ldap->update($dn,$info,$user,$olddn);
166
-				}
167
-
168
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
169
-			}
170
-		}
171
-		elseif ($action == 'USER_ENABLEDISABLE')
172
-		{
173
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
174
-		}
175
-		elseif ($action == 'USER_DELETE')
176
-		{
177
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
178
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
179
-			{
180
-				$ldap=new Ldap();
181
-				$result=$ldap->connect_bind();
182
-
183
-				if ($result > 0)
184
-				{
185
-					$info=$object->_load_ldap_info();
186
-					$dn=$object->_load_ldap_dn($info);
187
-
188
-					$result=$ldap->delete($dn);
189
-				}
190
-
191
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
192
-			}
193
-		}
194
-		elseif ($action == 'USER_SETINGROUP')
195
-		{
196
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
197
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
198
-			{
199
-				$ldap=new Ldap();
200
-				$result=$ldap->connect_bind();
201
-
202
-				if ($result > 0)
203
-				{
204
-					// Must edit $object->newgroupid
205
-					$usergroup=new UserGroup($this->db);
206
-					if ($object->newgroupid > 0)
207
-					{
208
-						$usergroup->fetch($object->newgroupid);
209
-
210
-						$oldinfo=$usergroup->_load_ldap_info();
211
-						$olddn=$usergroup->_load_ldap_dn($oldinfo);
212
-
213
-						// Verify if entry exist
214
-						$container=$usergroup->_load_ldap_dn($oldinfo,1);
215
-						$search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")";
216
-						$records=$ldap->search($container,$search);
217
-						if (count($records) && $records['count'] == 0)
218
-						{
219
-							$olddn = '';
220
-						}
221
-
222
-						$info=$usergroup->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
223
-						$dn=$usergroup->_load_ldap_dn($info);
224
-
225
-						$result=$ldap->update($dn,$info,$user,$olddn);
226
-					}
227
-				}
228
-
229
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
230
-			}
231
-		}
232
-		elseif ($action == 'USER_REMOVEFROMGROUP')
233
-		{
234
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
235
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
236
-			{
237
-				$ldap=new Ldap();
238
-				$result=$ldap->connect_bind();
239
-
240
-				if ($result > 0)
241
-				{
242
-					// Must edit $object->newgroupid
243
-					$usergroup=new UserGroup($this->db);
244
-					if ($object->oldgroupid > 0)
245
-					{
246
-						$usergroup->fetch($object->oldgroupid);
247
-
248
-						$oldinfo=$usergroup->_load_ldap_info();
249
-						$olddn=$usergroup->_load_ldap_dn($oldinfo);
250
-
251
-						// Verify if entry exist
252
-						$container=$usergroup->_load_ldap_dn($oldinfo,1);
253
-						$search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")";
254
-						$records=$ldap->search($container,$search);
255
-						if (count($records) && $records['count'] == 0)
256
-						{
257
-							$olddn = '';
258
-						}
259
-
260
-						$info=$usergroup->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
261
-						$dn=$usergroup->_load_ldap_dn($info);
262
-
263
-						$result=$ldap->update($dn,$info,$user,$olddn);
264
-					}
265
-				}
266
-
267
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
268
-			}
269
-		}
270
-
271
-		// Groupes
272
-		elseif ($action == 'GROUP_CREATE')
273
-		{
274
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
275
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
276
-			{
277
-				$ldap=new Ldap();
278
-				$result=$ldap->connect_bind();
279
-
280
-				if ($result > 0)
281
-				{
282
-					$info=$object->_load_ldap_info();
283
-					$dn=$object->_load_ldap_dn($info);
284
-
285
-					// Get a gid number for objectclass PosixGroup
286
-					if (in_array('posixGroup',$info['objectclass'])) {
287
-						$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
288
-					}
289
-
290
-					$result=$ldap->add($dn,$info,$user);
291
-				}
292
-
293
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
294
-			}
295
-		}
296
-		elseif ($action == 'GROUP_MODIFY')
297
-		{
298
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
299
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
300
-			{
301
-				$ldap=new Ldap();
302
-				$result=$ldap->connect_bind();
303
-
304
-				if ($result > 0)
305
-				{
306
-					if (empty($object->oldcopy) || ! is_object($object->oldcopy))
307
-					{
308
-						dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
309
-						$object->oldcopy = clone $object;
310
-					}
311
-
312
-					$oldinfo=$object->oldcopy->_load_ldap_info();
313
-					$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
314
-
315
-					// Verify if entry exist
316
-					$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
317
-					$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
318
-					$records=$ldap->search($container,$search);
319
-					if (count($records) && $records['count'] == 0)
320
-					{
321
-						$olddn = '';
322
-					}
323
-
324
-					$info=$object->_load_ldap_info();
325
-					$dn=$object->_load_ldap_dn($info);
326
-
327
-					$result=$ldap->update($dn,$info,$user,$olddn);
328
-				}
329
-
330
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
331
-			}
332
-		}
333
-		elseif ($action == 'GROUP_DELETE')
334
-		{
335
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
336
-			if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
337
-			{
338
-				$ldap=new Ldap();
339
-				$result=$ldap->connect_bind();
340
-
341
-				if ($result > 0)
342
-				{
343
-					$info=$object->_load_ldap_info();
344
-					$dn=$object->_load_ldap_dn($info);
345
-
346
-					$result=$ldap->delete($dn);
347
-				}
348
-
349
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
350
-			}
351
-		}
352
-
353
-		// Contacts
354
-		elseif ($action == 'CONTACT_CREATE')
355
-		{
356
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
357
-			if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
358
-			{
359
-				$ldap=new Ldap();
360
-				$result=$ldap->connect_bind();
361
-
362
-				if ($result > 0)
363
-				{
364
-					$info=$object->_load_ldap_info();
365
-					$dn=$object->_load_ldap_dn($info);
366
-
367
-					$result=$ldap->add($dn,$info,$user);
368
-				}
369
-
370
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
371
-			}
372
-		}
373
-		elseif ($action == 'CONTACT_MODIFY')
374
-		{
375
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
376
-			if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
377
-			{
378
-				$ldap=new Ldap();
379
-				$result=$ldap->connect_bind();
380
-
381
-				if ($result > 0)
382
-				{
383
-					if (empty($object->oldcopy) || ! is_object($object->oldcopy))
384
-					{
385
-						dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
386
-						$object->oldcopy = clone $object;
387
-					}
388
-
389
-					$oldinfo=$object->oldcopy->_load_ldap_info();
390
-					$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
391
-
392
-					// Verify if entry exist
393
-					$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
394
-					$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
395
-					$records=$ldap->search($container,$search);
396
-					if (count($records) && $records['count'] == 0)
397
-					{
398
-						$olddn = '';
399
-					}
400
-
401
-					$info=$object->_load_ldap_info();
402
-					$dn=$object->_load_ldap_dn($info);
403
-
404
-					$result=$ldap->update($dn,$info,$user,$olddn);
405
-				}
406
-
407
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
408
-			}
409
-		}
410
-		elseif ($action == 'CONTACT_DELETE')
411
-		{
412
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
413
-			if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
414
-			{
415
-				$ldap=new Ldap();
416
-				$result=$ldap->connect_bind();
417
-
418
-				if ($result > 0)
419
-				{
420
-					$info=$object->_load_ldap_info();
421
-					$dn=$object->_load_ldap_dn($info);
422
-
423
-					$result=$ldap->delete($dn);
424
-				}
425
-
426
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
427
-			}
428
-		}
429
-
430
-		// Members
431
-		elseif ($action == 'MEMBER_CREATE')
432
-		{
433
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
434
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
435
-			{
436
-				$ldap=new Ldap();
437
-				$result=$ldap->connect_bind();
438
-
439
-				if ($result > 0)
440
-				{
441
-					$info=$object->_load_ldap_info();
442
-					$dn=$object->_load_ldap_dn($info);
443
-
444
-					$result=$ldap->add($dn,$info,$user);
445
-
446
-					// For member type
447
-					if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
448
-					{
449
-						$membertype=new AdherentType($this->db);
450
-						if ($object->typeid > 0)
451
-						{
452
-							$membertype->fetch($object->typeid);
453
-							$membertype->listMembersForMemberType('', 1);
454
-
455
-							$oldinfo=$membertype->_load_ldap_info();
456
-							$olddn=$membertype->_load_ldap_dn($oldinfo);
457
-
458
-							// Verify if entry exist
459
-							$container=$membertype->_load_ldap_dn($oldinfo,1);
460
-							$search = "(".$membertype->_load_ldap_dn($oldinfo,2).")";
461
-							$records=$ldap->search($container,$search);
462
-							if (count($records) && $records['count'] == 0)
463
-							{
464
-								$olddn = '';
465
-							}
466
-
467
-							$info=$membertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
468
-							$dn=$membertype->_load_ldap_dn($info);
469
-
470
-							$result=$ldap->update($dn,$info,$user,$olddn);
471
-						}
472
-					}
473
-				}
474
-
475
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
476
-			}
477
-		}
478
-		elseif ($action == 'MEMBER_VALIDATE')
479
-		{
480
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
481
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
482
-			{
483
-				// If status field is setup to be synchronized
484
-				if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS))
485
-				{
486
-					$ldap=new Ldap();
487
-					$result=$ldap->connect_bind();
488
-
489
-					if ($result > 0)
490
-					{
491
-						$info=$object->_load_ldap_info();
492
-						$dn=$object->_load_ldap_dn($info);
493
-						$olddn=$dn;	// We know olddn=dn as we change only status
494
-
495
-						$result=$ldap->update($dn,$info,$user,$olddn);
496
-					}
497
-
498
-					if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
499
-				}
500
-			}
501
-		}
502
-		elseif ($action == 'MEMBER_SUBSCRIPTION')
503
-		{
504
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
505
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
506
-			{
507
-				// If subscriptions fields are setup to be synchronized
508
-				if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE
509
-					|| $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT
510
-					|| $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE
511
-					|| $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
512
-					|| $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
513
-				{
514
-					$ldap=new Ldap();
515
-					$result=$ldap->connect_bind();
516
-
517
-					if ($result > 0)
518
-					{
519
-						$info=$object->_load_ldap_info();
520
-						$dn=$object->_load_ldap_dn($info);
521
-						$olddn=$dn;	// We know olddn=dn as we change only subscriptions
522
-
523
-						$result=$ldap->update($dn,$info,$user,$olddn);
524
-					}
525
-
526
-					if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
527
-				}
528
-			}
529
-		}
530
-		elseif ($action == 'MEMBER_MODIFY')
531
-		{
532
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
533
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
534
-			{
535
-				$ldap=new Ldap();
536
-				$result=$ldap->connect_bind();
537
-
538
-				if ($result > 0)
539
-				{
540
-					if (empty($object->oldcopy) || ! is_object($object->oldcopy))
541
-					{
542
-						dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
543
-						$object->oldcopy = clone $object;
544
-					}
545
-
546
-					$oldinfo=$object->oldcopy->_load_ldap_info();
547
-					$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
548
-
549
-					// Verify if entry exist
550
-					$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
551
-					$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
552
-					$records=$ldap->search($container,$search);
553
-					if (count($records) && $records['count'] == 0)
554
-					{
555
-						$olddn = '';
556
-					}
557
-
558
-					$info=$object->_load_ldap_info();
559
-					$dn=$object->_load_ldap_dn($info);
560
-					$newrdn=$object->_load_ldap_dn($info,2);
561
-					$newparent=$object->_load_ldap_dn($info,1);
562
-
563
-					$result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent);
564
-
565
-					// For member type
566
-					if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
567
-					{
568
-						/*
34
+    public $family = 'ldap';
35
+    public $description = "Triggers of this module allows to synchronize Dolibarr toward a LDAP database.";
36
+
37
+    /**
38
+     * Version of the trigger
39
+     * @var string
40
+     */
41
+    public $version = self::VERSION_DOLIBARR;
42
+
43
+    /**
44
+     * @var string Image of the trigger
45
+     */
46
+    public $picto = 'technic';
47
+
48
+    /**
49
+     * Function called when a Dolibarrr business event is done.
50
+     * All functions "runTrigger" are triggered if file is inside directory htdocs/core/triggers or htdocs/module/code/triggers (and declared)
51
+     *
52
+     * @param string		$action		Event action code
53
+     * @param Object		$object     Object
54
+     * @param User		    $user       Object user
55
+     * @param Translate 	$langs      Object langs
56
+     * @param conf		    $conf       Object conf
57
+     * @return int         				<0 if KO, 0 if no triggered ran, >0 if OK
58
+     */
59
+    public function runTrigger($action, $object, User $user, Translate $langs, Conf $conf)
60
+    {
61
+        if (empty($conf->ldap->enabled)) return 0;		// Module not active, we do nothing
62
+        if (defined('DISABLE_LDAP_SYNCHRO')) return 0;	// If constant defined, we do nothing
63
+
64
+        if (! function_exists('ldap_connect'))
65
+        {
66
+            dol_syslog("Warning, module LDAP is enabled but LDAP functions not available in this PHP", LOG_WARNING);
67
+            return 0;
68
+        }
69
+
70
+        require_once DOL_DOCUMENT_ROOT."/core/class/ldap.class.php";
71
+        require_once DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php";
72
+
73
+        $result=0;
74
+
75
+        // Users
76
+        if ($action == 'USER_CREATE')
77
+        {
78
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
79
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
80
+            {
81
+                $ldap=new Ldap();
82
+                $result=$ldap->connect_bind();
83
+
84
+                if ($result > 0)
85
+                {
86
+                    $info=$object->_load_ldap_info();
87
+                    $dn=$object->_load_ldap_dn($info);
88
+
89
+                    $result=$ldap->add($dn,$info,$user);
90
+                }
91
+
92
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
93
+            }
94
+        }
95
+        elseif ($action == 'USER_MODIFY')
96
+        {
97
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
98
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
99
+            {
100
+                $ldap=new Ldap();
101
+                $result=$ldap->connect_bind();
102
+
103
+                if ($result > 0)
104
+                {
105
+                    if (empty($object->oldcopy) || ! is_object($object->oldcopy))
106
+                    {
107
+                        dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
108
+                        $object->oldcopy = clone $object;
109
+                    }
110
+
111
+                    $oldinfo=$object->oldcopy->_load_ldap_info();
112
+                    $olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
113
+
114
+                    // Verify if entry exist
115
+                    $container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
116
+                    $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
117
+                    $records=$ldap->search($container,$search);
118
+                    if (count($records) && $records['count'] == 0)
119
+                    {
120
+                        $olddn = '';
121
+                    }
122
+
123
+                    $info=$object->_load_ldap_info();
124
+                    $dn=$object->_load_ldap_dn($info);
125
+                    $newrdn=$object->_load_ldap_dn($info,2);
126
+                    $newparent=$object->_load_ldap_dn($info,1);
127
+
128
+                    $result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent);
129
+                }
130
+
131
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
132
+            }
133
+        }
134
+        elseif ($action == 'USER_NEW_PASSWORD')
135
+        {
136
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
137
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
138
+            {
139
+                $ldap=new Ldap();
140
+                $result=$ldap->connect_bind();
141
+
142
+                if ($result > 0)
143
+                {
144
+                    if (empty($object->oldcopy) || ! is_object($object->oldcopy))
145
+                    {
146
+                        dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
147
+                        $object->oldcopy = clone $object;
148
+                    }
149
+
150
+                    $oldinfo=$object->oldcopy->_load_ldap_info();
151
+                    $olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
152
+
153
+                    // Verify if entry exist
154
+                    $container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
155
+                    $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
156
+                    $records=$ldap->search($container,$search);
157
+                    if (count($records) && $records['count'] == 0)
158
+                    {
159
+                        $olddn = '';
160
+                    }
161
+
162
+                    $info=$object->_load_ldap_info();
163
+                    $dn=$object->_load_ldap_dn($info);
164
+
165
+                    $result=$ldap->update($dn,$info,$user,$olddn);
166
+                }
167
+
168
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
169
+            }
170
+        }
171
+        elseif ($action == 'USER_ENABLEDISABLE')
172
+        {
173
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
174
+        }
175
+        elseif ($action == 'USER_DELETE')
176
+        {
177
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
178
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
179
+            {
180
+                $ldap=new Ldap();
181
+                $result=$ldap->connect_bind();
182
+
183
+                if ($result > 0)
184
+                {
185
+                    $info=$object->_load_ldap_info();
186
+                    $dn=$object->_load_ldap_dn($info);
187
+
188
+                    $result=$ldap->delete($dn);
189
+                }
190
+
191
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
192
+            }
193
+        }
194
+        elseif ($action == 'USER_SETINGROUP')
195
+        {
196
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
197
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
198
+            {
199
+                $ldap=new Ldap();
200
+                $result=$ldap->connect_bind();
201
+
202
+                if ($result > 0)
203
+                {
204
+                    // Must edit $object->newgroupid
205
+                    $usergroup=new UserGroup($this->db);
206
+                    if ($object->newgroupid > 0)
207
+                    {
208
+                        $usergroup->fetch($object->newgroupid);
209
+
210
+                        $oldinfo=$usergroup->_load_ldap_info();
211
+                        $olddn=$usergroup->_load_ldap_dn($oldinfo);
212
+
213
+                        // Verify if entry exist
214
+                        $container=$usergroup->_load_ldap_dn($oldinfo,1);
215
+                        $search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")";
216
+                        $records=$ldap->search($container,$search);
217
+                        if (count($records) && $records['count'] == 0)
218
+                        {
219
+                            $olddn = '';
220
+                        }
221
+
222
+                        $info=$usergroup->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
223
+                        $dn=$usergroup->_load_ldap_dn($info);
224
+
225
+                        $result=$ldap->update($dn,$info,$user,$olddn);
226
+                    }
227
+                }
228
+
229
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
230
+            }
231
+        }
232
+        elseif ($action == 'USER_REMOVEFROMGROUP')
233
+        {
234
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
235
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
236
+            {
237
+                $ldap=new Ldap();
238
+                $result=$ldap->connect_bind();
239
+
240
+                if ($result > 0)
241
+                {
242
+                    // Must edit $object->newgroupid
243
+                    $usergroup=new UserGroup($this->db);
244
+                    if ($object->oldgroupid > 0)
245
+                    {
246
+                        $usergroup->fetch($object->oldgroupid);
247
+
248
+                        $oldinfo=$usergroup->_load_ldap_info();
249
+                        $olddn=$usergroup->_load_ldap_dn($oldinfo);
250
+
251
+                        // Verify if entry exist
252
+                        $container=$usergroup->_load_ldap_dn($oldinfo,1);
253
+                        $search = "(".$usergroup->_load_ldap_dn($oldinfo,2).")";
254
+                        $records=$ldap->search($container,$search);
255
+                        if (count($records) && $records['count'] == 0)
256
+                        {
257
+                            $olddn = '';
258
+                        }
259
+
260
+                        $info=$usergroup->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
261
+                        $dn=$usergroup->_load_ldap_dn($info);
262
+
263
+                        $result=$ldap->update($dn,$info,$user,$olddn);
264
+                    }
265
+                }
266
+
267
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
268
+            }
269
+        }
270
+
271
+        // Groupes
272
+        elseif ($action == 'GROUP_CREATE')
273
+        {
274
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
275
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
276
+            {
277
+                $ldap=new Ldap();
278
+                $result=$ldap->connect_bind();
279
+
280
+                if ($result > 0)
281
+                {
282
+                    $info=$object->_load_ldap_info();
283
+                    $dn=$object->_load_ldap_dn($info);
284
+
285
+                    // Get a gid number for objectclass PosixGroup
286
+                    if (in_array('posixGroup',$info['objectclass'])) {
287
+                        $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_GROUPS');
288
+                    }
289
+
290
+                    $result=$ldap->add($dn,$info,$user);
291
+                }
292
+
293
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
294
+            }
295
+        }
296
+        elseif ($action == 'GROUP_MODIFY')
297
+        {
298
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
299
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
300
+            {
301
+                $ldap=new Ldap();
302
+                $result=$ldap->connect_bind();
303
+
304
+                if ($result > 0)
305
+                {
306
+                    if (empty($object->oldcopy) || ! is_object($object->oldcopy))
307
+                    {
308
+                        dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
309
+                        $object->oldcopy = clone $object;
310
+                    }
311
+
312
+                    $oldinfo=$object->oldcopy->_load_ldap_info();
313
+                    $olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
314
+
315
+                    // Verify if entry exist
316
+                    $container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
317
+                    $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
318
+                    $records=$ldap->search($container,$search);
319
+                    if (count($records) && $records['count'] == 0)
320
+                    {
321
+                        $olddn = '';
322
+                    }
323
+
324
+                    $info=$object->_load_ldap_info();
325
+                    $dn=$object->_load_ldap_dn($info);
326
+
327
+                    $result=$ldap->update($dn,$info,$user,$olddn);
328
+                }
329
+
330
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
331
+            }
332
+        }
333
+        elseif ($action == 'GROUP_DELETE')
334
+        {
335
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
336
+            if (! empty($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE === 'dolibarr2ldap')
337
+            {
338
+                $ldap=new Ldap();
339
+                $result=$ldap->connect_bind();
340
+
341
+                if ($result > 0)
342
+                {
343
+                    $info=$object->_load_ldap_info();
344
+                    $dn=$object->_load_ldap_dn($info);
345
+
346
+                    $result=$ldap->delete($dn);
347
+                }
348
+
349
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
350
+            }
351
+        }
352
+
353
+        // Contacts
354
+        elseif ($action == 'CONTACT_CREATE')
355
+        {
356
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
357
+            if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
358
+            {
359
+                $ldap=new Ldap();
360
+                $result=$ldap->connect_bind();
361
+
362
+                if ($result > 0)
363
+                {
364
+                    $info=$object->_load_ldap_info();
365
+                    $dn=$object->_load_ldap_dn($info);
366
+
367
+                    $result=$ldap->add($dn,$info,$user);
368
+                }
369
+
370
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
371
+            }
372
+        }
373
+        elseif ($action == 'CONTACT_MODIFY')
374
+        {
375
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
376
+            if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
377
+            {
378
+                $ldap=new Ldap();
379
+                $result=$ldap->connect_bind();
380
+
381
+                if ($result > 0)
382
+                {
383
+                    if (empty($object->oldcopy) || ! is_object($object->oldcopy))
384
+                    {
385
+                        dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
386
+                        $object->oldcopy = clone $object;
387
+                    }
388
+
389
+                    $oldinfo=$object->oldcopy->_load_ldap_info();
390
+                    $olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
391
+
392
+                    // Verify if entry exist
393
+                    $container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
394
+                    $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
395
+                    $records=$ldap->search($container,$search);
396
+                    if (count($records) && $records['count'] == 0)
397
+                    {
398
+                        $olddn = '';
399
+                    }
400
+
401
+                    $info=$object->_load_ldap_info();
402
+                    $dn=$object->_load_ldap_dn($info);
403
+
404
+                    $result=$ldap->update($dn,$info,$user,$olddn);
405
+                }
406
+
407
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
408
+            }
409
+        }
410
+        elseif ($action == 'CONTACT_DELETE')
411
+        {
412
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
413
+            if (! empty($conf->global->LDAP_CONTACT_ACTIVE))
414
+            {
415
+                $ldap=new Ldap();
416
+                $result=$ldap->connect_bind();
417
+
418
+                if ($result > 0)
419
+                {
420
+                    $info=$object->_load_ldap_info();
421
+                    $dn=$object->_load_ldap_dn($info);
422
+
423
+                    $result=$ldap->delete($dn);
424
+                }
425
+
426
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
427
+            }
428
+        }
429
+
430
+        // Members
431
+        elseif ($action == 'MEMBER_CREATE')
432
+        {
433
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
434
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
435
+            {
436
+                $ldap=new Ldap();
437
+                $result=$ldap->connect_bind();
438
+
439
+                if ($result > 0)
440
+                {
441
+                    $info=$object->_load_ldap_info();
442
+                    $dn=$object->_load_ldap_dn($info);
443
+
444
+                    $result=$ldap->add($dn,$info,$user);
445
+
446
+                    // For member type
447
+                    if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
448
+                    {
449
+                        $membertype=new AdherentType($this->db);
450
+                        if ($object->typeid > 0)
451
+                        {
452
+                            $membertype->fetch($object->typeid);
453
+                            $membertype->listMembersForMemberType('', 1);
454
+
455
+                            $oldinfo=$membertype->_load_ldap_info();
456
+                            $olddn=$membertype->_load_ldap_dn($oldinfo);
457
+
458
+                            // Verify if entry exist
459
+                            $container=$membertype->_load_ldap_dn($oldinfo,1);
460
+                            $search = "(".$membertype->_load_ldap_dn($oldinfo,2).")";
461
+                            $records=$ldap->search($container,$search);
462
+                            if (count($records) && $records['count'] == 0)
463
+                            {
464
+                                $olddn = '';
465
+                            }
466
+
467
+                            $info=$membertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
468
+                            $dn=$membertype->_load_ldap_dn($info);
469
+
470
+                            $result=$ldap->update($dn,$info,$user,$olddn);
471
+                        }
472
+                    }
473
+                }
474
+
475
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
476
+            }
477
+        }
478
+        elseif ($action == 'MEMBER_VALIDATE')
479
+        {
480
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
481
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
482
+            {
483
+                // If status field is setup to be synchronized
484
+                if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS))
485
+                {
486
+                    $ldap=new Ldap();
487
+                    $result=$ldap->connect_bind();
488
+
489
+                    if ($result > 0)
490
+                    {
491
+                        $info=$object->_load_ldap_info();
492
+                        $dn=$object->_load_ldap_dn($info);
493
+                        $olddn=$dn;	// We know olddn=dn as we change only status
494
+
495
+                        $result=$ldap->update($dn,$info,$user,$olddn);
496
+                    }
497
+
498
+                    if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
499
+                }
500
+            }
501
+        }
502
+        elseif ($action == 'MEMBER_SUBSCRIPTION')
503
+        {
504
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
505
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
506
+            {
507
+                // If subscriptions fields are setup to be synchronized
508
+                if ($conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_DATE
509
+                    || $conf->global->LDAP_FIELD_MEMBER_FIRSTSUBSCRIPTION_AMOUNT
510
+                    || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_DATE
511
+                    || $conf->global->LDAP_FIELD_MEMBER_LASTSUBSCRIPTION_AMOUNT
512
+                    || $conf->global->LDAP_FIELD_MEMBER_END_LASTSUBSCRIPTION)
513
+                {
514
+                    $ldap=new Ldap();
515
+                    $result=$ldap->connect_bind();
516
+
517
+                    if ($result > 0)
518
+                    {
519
+                        $info=$object->_load_ldap_info();
520
+                        $dn=$object->_load_ldap_dn($info);
521
+                        $olddn=$dn;	// We know olddn=dn as we change only subscriptions
522
+
523
+                        $result=$ldap->update($dn,$info,$user,$olddn);
524
+                    }
525
+
526
+                    if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
527
+                }
528
+            }
529
+        }
530
+        elseif ($action == 'MEMBER_MODIFY')
531
+        {
532
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
533
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
534
+            {
535
+                $ldap=new Ldap();
536
+                $result=$ldap->connect_bind();
537
+
538
+                if ($result > 0)
539
+                {
540
+                    if (empty($object->oldcopy) || ! is_object($object->oldcopy))
541
+                    {
542
+                        dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
543
+                        $object->oldcopy = clone $object;
544
+                    }
545
+
546
+                    $oldinfo=$object->oldcopy->_load_ldap_info();
547
+                    $olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
548
+
549
+                    // Verify if entry exist
550
+                    $container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
551
+                    $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
552
+                    $records=$ldap->search($container,$search);
553
+                    if (count($records) && $records['count'] == 0)
554
+                    {
555
+                        $olddn = '';
556
+                    }
557
+
558
+                    $info=$object->_load_ldap_info();
559
+                    $dn=$object->_load_ldap_dn($info);
560
+                    $newrdn=$object->_load_ldap_dn($info,2);
561
+                    $newparent=$object->_load_ldap_dn($info,1);
562
+
563
+                    $result=$ldap->update($dn,$info,$user,$olddn,$newrdn,$newparent);
564
+
565
+                    // For member type
566
+                    if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
567
+                    {
568
+                        /*
569 569
 						 * Change member info
570 570
 						 */
571
-						$newmembertype=new AdherentType($this->db);
572
-						$newmembertype->fetch($object->typeid);
573
-						$newmembertype->listMembersForMemberType('', 1);
574
-
575
-						$oldinfo=$newmembertype->_load_ldap_info();
576
-						$olddn=$newmembertype->_load_ldap_dn($oldinfo);
577
-
578
-						// Verify if entry exist
579
-						$container=$newmembertype->_load_ldap_dn($oldinfo,1);
580
-						$search = "(".$newmembertype->_load_ldap_dn($oldinfo,2).")";
581
-						$records=$ldap->search($container,$search);
582
-						if (count($records) && $records['count'] == 0)
583
-						{
584
-							$olddn = '';
585
-						}
586
-
587
-						$info=$newmembertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
588
-						$dn=$newmembertype->_load_ldap_dn($info);
589
-
590
-						$result=$ldap->update($dn,$info,$user,$olddn);
591
-
592
-						if ($object->oldcopy->typeid != $object->typeid)
593
-						{
594
-							/*
571
+                        $newmembertype=new AdherentType($this->db);
572
+                        $newmembertype->fetch($object->typeid);
573
+                        $newmembertype->listMembersForMemberType('', 1);
574
+
575
+                        $oldinfo=$newmembertype->_load_ldap_info();
576
+                        $olddn=$newmembertype->_load_ldap_dn($oldinfo);
577
+
578
+                        // Verify if entry exist
579
+                        $container=$newmembertype->_load_ldap_dn($oldinfo,1);
580
+                        $search = "(".$newmembertype->_load_ldap_dn($oldinfo,2).")";
581
+                        $records=$ldap->search($container,$search);
582
+                        if (count($records) && $records['count'] == 0)
583
+                        {
584
+                            $olddn = '';
585
+                        }
586
+
587
+                        $info=$newmembertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
588
+                        $dn=$newmembertype->_load_ldap_dn($info);
589
+
590
+                        $result=$ldap->update($dn,$info,$user,$olddn);
591
+
592
+                        if ($object->oldcopy->typeid != $object->typeid)
593
+                        {
594
+                            /*
595 595
 							 * Remove member in old member type
596 596
 							 */
597
-							$oldmembertype=new AdherentType($this->db);
598
-							$oldmembertype->fetch($object->oldcopy->typeid);
599
-							$oldmembertype->listMembersForMemberType('', 1);
600
-
601
-							$oldinfo=$oldmembertype->_load_ldap_info();
602
-							$olddn=$oldmembertype->_load_ldap_dn($oldinfo);
603
-
604
-							// Verify if entry exist
605
-							$container=$oldmembertype->_load_ldap_dn($oldinfo,1);
606
-							$search = "(".$oldmembertype->_load_ldap_dn($oldinfo,2).")";
607
-							$records=$ldap->search($container,$search);
608
-							if (count($records) && $records['count'] == 0)
609
-							{
610
-								$olddn = '';
611
-							}
612
-
613
-							$info=$oldmembertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
614
-							$dn=$oldmembertype->_load_ldap_dn($info);
615
-
616
-							$result=$ldap->update($dn,$info,$user,$olddn);
617
-						}
618
-					}
619
-				}
620
-
621
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
622
-			}
623
-		}
624
-		elseif ($action == 'MEMBER_NEW_PASSWORD')
625
-		{
626
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
627
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
628
-			{
629
-				// If password field is setup to be synchronized
630
-				if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED)
631
-				{
632
-					$ldap=new Ldap();
633
-					$result=$ldap->connect_bind();
634
-
635
-					if ($result > 0)
636
-					{
637
-						$info=$object->_load_ldap_info();
638
-						$dn=$object->_load_ldap_dn($info);
639
-						$olddn=$dn;	// We know olddn=dn as we change only password
640
-
641
-						$result=$ldap->update($dn,$info,$user,$olddn);
642
-					}
643
-
644
-					if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
645
-				}
646
-			}
647
-		}
648
-		elseif ($action == 'MEMBER_RESILIATE')
649
-		{
650
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
651
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
652
-			{
653
-				// If status field is setup to be synchronized
654
-				if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS))
655
-				{
656
-					$ldap=new Ldap();
657
-					$result=$ldap->connect_bind();
658
-
659
-					if ($result > 0)
660
-					{
661
-						$info=$object->_load_ldap_info();
662
-						$dn=$object->_load_ldap_dn($info);
663
-						$olddn=$dn;	// We know olddn=dn as we change only status
664
-
665
-						$result=$ldap->update($dn,$info,$user,$olddn);
666
-					}
667
-
668
-					if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
669
-				}
670
-			}
671
-		}
672
-		elseif ($action == 'MEMBER_DELETE')
673
-		{
674
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
675
-			if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
676
-			{
677
-				$ldap=new Ldap();
678
-				$result=$ldap->connect_bind();
679
-
680
-				if ($result > 0)
681
-				{
682
-					$info=$object->_load_ldap_info();
683
-					$dn=$object->_load_ldap_dn($info);
684
-
685
-					$result=$ldap->delete($dn);
686
-
687
-					// For member type
688
-					if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
689
-					{
690
-						if ($object->typeid > 0)
691
-						{
692
-							/*
597
+                            $oldmembertype=new AdherentType($this->db);
598
+                            $oldmembertype->fetch($object->oldcopy->typeid);
599
+                            $oldmembertype->listMembersForMemberType('', 1);
600
+
601
+                            $oldinfo=$oldmembertype->_load_ldap_info();
602
+                            $olddn=$oldmembertype->_load_ldap_dn($oldinfo);
603
+
604
+                            // Verify if entry exist
605
+                            $container=$oldmembertype->_load_ldap_dn($oldinfo,1);
606
+                            $search = "(".$oldmembertype->_load_ldap_dn($oldinfo,2).")";
607
+                            $records=$ldap->search($container,$search);
608
+                            if (count($records) && $records['count'] == 0)
609
+                            {
610
+                                $olddn = '';
611
+                            }
612
+
613
+                            $info=$oldmembertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
614
+                            $dn=$oldmembertype->_load_ldap_dn($info);
615
+
616
+                            $result=$ldap->update($dn,$info,$user,$olddn);
617
+                        }
618
+                    }
619
+                }
620
+
621
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
622
+            }
623
+        }
624
+        elseif ($action == 'MEMBER_NEW_PASSWORD')
625
+        {
626
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
627
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
628
+            {
629
+                // If password field is setup to be synchronized
630
+                if ($conf->global->LDAP_FIELD_PASSWORD || $conf->global->LDAP_FIELD_PASSWORD_CRYPTED)
631
+                {
632
+                    $ldap=new Ldap();
633
+                    $result=$ldap->connect_bind();
634
+
635
+                    if ($result > 0)
636
+                    {
637
+                        $info=$object->_load_ldap_info();
638
+                        $dn=$object->_load_ldap_dn($info);
639
+                        $olddn=$dn;	// We know olddn=dn as we change only password
640
+
641
+                        $result=$ldap->update($dn,$info,$user,$olddn);
642
+                    }
643
+
644
+                    if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
645
+                }
646
+            }
647
+        }
648
+        elseif ($action == 'MEMBER_RESILIATE')
649
+        {
650
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
651
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
652
+            {
653
+                // If status field is setup to be synchronized
654
+                if (! empty($conf->global->LDAP_FIELD_MEMBER_STATUS))
655
+                {
656
+                    $ldap=new Ldap();
657
+                    $result=$ldap->connect_bind();
658
+
659
+                    if ($result > 0)
660
+                    {
661
+                        $info=$object->_load_ldap_info();
662
+                        $dn=$object->_load_ldap_dn($info);
663
+                        $olddn=$dn;	// We know olddn=dn as we change only status
664
+
665
+                        $result=$ldap->update($dn,$info,$user,$olddn);
666
+                    }
667
+
668
+                    if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
669
+                }
670
+            }
671
+        }
672
+        elseif ($action == 'MEMBER_DELETE')
673
+        {
674
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
675
+            if (! empty($conf->global->LDAP_MEMBER_ACTIVE) && (string) $conf->global->LDAP_MEMBER_ACTIVE == '1')
676
+            {
677
+                $ldap=new Ldap();
678
+                $result=$ldap->connect_bind();
679
+
680
+                if ($result > 0)
681
+                {
682
+                    $info=$object->_load_ldap_info();
683
+                    $dn=$object->_load_ldap_dn($info);
684
+
685
+                    $result=$ldap->delete($dn);
686
+
687
+                    // For member type
688
+                    if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
689
+                    {
690
+                        if ($object->typeid > 0)
691
+                        {
692
+                            /*
693 693
 							 * Remove member in member type
694 694
 							 */
695
-							$membertype=new AdherentType($this->db);
696
-							$membertype->fetch($object->typeid);
697
-							$membertype->listMembersForMemberType('a.rowid != ' . $object->id, 1); // remove deleted member from the list
698
-
699
-							$oldinfo=$membertype->_load_ldap_info();
700
-							$olddn=$membertype->_load_ldap_dn($oldinfo);
701
-
702
-							// Verify if entry exist
703
-							$container=$membertype->_load_ldap_dn($oldinfo,1);
704
-							$search = "(".$membertype->_load_ldap_dn($oldinfo,2).")";
705
-							$records=$ldap->search($container,$search);
706
-							if (count($records) && $records['count'] == 0)
707
-							{
708
-								$olddn = '';
709
-							}
710
-
711
-							$info=$membertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
712
-							$dn=$membertype->_load_ldap_dn($info);
713
-
714
-							$result=$ldap->update($dn,$info,$user,$olddn);
715
-						}
716
-					}
717
-				}
718
-
719
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
720
-			}
721
-		}
722
-
723
-		// Members types
724
-		elseif ($action == 'MEMBER_TYPE_CREATE')
725
-		{
726
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
727
-			if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
728
-			{
729
-				$ldap=new Ldap();
730
-				$result=$ldap->connect_bind();
731
-
732
-				if ($result > 0)
733
-				{
734
-					$info=$object->_load_ldap_info();
735
-					$dn=$object->_load_ldap_dn($info);
736
-
737
-					// Get a gid number for objectclass PosixGroup
738
-					if (in_array('posixGroup',$info['objectclass'])) {
739
-						$info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPE');
740
-					}
741
-
742
-					$result=$ldap->add($dn,$info,$user);
743
-				}
744
-
745
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
746
-			}
747
-		}
748
-		elseif ($action == 'MEMBER_TYPE_MODIFY')
749
-		{
750
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
751
-			if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
752
-			{
753
-				$ldap=new Ldap();
754
-				$result=$ldap->connect_bind();
755
-
756
-				if ($result > 0)
757
-				{
758
-					if (empty($object->oldcopy) || ! is_object($object->oldcopy))
759
-					{
760
-						dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
761
-						$object->oldcopy = clone $object;
762
-					}
763
-
764
-					$object->oldcopy->listMembersForMemberType('', 1);
765
-
766
-					$oldinfo=$object->oldcopy->_load_ldap_info();
767
-					$olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
768
-
769
-					// Verify if entry exist
770
-					$container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
771
-					$search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
772
-					$records=$ldap->search($container,$search);
773
-					if (count($records) && $records['count'] == 0)
774
-					{
775
-						$olddn = '';
776
-					}
777
-
778
-					$object->listMembersForMemberType('', 1);
779
-
780
-					$info=$object->_load_ldap_info();
781
-					$dn=$object->_load_ldap_dn($info);
782
-
783
-					$result=$ldap->update($dn,$info,$user,$olddn);
784
-				}
785
-
786
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
787
-			}
788
-		}
789
-		elseif ($action == 'MEMBER_TYPE_DELETE')
790
-		{
791
-			dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
792
-			if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
793
-			{
794
-				$ldap=new Ldap();
795
-				$result=$ldap->connect_bind();
796
-
797
-				if ($result > 0)
798
-				{
799
-					$info=$object->_load_ldap_info();
800
-					$dn=$object->_load_ldap_dn($info);
801
-
802
-					$result=$ldap->delete($dn);
803
-				}
804
-
805
-				if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
806
-			}
807
-		}
808
-
809
-		return $result;
810
-	}
695
+                            $membertype=new AdherentType($this->db);
696
+                            $membertype->fetch($object->typeid);
697
+                            $membertype->listMembersForMemberType('a.rowid != ' . $object->id, 1); // remove deleted member from the list
698
+
699
+                            $oldinfo=$membertype->_load_ldap_info();
700
+                            $olddn=$membertype->_load_ldap_dn($oldinfo);
701
+
702
+                            // Verify if entry exist
703
+                            $container=$membertype->_load_ldap_dn($oldinfo,1);
704
+                            $search = "(".$membertype->_load_ldap_dn($oldinfo,2).")";
705
+                            $records=$ldap->search($container,$search);
706
+                            if (count($records) && $records['count'] == 0)
707
+                            {
708
+                                $olddn = '';
709
+                            }
710
+
711
+                            $info=$membertype->_load_ldap_info();    // Contains all members, included the new one (insert already done before trigger call)
712
+                            $dn=$membertype->_load_ldap_dn($info);
713
+
714
+                            $result=$ldap->update($dn,$info,$user,$olddn);
715
+                        }
716
+                    }
717
+                }
718
+
719
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
720
+            }
721
+        }
722
+
723
+        // Members types
724
+        elseif ($action == 'MEMBER_TYPE_CREATE')
725
+        {
726
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
727
+            if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
728
+            {
729
+                $ldap=new Ldap();
730
+                $result=$ldap->connect_bind();
731
+
732
+                if ($result > 0)
733
+                {
734
+                    $info=$object->_load_ldap_info();
735
+                    $dn=$object->_load_ldap_dn($info);
736
+
737
+                    // Get a gid number for objectclass PosixGroup
738
+                    if (in_array('posixGroup',$info['objectclass'])) {
739
+                        $info['gidNumber'] = $ldap->getNextGroupGid('LDAP_KEY_MEMBERS_TYPE');
740
+                    }
741
+
742
+                    $result=$ldap->add($dn,$info,$user);
743
+                }
744
+
745
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
746
+            }
747
+        }
748
+        elseif ($action == 'MEMBER_TYPE_MODIFY')
749
+        {
750
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
751
+            if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
752
+            {
753
+                $ldap=new Ldap();
754
+                $result=$ldap->connect_bind();
755
+
756
+                if ($result > 0)
757
+                {
758
+                    if (empty($object->oldcopy) || ! is_object($object->oldcopy))
759
+                    {
760
+                        dol_syslog("Trigger ".$action." was called by a function that did not set previously the property ->oldcopy onto object", LOG_WARNING);
761
+                        $object->oldcopy = clone $object;
762
+                    }
763
+
764
+                    $object->oldcopy->listMembersForMemberType('', 1);
765
+
766
+                    $oldinfo=$object->oldcopy->_load_ldap_info();
767
+                    $olddn=$object->oldcopy->_load_ldap_dn($oldinfo);
768
+
769
+                    // Verify if entry exist
770
+                    $container=$object->oldcopy->_load_ldap_dn($oldinfo,1);
771
+                    $search = "(".$object->oldcopy->_load_ldap_dn($oldinfo,2).")";
772
+                    $records=$ldap->search($container,$search);
773
+                    if (count($records) && $records['count'] == 0)
774
+                    {
775
+                        $olddn = '';
776
+                    }
777
+
778
+                    $object->listMembersForMemberType('', 1);
779
+
780
+                    $info=$object->_load_ldap_info();
781
+                    $dn=$object->_load_ldap_dn($info);
782
+
783
+                    $result=$ldap->update($dn,$info,$user,$olddn);
784
+                }
785
+
786
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
787
+            }
788
+        }
789
+        elseif ($action == 'MEMBER_TYPE_DELETE')
790
+        {
791
+            dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);
792
+            if (! empty($conf->global->LDAP_MEMBER_TYPE_ACTIVE) && (string) $conf->global->LDAP_MEMBER_TYPE_ACTIVE == '1')
793
+            {
794
+                $ldap=new Ldap();
795
+                $result=$ldap->connect_bind();
796
+
797
+                if ($result > 0)
798
+                {
799
+                    $info=$object->_load_ldap_info();
800
+                    $dn=$object->_load_ldap_dn($info);
801
+
802
+                    $result=$ldap->delete($dn);
803
+                }
804
+
805
+                if ($result < 0) $this->error="ErrorLDAP ".$ldap->error;
806
+            }
807
+        }
808
+
809
+        return $result;
810
+    }
811 811
 }
Please login to merge, or discard this patch.