Passed
Push — master ( 853f8f...c34860 )
by Alxarafe
25:12
created
dolibarr/htdocs/core/class/html.formintervention.class.php 3 patches
Indentation   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -33,9 +33,9 @@  discard block
 block discarded – undo
33 33
     public $db;
34 34
 
35 35
     /**
36
-	 * @var string Error code (or message)
37
-	 */
38
-	public $error='';
36
+     * @var string Error code (or message)
37
+     */
38
+    public $error='';
39 39
 
40 40
 
41 41
     /**
@@ -50,99 +50,99 @@  discard block
 block discarded – undo
50 50
 
51 51
 
52 52
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
53
-	/**
54
-	 *	Show a combo list with contracts qualified for a third party
55
-	 *
56
-	 *	@param	int		$socid      Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id)
57
-	 *	@param  int		$selected   Id intervention preselected
58
-	 *	@param  string	$htmlname   Nom de la zone html
59
-	 *	@param	int		$maxlength	Maximum length of label
60
-	 *	@param	int		$showempty	Show empty line
61
-	 *	@return int         		Nbre of project if OK, <0 if KO
62
-	 */
63
-	function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1)
64
-	{
53
+    /**
54
+     *	Show a combo list with contracts qualified for a third party
55
+     *
56
+     *	@param	int		$socid      Id third party (-1=all, 0=only interventions not linked to a third party, id=intervention not linked or linked to third party id)
57
+     *	@param  int		$selected   Id intervention preselected
58
+     *	@param  string	$htmlname   Nom de la zone html
59
+     *	@param	int		$maxlength	Maximum length of label
60
+     *	@param	int		$showempty	Show empty line
61
+     *	@return int         		Nbre of project if OK, <0 if KO
62
+     */
63
+    function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1)
64
+    {
65 65
         // phpcs:enable
66
-		global $db,$user,$conf,$langs;
66
+        global $db,$user,$conf,$langs;
67 67
 
68
-		$out='';
68
+        $out='';
69 69
 
70
-		$hideunselectables=false;
70
+        $hideunselectables=false;
71 71
 
72
-		// Search all contacts
73
-		$sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut';
74
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f';
75
-		$sql.= " WHERE f.entity = ".$conf->entity;
76
-		if ($socid != '')
77
-		{
78
-			if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
79
-			else $sql.= " AND f.fk_soc = ".$socid;
80
-		}
72
+        // Search all contacts
73
+        $sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut';
74
+        $sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f';
75
+        $sql.= " WHERE f.entity = ".$conf->entity;
76
+        if ($socid != '')
77
+        {
78
+            if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
79
+            else $sql.= " AND f.fk_soc = ".$socid;
80
+        }
81 81
 
82
-		dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
83
-		$resql=$db->query($sql);
84
-		if ($resql)
85
-		{
86
-			$out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
87
-			if ($showempty) $out.='<option value="0">&nbsp;</option>';
88
-			$num = $db->num_rows($resql);
89
-			$i = 0;
90
-			if ($num)
91
-			{
92
-				while ($i < $num)
93
-				{
94
-					$obj = $db->fetch_object($resql);
95
-					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
96
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
97
-					{
98
-						// Do nothing
99
-					}
100
-					else
101
-					{
102
-						$labeltoshow=dol_trunc($obj->ref,18);
103
-						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
104
-						{
105
-							$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
106
-						}
107
-						else
108
-						{
109
-							$disabled=0;
110
-							if (! $obj->fk_statut > 0)
111
-							{
112
-								$disabled=1;
113
-								$labeltoshow.=' ('.$langs->trans("Draft").')';
114
-							}
115
-							if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
116
-							{
117
-								$disabled=1;
118
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
119
-							}
82
+        dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
83
+        $resql=$db->query($sql);
84
+        if ($resql)
85
+        {
86
+            $out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
87
+            if ($showempty) $out.='<option value="0">&nbsp;</option>';
88
+            $num = $db->num_rows($resql);
89
+            $i = 0;
90
+            if ($num)
91
+            {
92
+                while ($i < $num)
93
+                {
94
+                    $obj = $db->fetch_object($resql);
95
+                    // If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
96
+                    if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
97
+                    {
98
+                        // Do nothing
99
+                    }
100
+                    else
101
+                    {
102
+                        $labeltoshow=dol_trunc($obj->ref,18);
103
+                        if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
104
+                        {
105
+                            $out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
106
+                        }
107
+                        else
108
+                        {
109
+                            $disabled=0;
110
+                            if (! $obj->fk_statut > 0)
111
+                            {
112
+                                $disabled=1;
113
+                                $labeltoshow.=' ('.$langs->trans("Draft").')';
114
+                            }
115
+                            if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
116
+                            {
117
+                                $disabled=1;
118
+                                $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
119
+                            }
120 120
 
121
-							if ($hideunselectables && $disabled)
122
-							{
123
-								$resultat='';
124
-							}
125
-							else
126
-							{
127
-								$resultat='<option value="'.$obj->rowid.'"';
128
-								if ($disabled) $resultat.=' disabled';
129
-								$resultat.='>'.$labeltoshow;
130
-								$resultat.='</option>';
131
-							}
132
-							$out.=$resultat;
133
-						}
134
-					}
135
-					$i++;
136
-				}
137
-			}
138
-			$out.='</select>';
139
-			$db->free($resql);
140
-			return $out;
141
-		}
142
-		else
143
-		{
144
-			dol_print_error($db);
145
-			return '';
146
-		}
147
-	}
121
+                            if ($hideunselectables && $disabled)
122
+                            {
123
+                                $resultat='';
124
+                            }
125
+                            else
126
+                            {
127
+                                $resultat='<option value="'.$obj->rowid.'"';
128
+                                if ($disabled) $resultat.=' disabled';
129
+                                $resultat.='>'.$labeltoshow;
130
+                                $resultat.='</option>';
131
+                            }
132
+                            $out.=$resultat;
133
+                        }
134
+                    }
135
+                    $i++;
136
+                }
137
+            }
138
+            $out.='</select>';
139
+            $db->free($resql);
140
+            return $out;
141
+        }
142
+        else
143
+        {
144
+            dol_print_error($db);
145
+            return '';
146
+        }
147
+    }
148 148
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     /**
36 36
 	 * @var string Error code (or message)
37 37
 	 */
38
-	public $error='';
38
+	public $error = '';
39 39
 
40 40
 
41 41
     /**
@@ -60,31 +60,31 @@  discard block
 block discarded – undo
60 60
 	 *	@param	int		$showempty	Show empty line
61 61
 	 *	@return int         		Nbre of project if OK, <0 if KO
62 62
 	 */
63
-	function select_interventions($socid=-1, $selected='', $htmlname='interventionid', $maxlength=16, $showempty=1)
63
+	function select_interventions($socid = -1, $selected = '', $htmlname = 'interventionid', $maxlength = 16, $showempty = 1)
64 64
 	{
65 65
         // phpcs:enable
66
-		global $db,$user,$conf,$langs;
66
+		global $db, $user, $conf, $langs;
67 67
 
68
-		$out='';
68
+		$out = '';
69 69
 
70
-		$hideunselectables=false;
70
+		$hideunselectables = false;
71 71
 
72 72
 		// Search all contacts
73 73
 		$sql = 'SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut';
74
-		$sql.= ' FROM '.MAIN_DB_PREFIX .'fichinter as f';
75
-		$sql.= " WHERE f.entity = ".$conf->entity;
74
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'fichinter as f';
75
+		$sql .= " WHERE f.entity = ".$conf->entity;
76 76
 		if ($socid != '')
77 77
 		{
78
-			if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
79
-			else $sql.= " AND f.fk_soc = ".$socid;
78
+			if ($socid == '0') $sql .= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
79
+			else $sql .= " AND f.fk_soc = ".$socid;
80 80
 		}
81 81
 
82 82
 		dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
83
-		$resql=$db->query($sql);
83
+		$resql = $db->query($sql);
84 84
 		if ($resql)
85 85
 		{
86
-			$out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
87
-			if ($showempty) $out.='<option value="0">&nbsp;</option>';
86
+			$out .= '<select id="interventionid" class="flat" name="'.$htmlname.'">';
87
+			if ($showempty) $out .= '<option value="0">&nbsp;</option>';
88 88
 			$num = $db->num_rows($resql);
89 89
 			$i = 0;
90 90
 			if ($num)
@@ -93,49 +93,49 @@  discard block
 block discarded – undo
93 93
 				{
94 94
 					$obj = $db->fetch_object($resql);
95 95
 					// If we ask to filter on a company and user has no permission to see all companies and project is linked to another company, we hide project.
96
-					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
96
+					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && !$user->rights->societe->lire)
97 97
 					{
98 98
 						// Do nothing
99 99
 					}
100 100
 					else
101 101
 					{
102
-						$labeltoshow=dol_trunc($obj->ref,18);
102
+						$labeltoshow = dol_trunc($obj->ref, 18);
103 103
 						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
104 104
 						{
105
-							$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
105
+							$out .= '<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
106 106
 						}
107 107
 						else
108 108
 						{
109
-							$disabled=0;
110
-							if (! $obj->fk_statut > 0)
109
+							$disabled = 0;
110
+							if (!$obj->fk_statut > 0)
111 111
 							{
112
-								$disabled=1;
113
-								$labeltoshow.=' ('.$langs->trans("Draft").')';
112
+								$disabled = 1;
113
+								$labeltoshow .= ' ('.$langs->trans("Draft").')';
114 114
 							}
115
-							if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid))
115
+							if ($socid > 0 && (!empty($obj->fk_soc) && $obj->fk_soc != $socid))
116 116
 							{
117
-								$disabled=1;
118
-								$labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany");
117
+								$disabled = 1;
118
+								$labeltoshow .= ' - '.$langs->trans("LinkedToAnotherCompany");
119 119
 							}
120 120
 
121 121
 							if ($hideunselectables && $disabled)
122 122
 							{
123
-								$resultat='';
123
+								$resultat = '';
124 124
 							}
125 125
 							else
126 126
 							{
127
-								$resultat='<option value="'.$obj->rowid.'"';
128
-								if ($disabled) $resultat.=' disabled';
129
-								$resultat.='>'.$labeltoshow;
130
-								$resultat.='</option>';
127
+								$resultat = '<option value="'.$obj->rowid.'"';
128
+								if ($disabled) $resultat .= ' disabled';
129
+								$resultat .= '>'.$labeltoshow;
130
+								$resultat .= '</option>';
131 131
 							}
132
-							$out.=$resultat;
132
+							$out .= $resultat;
133 133
 						}
134 134
 					}
135 135
 					$i++;
136 136
 				}
137 137
 			}
138
-			$out.='</select>';
138
+			$out .= '</select>';
139 139
 			$db->free($resql);
140 140
 			return $out;
141 141
 		}
Please login to merge, or discard this patch.
Braces   +15 added lines, -12 removed lines patch added patch discarded remove patch
@@ -75,8 +75,11 @@  discard block
 block discarded – undo
75 75
 		$sql.= " WHERE f.entity = ".$conf->entity;
76 76
 		if ($socid != '')
77 77
 		{
78
-			if ($socid == '0') $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
79
-			else $sql.= " AND f.fk_soc = ".$socid;
78
+			if ($socid == '0') {
79
+			    $sql.= " AND (f.fk_soc = 0 OR f.fk_soc IS NULL)";
80
+			} else {
81
+			    $sql.= " AND f.fk_soc = ".$socid;
82
+			}
80 83
 		}
81 84
 
82 85
 		dol_syslog(get_class($this)."::select_intervention", LOG_DEBUG);
@@ -84,7 +87,9 @@  discard block
 block discarded – undo
84 87
 		if ($resql)
85 88
 		{
86 89
 			$out.='<select id="interventionid" class="flat" name="'.$htmlname.'">';
87
-			if ($showempty) $out.='<option value="0">&nbsp;</option>';
90
+			if ($showempty) {
91
+			    $out.='<option value="0">&nbsp;</option>';
92
+			}
88 93
 			$num = $db->num_rows($resql);
89 94
 			$i = 0;
90 95
 			if ($num)
@@ -96,15 +101,13 @@  discard block
 block discarded – undo
96 101
 					if ($socid > 0 && (empty($obj->fk_soc) || $obj->fk_soc == $socid) && ! $user->rights->societe->lire)
97 102
 					{
98 103
 						// Do nothing
99
-					}
100
-					else
104
+					} else
101 105
 					{
102 106
 						$labeltoshow=dol_trunc($obj->ref,18);
103 107
 						if (!empty($selected) && $selected == $obj->rowid && $obj->statut > 0)
104 108
 						{
105 109
 							$out.='<option value="'.$obj->rowid.'" selected>'.$labeltoshow.'</option>';
106
-						}
107
-						else
110
+						} else
108 111
 						{
109 112
 							$disabled=0;
110 113
 							if (! $obj->fk_statut > 0)
@@ -121,11 +124,12 @@  discard block
 block discarded – undo
121 124
 							if ($hideunselectables && $disabled)
122 125
 							{
123 126
 								$resultat='';
124
-							}
125
-							else
127
+							} else
126 128
 							{
127 129
 								$resultat='<option value="'.$obj->rowid.'"';
128
-								if ($disabled) $resultat.=' disabled';
130
+								if ($disabled) {
131
+								    $resultat.=' disabled';
132
+								}
129 133
 								$resultat.='>'.$labeltoshow;
130 134
 								$resultat.='</option>';
131 135
 							}
@@ -138,8 +142,7 @@  discard block
 block discarded – undo
138 142
 			$out.='</select>';
139 143
 			$db->free($resql);
140 144
 			return $out;
141
-		}
142
-		else
145
+		} else
143 146
 		{
144 147
 			dol_print_error($db);
145 148
 			return '';
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/interfaces.class.php 3 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -36,12 +36,12 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public $db;
38 38
 
39
-	var $dir;				// Directory with all core and external triggers files
39
+    var $dir;				// Directory with all core and external triggers files
40 40
 
41 41
     /**
42
-	 * @var string[] Error codes (or messages)
43
-	 */
44
-	public $errors = array();
42
+     * @var string[] Error codes (or messages)
43
+     */
44
+    public $errors = array();
45 45
 
46 46
     /**
47 47
      *	Constructor
@@ -71,9 +71,9 @@  discard block
 block discarded – undo
71 71
         // Check parameters
72 72
         if (! is_object($object) || ! is_object($conf))	// Error
73 73
         {
74
-        	$this->error='function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf);
74
+            $this->error='function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf);
75 75
             dol_syslog(get_class($this).'::run_triggers '.$this->error, LOG_ERR);
76
-        	$this->errors[]=$this->error;
76
+            $this->errors[]=$this->error;
77 77
             return -1;
78 78
         }
79 79
         if (! is_object($langs))	// Warning
@@ -92,9 +92,9 @@  discard block
 block discarded – undo
92 92
         $files = array();
93 93
         $modules = array();
94 94
         $orders = array();
95
-		$i=0;
95
+        $i=0;
96 96
 
97
-		$dirtriggers=array_merge(array('/core/triggers'),$conf->modules_parts['triggers']);
97
+        $dirtriggers=array_merge(array('/core/triggers'),$conf->modules_parts['triggers']);
98 98
         foreach($dirtriggers as $reldir)
99 99
         {
100 100
             $dir=dol_buildpath($reldir,0);
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
                 {
112 112
                     if (is_readable($newdir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
113 113
                     {
114
-						$part1=$reg[1];
115
-						$part2=$reg[2];
116
-						$part3=$reg[3];
114
+                        $part1=$reg[1];
115
+                        $part2=$reg[2];
116
+                        $part3=$reg[3];
117 117
 
118 118
                         $nbfile++;
119 119
 
@@ -175,22 +175,22 @@  discard block
 block discarded – undo
175 175
             $objMod = new $modName($this->db);
176 176
             if ($objMod)
177 177
             {
178
-            	$result=0;
179
-
180
-				if (method_exists($objMod, 'runTrigger'))	// New method to implement
181
-				{
182
-	                //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG);
183
-	                $result=$objMod->runTrigger($action,$object,$user,$langs,$conf);
184
-				}
185
-				elseif (method_exists($objMod, 'run_trigger'))	// Deprecated method
186
-				{
187
-	                dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING);
188
-					$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
189
-				}
190
-				else
191
-				{
192
-	                dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR);
193
-				}
178
+                $result=0;
179
+
180
+                if (method_exists($objMod, 'runTrigger'))	// New method to implement
181
+                {
182
+                    //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG);
183
+                    $result=$objMod->runTrigger($action,$object,$user,$langs,$conf);
184
+                }
185
+                elseif (method_exists($objMod, 'run_trigger'))	// Deprecated method
186
+                {
187
+                    dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING);
188
+                    $result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
189
+                }
190
+                else
191
+                {
192
+                    dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR);
193
+                }
194 194
 
195 195
                 if ($result > 0)
196 196
                 {
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
                 }
216 216
             }
217 217
             else
218
-			{
218
+            {
219 219
                 dol_syslog(get_class($this)."::run_triggers action=".$action." Failed to instantiate trigger for file '".$files[$key]."'", LOG_ERR);
220 220
             }
221 221
         }
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         $dirtriggers=array_merge(array('/core/triggers/'),$conf->modules_parts['triggers']);
255 255
         if (is_array($forcedirtriggers))
256 256
         {
257
-        	$dirtriggers=$forcedirtriggers;
257
+            $dirtriggers=$forcedirtriggers;
258 258
         }
259 259
 
260 260
         foreach($dirtriggers as $reldir)
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
                     {
275 275
                         if (preg_match('/\.back$/',$file)) continue;
276 276
 
277
-						$part1=$reg[1];
278
-						$part2=$reg[2];
279
-						$part3=$reg[3];
277
+                        $part1=$reg[1];
278
+                        $part2=$reg[2];
279
+                        $part3=$reg[3];
280 280
 
281 281
                         $modName = 'Interface'.ucfirst($reg[3]);
282 282
                         //print "file=$file"; print "modName=$modName"; exit;
@@ -317,8 +317,8 @@  discard block
 block discarded – undo
317 317
 
318 318
             if (! class_exists($modName))
319 319
             {
320
-				print 'Error: A trigger file was found but its class "'.$modName.'" was not found.'."<br>\n";
321
-            	continue;
320
+                print 'Error: A trigger file was found but its class "'.$modName.'" was not found.'."<br>\n";
321
+                continue;
322 322
             }
323 323
 
324 324
             $objMod = new $modName($db);
@@ -340,7 +340,7 @@  discard block
 block discarded – undo
340 340
                 $triggers[$j]['module']=strtolower($module);
341 341
             }
342 342
 
343
-			// We set info of modules
343
+            // We set info of modules
344 344
             $triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
345 345
             $triggers[$j]['file'] = $files[$key];
346 346
             $triggers[$j]['fullpath'] = $fullpath[$key];
Please login to merge, or discard this patch.
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public $db;
38 38
 
39
-	var $dir;				// Directory with all core and external triggers files
39
+	var $dir; // Directory with all core and external triggers files
40 40
 
41 41
     /**
42 42
 	 * @var string[] Error codes (or messages)
@@ -65,22 +65,22 @@  discard block
 block discarded – undo
65 65
      *   @param     Conf		$conf       Objet conf
66 66
      *   @return    int         			Nb of triggers ran if no error, -Nb of triggers with errors otherwise.
67 67
      */
68
-    function run_triggers($action,$object,$user,$langs,$conf)
68
+    function run_triggers($action, $object, $user, $langs, $conf)
69 69
     {
70 70
         // phpcs:enable
71 71
         // Check parameters
72
-        if (! is_object($object) || ! is_object($conf))	// Error
72
+        if (!is_object($object) || !is_object($conf))	// Error
73 73
         {
74
-        	$this->error='function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf);
74
+        	$this->error = 'function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf);
75 75
             dol_syslog(get_class($this).'::run_triggers '.$this->error, LOG_ERR);
76
-        	$this->errors[]=$this->error;
76
+        	$this->errors[] = $this->error;
77 77
             return -1;
78 78
         }
79
-        if (! is_object($langs))	// Warning
79
+        if (!is_object($langs))	// Warning
80 80
         {
81 81
             dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
82 82
         }
83
-        if (! is_object($user))	    // Warning
83
+        if (!is_object($user))	    // Warning
84 84
         {
85 85
             dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
86 86
             global $db;
@@ -92,43 +92,43 @@  discard block
 block discarded – undo
92 92
         $files = array();
93 93
         $modules = array();
94 94
         $orders = array();
95
-		$i=0;
95
+		$i = 0;
96 96
 
97
-		$dirtriggers=array_merge(array('/core/triggers'),$conf->modules_parts['triggers']);
98
-        foreach($dirtriggers as $reldir)
97
+		$dirtriggers = array_merge(array('/core/triggers'), $conf->modules_parts['triggers']);
98
+        foreach ($dirtriggers as $reldir)
99 99
         {
100
-            $dir=dol_buildpath($reldir,0);
101
-            $newdir=dol_osencode($dir);
100
+            $dir = dol_buildpath($reldir, 0);
101
+            $newdir = dol_osencode($dir);
102 102
             //print "xx".$dir;exit;
103 103
 
104 104
             // Check if directory exists (we do not use dol_is_dir to avoir loading files.lib.php at each call)
105
-            if (! is_dir($newdir)) continue;
105
+            if (!is_dir($newdir)) continue;
106 106
 
107
-            $handle=opendir($newdir);
107
+            $handle = opendir($newdir);
108 108
             if (is_resource($handle))
109 109
             {
110
-                while (($file = readdir($handle))!==false)
110
+                while (($file = readdir($handle)) !== false)
111 111
                 {
112
-                    if (is_readable($newdir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i',$file,$reg))
112
+                    if (is_readable($newdir."/".$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php$/i', $file, $reg))
113 113
                     {
114
-						$part1=$reg[1];
115
-						$part2=$reg[2];
116
-						$part3=$reg[3];
114
+						$part1 = $reg[1];
115
+						$part2 = $reg[2];
116
+						$part3 = $reg[3];
117 117
 
118 118
                         $nbfile++;
119 119
 
120 120
                         // Check if trigger file is disabled by name
121
-                        if (preg_match('/NORUN$/i',$file)) continue;
121
+                        if (preg_match('/NORUN$/i', $file)) continue;
122 122
                         // Check if trigger file is for a particular module
123
-                        $qualified=true;
123
+                        $qualified = true;
124 124
                         if (strtolower($reg[2]) != 'all')
125 125
                         {
126
-                            $module=preg_replace('/^mod/i','',$reg[2]);
127
-                            $constparam='MAIN_MODULE_'.strtoupper($module);
128
-                            if (empty($conf->global->$constparam)) $qualified=false;
126
+                            $module = preg_replace('/^mod/i', '', $reg[2]);
127
+                            $constparam = 'MAIN_MODULE_'.strtoupper($module);
128
+                            if (empty($conf->global->$constparam)) $qualified = false;
129 129
                         }
130 130
 
131
-                        if (! $qualified)
131
+                        if (!$qualified)
132 132
                         {
133 133
                             //dol_syslog(get_class($this)."::run_triggers action=".$action." Triggers for file '".$file."' need module to be enabled", LOG_DEBUG);
134 134
                             continue;
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 
137 137
                         $modName = "Interface".ucfirst($reg[3]);
138 138
                         //print "file=$file - modName=$modName\n";
139
-                        if (in_array($modName,$modules))    // $modules = list of modName already loaded
139
+                        if (in_array($modName, $modules))    // $modules = list of modName already loaded
140 140
                         {
141 141
                             $langs->load("errors");
142 142
                             dol_syslog(get_class($this)."::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger", $newdir."/".$file, $fullpathfiles[$modName]), LOG_WARNING);
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
                             include_once $newdir.'/'.$file;
149 149
                             //print 'Done for '.$modName."\n";
150 150
                         }
151
-                        catch(Exception $e)
151
+                        catch (Exception $e)
152 152
                         {
153 153
                             dol_syslog('ko for '.$modName." ".$e->getMessage()."\n", LOG_ERR);
154 154
                         }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                         $modules[$i] = $modName;
157 157
                         $files[$i] = $file;
158 158
                         $fullpathfiles[$modName] = $newdir.'/'.$file;
159
-                        $orders[$i] = $part1.'_'.$part2.'_'.$part3;   // Set sort criteria value
159
+                        $orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value
160 160
 
161 161
                         $i++;
162 162
                     }
@@ -175,17 +175,17 @@  discard block
 block discarded – undo
175 175
             $objMod = new $modName($this->db);
176 176
             if ($objMod)
177 177
             {
178
-            	$result=0;
178
+            	$result = 0;
179 179
 
180 180
 				if (method_exists($objMod, 'runTrigger'))	// New method to implement
181 181
 				{
182 182
 	                //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG);
183
-	                $result=$objMod->runTrigger($action,$object,$user,$langs,$conf);
183
+	                $result = $objMod->runTrigger($action, $object, $user, $langs, $conf);
184 184
 				}
185 185
 				elseif (method_exists($objMod, 'run_trigger'))	// Deprecated method
186 186
 				{
187 187
 	                dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING);
188
-					$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
188
+					$result = $objMod->run_trigger($action, $object, $user, $langs, $conf);
189 189
 				}
190 190
 				else
191 191
 				{
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
                     //dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($objMod->errors), LOG_ERR);
210 210
                     $nbtotal++;
211 211
                     $nbko++;
212
-                    if (! empty($objMod->errors)) $this->errors=array_merge($this->errors,$objMod->errors);
213
-                    else if (! empty($objMod->error))  $this->errors[]=$objMod->error;
212
+                    if (!empty($objMod->errors)) $this->errors = array_merge($this->errors, $objMod->errors);
213
+                    else if (!empty($objMod->error))  $this->errors[] = $objMod->error;
214 214
                     //dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($this->errors), LOG_ERR);
215 215
                 }
216 216
             }
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      *	@param	array		$forcedirtriggers		null=All default directories. This parameter is used by modulebuilder module only.
240 240
      * 	@return	array								Array list of triggers
241 241
      */
242
-    function getTriggersList($forcedirtriggers=null)
242
+    function getTriggersList($forcedirtriggers = null)
243 243
     {
244 244
         global $conf, $langs, $db;
245 245
 
@@ -251,39 +251,39 @@  discard block
 block discarded – undo
251 251
         $orders = array();
252 252
         $i = 0;
253 253
 
254
-        $dirtriggers=array_merge(array('/core/triggers/'),$conf->modules_parts['triggers']);
254
+        $dirtriggers = array_merge(array('/core/triggers/'), $conf->modules_parts['triggers']);
255 255
         if (is_array($forcedirtriggers))
256 256
         {
257
-        	$dirtriggers=$forcedirtriggers;
257
+        	$dirtriggers = $forcedirtriggers;
258 258
         }
259 259
 
260
-        foreach($dirtriggers as $reldir)
260
+        foreach ($dirtriggers as $reldir)
261 261
         {
262
-            $dir=dol_buildpath($reldir,0);
263
-            $newdir=dol_osencode($dir);
262
+            $dir = dol_buildpath($reldir, 0);
263
+            $newdir = dol_osencode($dir);
264 264
 
265 265
             // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
266
-            if (! is_dir($newdir)) continue;
266
+            if (!is_dir($newdir)) continue;
267 267
 
268
-            $handle=opendir($newdir);
268
+            $handle = opendir($newdir);
269 269
             if (is_resource($handle))
270 270
             {
271
-                while (($file = readdir($handle))!==false)
271
+                while (($file = readdir($handle)) !== false)
272 272
                 {
273
-                    if (is_readable($newdir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/',$file,$reg))
273
+                    if (is_readable($newdir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/', $file, $reg))
274 274
                     {
275
-                        if (preg_match('/\.back$/',$file)) continue;
275
+                        if (preg_match('/\.back$/', $file)) continue;
276 276
 
277
-						$part1=$reg[1];
278
-						$part2=$reg[2];
279
-						$part3=$reg[3];
277
+						$part1 = $reg[1];
278
+						$part2 = $reg[2];
279
+						$part3 = $reg[3];
280 280
 
281 281
                         $modName = 'Interface'.ucfirst($reg[3]);
282 282
                         //print "file=$file"; print "modName=$modName"; exit;
283
-                        if (in_array($modName,$modules))
283
+                        if (in_array($modName, $modules))
284 284
                         {
285 285
                             $langs->load("errors");
286
-                            print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/").'</div>';
286
+                            print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger", $modName, "/htdocs/core/triggers/").'</div>';
287 287
                         }
288 288
                         else
289 289
                         {
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
 
293 293
                         $files[$i] = $file;
294 294
                         $fullpath[$i] = $dir.'/'.$file;
295
-                        $relpath[$i] = preg_replace('/^\//','',$reldir).'/'.$file;
296
-                        $iscoreorexternal[$i] = ($reldir == '/core/triggers/'?'internal':'external');
295
+                        $relpath[$i] = preg_replace('/^\//', '', $reldir).'/'.$file;
296
+                        $iscoreorexternal[$i] = ($reldir == '/core/triggers/' ? 'internal' : 'external');
297 297
                         $modules[$i] = $modName;
298
-                        $orders[$i] = $part1.'_'.$part2.'_'.$part3;   // Set sort criteria value
298
+                        $orders[$i] = $part1.'_'.$part2.'_'.$part3; // Set sort criteria value
299 299
 
300 300
                         $i++;
301 301
                     }
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
             $modName = $modules[$key];
316 316
             if (empty($modName)) continue;
317 317
 
318
-            if (! class_exists($modName))
318
+            if (!class_exists($modName))
319 319
             {
320 320
 				print 'Error: A trigger file was found but its class "'.$modName.'" was not found.'."<br>\n";
321 321
             	continue;
@@ -324,45 +324,45 @@  discard block
 block discarded – undo
324 324
             $objMod = new $modName($db);
325 325
 
326 326
             // Define disabledbyname and disabledbymodule
327
-            $disabledbyname=0;
328
-            $disabledbymodule=1;
329
-            $module='';
327
+            $disabledbyname = 0;
328
+            $disabledbymodule = 1;
329
+            $module = '';
330 330
 
331 331
             // Check if trigger file is disabled by name
332
-            if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1;
332
+            if (preg_match('/NORUN$/i', $files[$key])) $disabledbyname = 1;
333 333
             // Check if trigger file is for a particular module
334
-            if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
334
+            if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i', $files[$key], $reg))
335 335
             {
336
-                $module=preg_replace('/^mod/i','',$reg[2]);
337
-                $constparam='MAIN_MODULE_'.strtoupper($module);
338
-                if (strtolower($module) == 'all') $disabledbymodule=0;
339
-                else if (empty($conf->global->$constparam)) $disabledbymodule=2;
340
-                $triggers[$j]['module']=strtolower($module);
336
+                $module = preg_replace('/^mod/i', '', $reg[2]);
337
+                $constparam = 'MAIN_MODULE_'.strtoupper($module);
338
+                if (strtolower($module) == 'all') $disabledbymodule = 0;
339
+                else if (empty($conf->global->$constparam)) $disabledbymodule = 2;
340
+                $triggers[$j]['module'] = strtolower($module);
341 341
             }
342 342
 
343 343
 			// We set info of modules
344
-            $triggers[$j]['picto'] = $objMod->picto?img_object('',$objMod->picto):img_object('','generic');
344
+            $triggers[$j]['picto'] = $objMod->picto ?img_object('', $objMod->picto) : img_object('', 'generic');
345 345
             $triggers[$j]['file'] = $files[$key];
346 346
             $triggers[$j]['fullpath'] = $fullpath[$key];
347 347
             $triggers[$j]['relpath'] = $relpath[$key];
348 348
             $triggers[$j]['iscoreorexternal'] = $iscoreorexternal[$key];
349 349
             $triggers[$j]['version'] = $objMod->getVersion();
350
-            $triggers[$j]['status'] = img_picto($langs->trans("Active"),'tick');
350
+            $triggers[$j]['status'] = img_picto($langs->trans("Active"), 'tick');
351 351
             if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = '';
352 352
 
353
-            $text ='<b>'.$langs->trans("Description").':</b><br>';
354
-            $text.=$objMod->getDesc().'<br>';
355
-            $text.='<br><b>'.$langs->trans("Status").':</b><br>';
353
+            $text = '<b>'.$langs->trans("Description").':</b><br>';
354
+            $text .= $objMod->getDesc().'<br>';
355
+            $text .= '<br><b>'.$langs->trans("Status").':</b><br>';
356 356
             if ($disabledbyname == 1)
357 357
             {
358
-                $text.=$langs->trans("TriggerDisabledByName").'<br>';
359
-                if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
358
+                $text .= $langs->trans("TriggerDisabledByName").'<br>';
359
+                if ($disabledbymodule == 2) $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module).'<br>';
360 360
             }
361 361
             else
362 362
             {
363
-                if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'<br>';
364
-                if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
365
-                if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
363
+                if ($disabledbymodule == 0) $text .= $langs->trans("TriggerAlwaysActive").'<br>';
364
+                if ($disabledbymodule == 1) $text .= $langs->trans("TriggerActiveAsModuleActive", $module).'<br>';
365
+                if ($disabledbymodule == 2) $text .= $langs->trans("TriggerDisabledAsModuleDisabled", $module).'<br>';
366 366
             }
367 367
 
368 368
             $triggers[$j]['info'] = $text;
Please login to merge, or discard this patch.
Braces   +72 added lines, -35 removed lines patch added patch discarded remove patch
@@ -69,20 +69,26 @@  discard block
 block discarded – undo
69 69
     {
70 70
         // phpcs:enable
71 71
         // Check parameters
72
-        if (! is_object($object) || ! is_object($conf))	// Error
72
+        if (! is_object($object) || ! is_object($conf)) {
73
+            // Error
73 74
         {
74 75
         	$this->error='function run_triggers called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf);
76
+        }
75 77
             dol_syslog(get_class($this).'::run_triggers '.$this->error, LOG_ERR);
76 78
         	$this->errors[]=$this->error;
77 79
             return -1;
78 80
         }
79
-        if (! is_object($langs))	// Warning
81
+        if (! is_object($langs)) {
82
+            // Warning
80 83
         {
81 84
             dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
82 85
         }
83
-        if (! is_object($user))	    // Warning
86
+        }
87
+        if (! is_object($user)) {
88
+            // Warning
84 89
         {
85 90
             dol_syslog(get_class($this).'::run_triggers was called with wrong parameters action='.$action.' object='.is_object($object).' user='.is_object($user).' langs='.is_object($langs).' conf='.is_object($conf), LOG_WARNING);
91
+        }
86 92
             global $db;
87 93
             $user = new User($db);
88 94
         }
@@ -102,7 +108,9 @@  discard block
 block discarded – undo
102 108
             //print "xx".$dir;exit;
103 109
 
104 110
             // Check if directory exists (we do not use dol_is_dir to avoir loading files.lib.php at each call)
105
-            if (! is_dir($newdir)) continue;
111
+            if (! is_dir($newdir)) {
112
+                continue;
113
+            }
106 114
 
107 115
             $handle=opendir($newdir);
108 116
             if (is_resource($handle))
@@ -118,14 +126,18 @@  discard block
 block discarded – undo
118 126
                         $nbfile++;
119 127
 
120 128
                         // Check if trigger file is disabled by name
121
-                        if (preg_match('/NORUN$/i',$file)) continue;
129
+                        if (preg_match('/NORUN$/i',$file)) {
130
+                            continue;
131
+                        }
122 132
                         // Check if trigger file is for a particular module
123 133
                         $qualified=true;
124 134
                         if (strtolower($reg[2]) != 'all')
125 135
                         {
126 136
                             $module=preg_replace('/^mod/i','',$reg[2]);
127 137
                             $constparam='MAIN_MODULE_'.strtoupper($module);
128
-                            if (empty($conf->global->$constparam)) $qualified=false;
138
+                            if (empty($conf->global->$constparam)) {
139
+                                $qualified=false;
140
+                            }
129 141
                         }
130 142
 
131 143
                         if (! $qualified)
@@ -136,9 +148,11 @@  discard block
 block discarded – undo
136 148
 
137 149
                         $modName = "Interface".ucfirst($reg[3]);
138 150
                         //print "file=$file - modName=$modName\n";
139
-                        if (in_array($modName,$modules))    // $modules = list of modName already loaded
151
+                        if (in_array($modName,$modules)) {
152
+                            // $modules = list of modName already loaded
140 153
                         {
141 154
                             $langs->load("errors");
155
+                        }
142 156
                             dol_syslog(get_class($this)."::run_triggers action=".$action." ".$langs->trans("ErrorDuplicateTrigger", $newdir."/".$file, $fullpathfiles[$modName]), LOG_WARNING);
143 157
                             continue;
144 158
                         }
@@ -147,8 +161,7 @@  discard block
 block discarded – undo
147 161
                             //print 'Todo for '.$modName." : ".$newdir.'/'.$file."\n";
148 162
                             include_once $newdir.'/'.$file;
149 163
                             //print 'Done for '.$modName."\n";
150
-                        }
151
-                        catch(Exception $e)
164
+                        } catch(Exception $e)
152 165
                         {
153 166
                             dol_syslog('ko for '.$modName." ".$e->getMessage()."\n", LOG_ERR);
154 167
                         }
@@ -170,24 +183,28 @@  discard block
 block discarded – undo
170 183
         foreach ($orders as $key => $value)
171 184
         {
172 185
             $modName = $modules[$key];
173
-            if (empty($modName)) continue;
186
+            if (empty($modName)) {
187
+                continue;
188
+            }
174 189
 
175 190
             $objMod = new $modName($this->db);
176 191
             if ($objMod)
177 192
             {
178 193
             	$result=0;
179 194
 
180
-				if (method_exists($objMod, 'runTrigger'))	// New method to implement
195
+				if (method_exists($objMod, 'runTrigger')) {
196
+				    // New method to implement
181 197
 				{
182 198
 	                //dol_syslog(get_class($this)."::run_triggers action=".$action." Launch runTrigger for file '".$files[$key]."'", LOG_DEBUG);
183 199
 	                $result=$objMod->runTrigger($action,$object,$user,$langs,$conf);
184 200
 				}
185
-				elseif (method_exists($objMod, 'run_trigger'))	// Deprecated method
201
+				} elseif (method_exists($objMod, 'run_trigger')) {
202
+				    // Deprecated method
186 203
 				{
187 204
 	                dol_syslog(get_class($this)."::run_triggers action=".$action." Launch old method run_trigger (rename your trigger into runTrigger) for file '".$files[$key]."'", LOG_WARNING);
188
-					$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
189 205
 				}
190
-				else
206
+					$result=$objMod->run_trigger($action,$object,$user,$langs,$conf);
207
+				} else
191 208
 				{
192 209
 	                dol_syslog(get_class($this)."::run_triggers action=".$action." A trigger was declared for class ".get_class($objMod)." but method runTrigger was not found", LOG_ERR);
193 210
 				}
@@ -209,12 +226,14 @@  discard block
 block discarded – undo
209 226
                     //dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($objMod->errors), LOG_ERR);
210 227
                     $nbtotal++;
211 228
                     $nbko++;
212
-                    if (! empty($objMod->errors)) $this->errors=array_merge($this->errors,$objMod->errors);
213
-                    else if (! empty($objMod->error))  $this->errors[]=$objMod->error;
229
+                    if (! empty($objMod->errors)) {
230
+                        $this->errors=array_merge($this->errors,$objMod->errors);
231
+                    } else if (! empty($objMod->error)) {
232
+                        $this->errors[]=$objMod->error;
233
+                    }
214 234
                     //dol_syslog("Error in trigger ".$action." - Nb of error string returned = ".count($this->errors), LOG_ERR);
215 235
                 }
216
-            }
217
-            else
236
+            } else
218 237
 			{
219 238
                 dol_syslog(get_class($this)."::run_triggers action=".$action." Failed to instantiate trigger for file '".$files[$key]."'", LOG_ERR);
220 239
             }
@@ -224,8 +243,7 @@  discard block
 block discarded – undo
224 243
         {
225 244
             dol_syslog(get_class($this)."::run_triggers action=".$action." Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko." - Nb of error string returned in this->errors = ".count($this->errors), LOG_ERR);
226 245
             return -$nbko;
227
-        }
228
-        else
246
+        } else
229 247
         {
230 248
             //dol_syslog(get_class($this)."::run_triggers Files found: ".$nbfile.", Files launched: ".$nbtotal.", Done: ".$nbok.", Failed: ".$nbko, LOG_DEBUG);
231 249
             return $nbok;
@@ -263,7 +281,9 @@  discard block
 block discarded – undo
263 281
             $newdir=dol_osencode($dir);
264 282
 
265 283
             // Check if directory exists (we do not use dol_is_dir to avoid loading files.lib.php at each call)
266
-            if (! is_dir($newdir)) continue;
284
+            if (! is_dir($newdir)) {
285
+                continue;
286
+            }
267 287
 
268 288
             $handle=opendir($newdir);
269 289
             if (is_resource($handle))
@@ -272,7 +292,9 @@  discard block
 block discarded – undo
272 292
                 {
273 293
                     if (is_readable($newdir.'/'.$file) && preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/',$file,$reg))
274 294
                     {
275
-                        if (preg_match('/\.back$/',$file)) continue;
295
+                        if (preg_match('/\.back$/',$file)) {
296
+                            continue;
297
+                        }
276 298
 
277 299
 						$part1=$reg[1];
278 300
 						$part2=$reg[2];
@@ -284,8 +306,7 @@  discard block
 block discarded – undo
284 306
                         {
285 307
                             $langs->load("errors");
286 308
                             print '<div class="error">'.$langs->trans("Error").' : '.$langs->trans("ErrorDuplicateTrigger",$modName,"/htdocs/core/triggers/").'</div>';
287
-                        }
288
-                        else
309
+                        } else
289 310
                         {
290 311
                             include_once $newdir.'/'.$file;
291 312
                         }
@@ -313,7 +334,9 @@  discard block
 block discarded – undo
313 334
         foreach ($orders as $key => $value)
314 335
         {
315 336
             $modName = $modules[$key];
316
-            if (empty($modName)) continue;
337
+            if (empty($modName)) {
338
+                continue;
339
+            }
317 340
 
318 341
             if (! class_exists($modName))
319 342
             {
@@ -329,14 +352,19 @@  discard block
 block discarded – undo
329 352
             $module='';
330 353
 
331 354
             // Check if trigger file is disabled by name
332
-            if (preg_match('/NORUN$/i',$files[$key])) $disabledbyname=1;
355
+            if (preg_match('/NORUN$/i',$files[$key])) {
356
+                $disabledbyname=1;
357
+            }
333 358
             // Check if trigger file is for a particular module
334 359
             if (preg_match('/^interface_([0-9]+)_([^_]+)_(.+)\.class\.php/i',$files[$key],$reg))
335 360
             {
336 361
                 $module=preg_replace('/^mod/i','',$reg[2]);
337 362
                 $constparam='MAIN_MODULE_'.strtoupper($module);
338
-                if (strtolower($module) == 'all') $disabledbymodule=0;
339
-                else if (empty($conf->global->$constparam)) $disabledbymodule=2;
363
+                if (strtolower($module) == 'all') {
364
+                    $disabledbymodule=0;
365
+                } else if (empty($conf->global->$constparam)) {
366
+                    $disabledbymodule=2;
367
+                }
340 368
                 $triggers[$j]['module']=strtolower($module);
341 369
             }
342 370
 
@@ -348,7 +376,9 @@  discard block
 block discarded – undo
348 376
             $triggers[$j]['iscoreorexternal'] = $iscoreorexternal[$key];
349 377
             $triggers[$j]['version'] = $objMod->getVersion();
350 378
             $triggers[$j]['status'] = img_picto($langs->trans("Active"),'tick');
351
-            if ($disabledbyname > 0 || $disabledbymodule > 1) $triggers[$j]['status'] = '';
379
+            if ($disabledbyname > 0 || $disabledbymodule > 1) {
380
+                $triggers[$j]['status'] = '';
381
+            }
352 382
 
353 383
             $text ='<b>'.$langs->trans("Description").':</b><br>';
354 384
             $text.=$objMod->getDesc().'<br>';
@@ -356,13 +386,20 @@  discard block
 block discarded – undo
356 386
             if ($disabledbyname == 1)
357 387
             {
358 388
                 $text.=$langs->trans("TriggerDisabledByName").'<br>';
359
-                if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
360
-            }
361
-            else
389
+                if ($disabledbymodule == 2) {
390
+                    $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
391
+                }
392
+            } else
362 393
             {
363
-                if ($disabledbymodule == 0) $text.=$langs->trans("TriggerAlwaysActive").'<br>';
364
-                if ($disabledbymodule == 1) $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
365
-                if ($disabledbymodule == 2) $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
394
+                if ($disabledbymodule == 0) {
395
+                    $text.=$langs->trans("TriggerAlwaysActive").'<br>';
396
+                }
397
+                if ($disabledbymodule == 1) {
398
+                    $text.=$langs->trans("TriggerActiveAsModuleActive",$module).'<br>';
399
+                }
400
+                if ($disabledbymodule == 2) {
401
+                    $text.=$langs->trans("TriggerDisabledAsModuleDisabled",$module).'<br>';
402
+                }
366 403
             }
367 404
 
368 405
             $triggers[$j]['info'] = $text;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/google.class.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -26,63 +26,63 @@
 block discarded – undo
26 26
  */
27 27
 class GoogleAPI
28 28
 {
29
-	/**
29
+    /**
30 30
      * @var DoliDB Database handler.
31 31
      */
32 32
     public $db;
33 33
 
34
-	/**
35
-	 * @var string Error code (or message)
36
-	 */
37
-	public $error='';
34
+    /**
35
+     * @var string Error code (or message)
36
+     */
37
+    public $error='';
38 38
 
39
-	public $key;
39
+    public $key;
40 40
 
41
-	/**
42
-	 * Constructor
43
-	 *
44
-	 * @param 	DoliDB		$db			Database handler
45
-	 * @param	string		$key		Google key
46
-	 */
47
-	function __construct($db,$key)
48
-	{
49
-		$this->db=$db;
50
-		$this->key=$key;
51
-	}
41
+    /**
42
+     * Constructor
43
+     *
44
+     * @param 	DoliDB		$db			Database handler
45
+     * @param	string		$key		Google key
46
+     */
47
+    function __construct($db,$key)
48
+    {
49
+        $this->db=$db;
50
+        $this->key=$key;
51
+    }
52 52
 
53 53
 
54
-	/**
55
-	 *  Return geo coordinates of an address
56
-	 *
57
-	 *  @param	string	$address	Address
58
-	 * 								Example: 68 Grande rue Charles de Gaulle,+94130,+Nogent sur Marne,+France
59
-	 *								Example: 188, rue de Fontenay,+94300,+Vincennes,+France
60
-	 *	@return	string				Coordinates
61
-	 */
62
-	function getGeoCoordinatesOfAddress($address)
63
-	{
64
-		global $conf;
54
+    /**
55
+     *  Return geo coordinates of an address
56
+     *
57
+     *  @param	string	$address	Address
58
+     * 								Example: 68 Grande rue Charles de Gaulle,+94130,+Nogent sur Marne,+France
59
+     *								Example: 188, rue de Fontenay,+94300,+Vincennes,+France
60
+     *	@return	string				Coordinates
61
+     */
62
+    function getGeoCoordinatesOfAddress($address)
63
+    {
64
+        global $conf;
65 65
 
66
-		$i=0;
66
+        $i=0;
67 67
 
68
-		// Desired address
69
-		$urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key;
68
+        // Desired address
69
+        $urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key;
70 70
 
71
-		// Retrieve the URL contents
72
-		$page = file_get_contents($urladdress);
71
+        // Retrieve the URL contents
72
+        $page = file_get_contents($urladdress);
73 73
 
74
-		$code = strstr($page, '<coordinates>');
75
-		$code = strstr($code, '>');
76
-		$val=strpos($code, "<");
77
-		$code = substr($code, 1, $val-1);
78
-		//print $code;
79
-		//print "<br>";
80
-		$latitude = substr($code, 0, strpos($code, ","));
81
-		$longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3);
74
+        $code = strstr($page, '<coordinates>');
75
+        $code = strstr($code, '>');
76
+        $val=strpos($code, "<");
77
+        $code = substr($code, 1, $val-1);
78
+        //print $code;
79
+        //print "<br>";
80
+        $latitude = substr($code, 0, strpos($code, ","));
81
+        $longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3);
82 82
 
83
-		// Output the coordinates
84
-		//echo "Longitude: $longitude ',' Latitude: $latitude";
83
+        // Output the coordinates
84
+        //echo "Longitude: $longitude ',' Latitude: $latitude";
85 85
 
86
-		$i++;
87
-	}
86
+        $i++;
87
+    }
88 88
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 	/**
35 35
 	 * @var string Error code (or message)
36 36
 	 */
37
-	public $error='';
37
+	public $error = '';
38 38
 
39 39
 	public $key;
40 40
 
@@ -44,10 +44,10 @@  discard block
 block discarded – undo
44 44
 	 * @param 	DoliDB		$db			Database handler
45 45
 	 * @param	string		$key		Google key
46 46
 	 */
47
-	function __construct($db,$key)
47
+	function __construct($db, $key)
48 48
 	{
49
-		$this->db=$db;
50
-		$this->key=$key;
49
+		$this->db = $db;
50
+		$this->key = $key;
51 51
 	}
52 52
 
53 53
 
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	{
64 64
 		global $conf;
65 65
 
66
-		$i=0;
66
+		$i = 0;
67 67
 
68 68
 		// Desired address
69 69
 		$urladdress = "https://maps.google.com/maps/geo?q=".urlencode($address)."&output=xml&key=".$this->key;
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 
74 74
 		$code = strstr($page, '<coordinates>');
75 75
 		$code = strstr($code, '>');
76
-		$val=strpos($code, "<");
77
-		$code = substr($code, 1, $val-1);
76
+		$val = strpos($code, "<");
77
+		$code = substr($code, 1, $val - 1);
78 78
 		//print $code;
79 79
 		//print "<br>";
80 80
 		$latitude = substr($code, 0, strpos($code, ","));
81
-		$longitude = substr($code, strpos($code, ",")+1, dol_strlen(strpos($code, ","))-3);
81
+		$longitude = substr($code, strpos($code, ",") + 1, dol_strlen(strpos($code, ",")) - 3);
82 82
 
83 83
 		// Output the coordinates
84 84
 		//echo "Longitude: $longitude ',' Latitude: $latitude";
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formactions.class.php 3 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -35,15 +35,15 @@  discard block
 block discarded – undo
35 35
     public $db;
36 36
 
37 37
     /**
38
-	 * @var string Error code (or message)
39
-	 */
40
-	public $error='';
38
+     * @var string Error code (or message)
39
+     */
40
+    public $error='';
41 41
 
42 42
 
43 43
     /**
44
-	 *	Constructor
45
-	 *
46
-	 *  @param		DoliDB		$db      Database handler
44
+     *	Constructor
45
+     *
46
+     *  @param		DoliDB		$db      Database handler
47 47
      */
48 48
     function __construct($db)
49 49
     {
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             '50' => $langs->trans("ActionRunningShort"),
76 76
             '100' => $langs->trans("ActionDoneShort")
77 77
         );
78
-		// +ActionUncomplete
78
+        // +ActionUncomplete
79 79
 
80 80
         if (! empty($conf->use_javascript_ajax))
81 81
         {
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
         }
128 128
         if (! empty($conf->use_javascript_ajax) || $onlyselect)
129 129
         {
130
-        	//var_dump($selected);
131
-        	if ($selected == 'done') $selected='100';
130
+            //var_dump($selected);
131
+            if ($selected == 'done') $selected='100';
132 132
             print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
133 133
             if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
134 134
             foreach($listofstatus as $key => $val)
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
137 137
                 if ($key == '50' && $onlyselect == 2)
138 138
                 {
139
-                	print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
139
+                    print '<option value="todo"'.($selected == 'todo' ? ' selected' : '').'>'.$langs->trans("ActionUncomplete").' ('.$langs->trans("ActionsToDoShort")."+".$langs->trans("ActionRunningShort").')</option>';
140 140
                 }
141 141
             }
142 142
             print '</select>';
@@ -144,12 +144,12 @@  discard block
 block discarded – undo
144 144
 
145 145
             if (empty($onlyselect))
146 146
             {
147
-	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
148
-    	        print '<span class="hideonsmartphone hideifna">%</span>';
147
+                print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
148
+                print '<span class="hideonsmartphone hideifna">%</span>';
149 149
             }
150 150
         }
151 151
         else
152
-		{
152
+        {
153 153
             print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
154 154
         }
155 155
     }
@@ -179,18 +179,18 @@  discard block
 block discarded – undo
179 179
         $sortorder='DESC,DESC';
180 180
 
181 181
         $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
182
-		if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
182
+        if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
183 183
 
184 184
         $num = count($listofactions);
185 185
         if ($num || $forceshowtitle)
186 186
         {
187
-        	if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
188
-        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
189
-        	elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
190
-        	elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
191
-        	elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
192
-        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
193
-        	elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
187
+            if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
188
+            elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
189
+            elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
190
+            elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
191
+            elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
192
+            elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
193
+            elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
194 194
             elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
195 195
             elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
196 196
             elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
@@ -203,111 +203,111 @@  discard block
 block discarded – undo
203 203
             if ($typeelement == 'project') $projectid = $object->id;
204 204
 
205 205
             $newcardbutton='';
206
-			if (! empty($conf->agenda->enabled))
207
-			{
208
-				$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.($object->socid>0?'&socid='.$object->socid:($socid>0?'&socid='.$socid:'')).($projectid>0?'&projectid='.$projectid:'').'&backtopage='.urlencode($urlbacktopage).'"><span class="valignmiddle">'.$langs->trans("AddEvent").'</span>';
209
-				$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
210
-				$newcardbutton.= '</a>';
211
-			}
212
-
213
-        	print '<!-- formactions->showactions -->'."\n";
214
-        	print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlright);
215
-
216
-        	$page=0; $param='';
217
-
218
-        	$total = 0;
219
-
220
-        	print '<div class="div-table-responsive-no-min">';
221
-        	print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
222
-        	print '<tr class="liste_titre">';
223
-        	print getTitleFieldOfList('Ref',   0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
224
-        	print getTitleFieldOfList('By',    0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
225
-        	print getTitleFieldOfList('Type',  0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
226
-        	print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
227
-        	print getTitleFieldOfList('Date',  0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
228
-        	print getTitleFieldOfList('',      0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
229
-        	print '</tr>';
230
-        	print "\n";
231
-
232
-        	$userstatic = new User($this->db);
233
-
234
-        	if (count($listofactions))
235
-        	{
236
-	        	$cursorevent = 0;
237
-	        	foreach($listofactions as $action)
238
-	        	{
239
-	        		if ($max && $cursorevent >= $max) break;
240
-
241
-	        		$ref=$action->getNomUrl(1,-1);
242
-	        		$label=$action->getNomUrl(0,38);
243
-
244
-	        		print '<tr class="oddeven">';
245
-	        		// Ref
246
-					print '<td>'.$ref.'</td>';
247
-					// Onwer
248
-	        		print '<td>';
249
-	        		if (! empty($action->userownerid))
250
-	        		{
251
-	        			$userstatic->fetch($action->userownerid);	// TODO Introduce a cache on users fetched
252
-	        			print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
253
-	        		}
254
-	        		print '</td>';
255
-					// Type
256
-	        		print '<td>';
257
-					$imgpicto='';
258
-					if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
259
-					{
260
-						if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
261
-						else {
262
-							if ($action->type_code == 'AC_RDV')       $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
263
-							elseif ($action->type_code == 'AC_TEL')   $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
264
-							elseif ($action->type_code == 'AC_FAX')   $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
265
-							elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
266
-							elseif ($action->type_code == 'AC_INT')   $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
267
-							elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
268
-						}
269
-					}
270
-					print $imgpicto;
271
-	        		print $action->type_short ? $action->type_short : $action->type;
272
-	        		print '</td>';
273
-	        		// Label
274
-	        		print '<td>'.$label.'</td>';
275
-	        		// Date
276
-	        		print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
277
-	        		if ($action->datef)
278
-	        		{
279
-		        		$tmpa=dol_getdate($action->datep);
280
-		        		$tmpb=dol_getdate($action->datef);
281
-		        		if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
282
-		        		{
283
-		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
284
-		        		}
285
-		        		else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
286
-	        		}
287
-	        		print '</td>';
288
-	        		print '<td align="right">';
289
-	        		if (! empty($action->author->id))
290
-	        		{
291
-	        			print $action->getLibStatut(3);
292
-	        		}
293
-	        		print '</td>';
294
-	        		print '</tr>';
295
-
296
-	        		$cursorevent++;
297
-	        	}
298
-        	}
299
-        	else
300
-        	{
301
-        		print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
302
-        	}
303
-
304
-        	if ($max && $num > $max)
305
-        	{
306
-        		print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
307
-        	}
308
-
309
-        	print '</table>';
310
-        	print '</div>';
206
+            if (! empty($conf->agenda->enabled))
207
+            {
208
+                $newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.($object->socid>0?'&socid='.$object->socid:($socid>0?'&socid='.$socid:'')).($projectid>0?'&projectid='.$projectid:'').'&backtopage='.urlencode($urlbacktopage).'"><span class="valignmiddle">'.$langs->trans("AddEvent").'</span>';
209
+                $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
210
+                $newcardbutton.= '</a>';
211
+            }
212
+
213
+            print '<!-- formactions->showactions -->'."\n";
214
+            print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlright);
215
+
216
+            $page=0; $param='';
217
+
218
+            $total = 0;
219
+
220
+            print '<div class="div-table-responsive-no-min">';
221
+            print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
222
+            print '<tr class="liste_titre">';
223
+            print getTitleFieldOfList('Ref',   0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
224
+            print getTitleFieldOfList('By',    0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
225
+            print getTitleFieldOfList('Type',  0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
226
+            print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
227
+            print getTitleFieldOfList('Date',  0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
228
+            print getTitleFieldOfList('',      0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
229
+            print '</tr>';
230
+            print "\n";
231
+
232
+            $userstatic = new User($this->db);
233
+
234
+            if (count($listofactions))
235
+            {
236
+                $cursorevent = 0;
237
+                foreach($listofactions as $action)
238
+                {
239
+                    if ($max && $cursorevent >= $max) break;
240
+
241
+                    $ref=$action->getNomUrl(1,-1);
242
+                    $label=$action->getNomUrl(0,38);
243
+
244
+                    print '<tr class="oddeven">';
245
+                    // Ref
246
+                    print '<td>'.$ref.'</td>';
247
+                    // Onwer
248
+                    print '<td>';
249
+                    if (! empty($action->userownerid))
250
+                    {
251
+                        $userstatic->fetch($action->userownerid);	// TODO Introduce a cache on users fetched
252
+                        print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
253
+                    }
254
+                    print '</td>';
255
+                    // Type
256
+                    print '<td>';
257
+                    $imgpicto='';
258
+                    if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
259
+                    {
260
+                        if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
261
+                        else {
262
+                            if ($action->type_code == 'AC_RDV')       $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
263
+                            elseif ($action->type_code == 'AC_TEL')   $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
264
+                            elseif ($action->type_code == 'AC_FAX')   $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
265
+                            elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
266
+                            elseif ($action->type_code == 'AC_INT')   $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
267
+                            elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
268
+                        }
269
+                    }
270
+                    print $imgpicto;
271
+                    print $action->type_short ? $action->type_short : $action->type;
272
+                    print '</td>';
273
+                    // Label
274
+                    print '<td>'.$label.'</td>';
275
+                    // Date
276
+                    print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
277
+                    if ($action->datef)
278
+                    {
279
+                        $tmpa=dol_getdate($action->datep);
280
+                        $tmpb=dol_getdate($action->datef);
281
+                        if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
282
+                        {
283
+                            if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
284
+                        }
285
+                        else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
286
+                    }
287
+                    print '</td>';
288
+                    print '<td align="right">';
289
+                    if (! empty($action->author->id))
290
+                    {
291
+                        print $action->getLibStatut(3);
292
+                    }
293
+                    print '</td>';
294
+                    print '</tr>';
295
+
296
+                    $cursorevent++;
297
+                }
298
+            }
299
+            else
300
+            {
301
+                print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
302
+            }
303
+
304
+            if ($max && $num > $max)
305
+            {
306
+                print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("More").'...</td></tr>';
307
+            }
308
+
309
+            print '</table>';
310
+            print '</div>';
311 311
         }
312 312
 
313 313
         return $num;
@@ -338,27 +338,27 @@  discard block
 block discarded – undo
338 338
         require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
339 339
         $caction=new CActionComm($this->db);
340 340
 
341
-       	// Suggest a list with manual events or all auto events
342
-       	$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
343
-       	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
344
-       	//asort($arraylist);
341
+            // Suggest a list with manual events or all auto events
342
+            $arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
343
+            array_unshift($arraylist,'&nbsp;');     // Add empty line at start
344
+            //asort($arraylist);
345 345
 
346
-       	if ($selected == 'manual') $selected='AC_OTH';
347
-       	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
346
+            if ($selected == 'manual') $selected='AC_OTH';
347
+            if ($selected == 'auto')   $selected='AC_OTH_AUTO';
348 348
 
349
-       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
349
+            if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
350 350
 
351
-       	$out='';
351
+            $out='';
352 352
 
353
-		if (! empty($multiselect))
354
-		{
355
-	        if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
356
-			$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
357
-		}
358
-		else
359
-		{
360
-			$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
361
-		}
353
+        if (! empty($multiselect))
354
+        {
355
+            if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
356
+            $out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
357
+        }
358
+        else
359
+        {
360
+            $out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
361
+        }
362 362
 
363 363
         if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
364 364
         {
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
     /**
38 38
 	 * @var string Error code (or message)
39 39
 	 */
40
-	public $error='';
40
+	public $error = '';
41 41
 
42 42
 
43 43
     /**
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
      *  @param  string  $morecss        More css on select field
65 65
      * 	@return	void
66 66
      */
67
-    function form_select_status_action($formname, $selected, $canedit=1, $htmlname='complete', $showempty=0, $onlyselect=0, $morecss='maxwidth100')
67
+    function form_select_status_action($formname, $selected, $canedit = 1, $htmlname = 'complete', $showempty = 0, $onlyselect = 0, $morecss = 'maxwidth100')
68 68
     {
69 69
         // phpcs:enable
70
-        global $langs,$conf;
70
+        global $langs, $conf;
71 71
 
72 72
         $listofstatus = array(
73 73
             '-1' => $langs->trans("ActionNotApplicable"),
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
         );
78 78
 		// +ActionUncomplete
79 79
 
80
-        if (! empty($conf->use_javascript_ajax))
80
+        if (!empty($conf->use_javascript_ajax))
81 81
         {
82 82
             print "\n";
83 83
             print "<script type=\"text/javascript\">
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
                 function select_status() {
99 99
                     var defaultvalue = $('#select' + htmlname).val();
100 100
                     var percentage = $('input[name=percentage]');
101
-                    var selected = '".(isset($selected)?$selected:'')."';
101
+                    var selected = '".(isset($selected) ? $selected : '')."';
102 102
                     var value = (selected>0?selected:(defaultvalue>=0?defaultvalue:''));
103 103
 
104 104
                     percentage.val(value);
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
                 }
126 126
                 </script>\n";
127 127
         }
128
-        if (! empty($conf->use_javascript_ajax) || $onlyselect)
128
+        if (!empty($conf->use_javascript_ajax) || $onlyselect)
129 129
         {
130 130
         	//var_dump($selected);
131
-        	if ($selected == 'done') $selected='100';
132
-            print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
133
-            if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
134
-            foreach($listofstatus as $key => $val)
131
+        	if ($selected == 'done') $selected = '100';
132
+            print '<select '.($canedit ? '' : 'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss ? ' '.$morecss : '').'">';
133
+            if ($showempty) print '<option value=""'.($selected == '' ? ' selected' : '').'></option>';
134
+            foreach ($listofstatus as $key => $val)
135 135
             {
136 136
                 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
137 137
                 if ($key == '50' && $onlyselect == 2)
@@ -140,17 +140,17 @@  discard block
 block discarded – undo
140 140
                 }
141 141
             }
142 142
             print '</select>';
143
-            if ($selected == 0 || $selected == 100) $canedit=0;
143
+            if ($selected == 0 || $selected == 100) $canedit = 0;
144 144
 
145 145
             if (empty($onlyselect))
146 146
             {
147
-	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
147
+	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit && ($selected >= 0) ? '' : ' disabled').'>';
148 148
     	        print '<span class="hideonsmartphone hideifna">%</span>';
149 149
             }
150 150
         }
151 151
         else
152 152
 		{
153
-            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
153
+            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected >= 0 ? $selected : '').'" size="2"'.($canedit ? '' : ' disabled').'>%';
154 154
         }
155 155
     }
156 156
 
@@ -168,64 +168,64 @@  discard block
 block discarded – undo
168 168
      *  @param	string	$morehtmlright			More html text on right of title line
169 169
      *	@return	int								<0 if KO, >=0 if OK
170 170
      */
171
-    function showactions($object, $typeelement, $socid=0, $forceshowtitle=0, $morecss='listactions', $max=0, $moreparambacktopage='', $morehtmlright='')
171
+    function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlright = '')
172 172
     {
173
-        global $langs,$conf,$user;
173
+        global $langs, $conf, $user;
174 174
         global $bc;
175 175
 
176 176
         require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
177 177
 
178
-        $sortfield='a.datep,a.id';
179
-        $sortorder='DESC,DESC';
178
+        $sortfield = 'a.datep,a.id';
179
+        $sortorder = 'DESC,DESC';
180 180
 
181
-        $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
182
-		if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
181
+        $listofactions = ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0));
182
+		if (!is_array($listofactions)) dol_print_error($this->db, 'FailedToGetActions');
183 183
 
184 184
         $num = count($listofactions);
185 185
         if ($num || $forceshowtitle)
186 186
         {
187
-        	if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
188
-        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
189
-        	elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
190
-        	elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
191
-        	elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
192
-        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
193
-        	elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
194
-            elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
195
-            elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
196
-            elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
197
-            elseif ($typeelement == 'member')            $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
198
-            else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
199
-
200
-            $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
187
+        	if ($typeelement == 'invoice')               $title = $langs->trans('ActionsOnBill');
188
+        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title = $langs->trans('ActionsOnBill');
189
+        	elseif ($typeelement == 'propal')            $title = $langs->trans('ActionsOnPropal');
190
+        	elseif ($typeelement == 'supplier_proposal') $title = $langs->trans('ActionsOnSupplierProposal');
191
+        	elseif ($typeelement == 'order')             $title = $langs->trans('ActionsOnOrder');
192
+        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title = $langs->trans('ActionsOnOrder');
193
+        	elseif ($typeelement == 'shipping')          $title = $langs->trans('ActionsOnShipping');
194
+            elseif ($typeelement == 'fichinter')         $title = $langs->trans('ActionsOnFicheInter');
195
+            elseif ($typeelement == 'project')           $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
196
+            elseif ($typeelement == 'task')              $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
197
+            elseif ($typeelement == 'member')            $title = $langs->trans('LatestLinkedEvents', $max ? $max : '');
198
+            else $title = $langs->trans("LatestLinkedEvents", $max ? $max : '');
199
+
200
+            $urlbacktopage = $_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage ? '&'.$moreparambacktopage : '');
201 201
 
202 202
             $projectid = $object->fk_project;
203 203
             if ($typeelement == 'project') $projectid = $object->id;
204 204
 
205
-            $newcardbutton='';
206
-			if (! empty($conf->agenda->enabled))
205
+            $newcardbutton = '';
206
+			if (!empty($conf->agenda->enabled))
207 207
 			{
208
-				$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(),'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.($object->socid>0?'&socid='.$object->socid:($socid>0?'&socid='.$socid:'')).($projectid>0?'&projectid='.$projectid:'').'&backtopage='.urlencode($urlbacktopage).'"><span class="valignmiddle">'.$langs->trans("AddEvent").'</span>';
209
-				$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
210
-				$newcardbutton.= '</a>';
208
+				$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.dol_print_date(dol_now(), 'dayhourlog').'&origin='.$typeelement.'&originid='.$object->id.($object->socid > 0 ? '&socid='.$object->socid : ($socid > 0 ? '&socid='.$socid : '')).($projectid > 0 ? '&projectid='.$projectid : '').'&backtopage='.urlencode($urlbacktopage).'"><span class="valignmiddle">'.$langs->trans("AddEvent").'</span>';
209
+				$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>';
210
+				$newcardbutton .= '</a>';
211 211
 			}
212 212
 
213 213
         	print '<!-- formactions->showactions -->'."\n";
214 214
         	print load_fiche_titre($title, $newcardbutton, '', 0, 0, '', $morehtmlright);
215 215
 
216
-        	$page=0; $param='';
216
+        	$page = 0; $param = '';
217 217
 
218 218
         	$total = 0;
219 219
 
220 220
         	print '<div class="div-table-responsive-no-min">';
221
-        	print '<table class="noborder'.($morecss?' '.$morecss:'').'" width="100%">';
221
+        	print '<table class="noborder'.($morecss ? ' '.$morecss : '').'" width="100%">';
222 222
         	print '<tr class="liste_titre">';
223
-        	print getTitleFieldOfList('Ref',   0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
224
-        	print getTitleFieldOfList('By',    0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
225
-        	print getTitleFieldOfList('Type',  0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
223
+        	print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
224
+        	print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
225
+        	print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
226 226
         	print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1);
227
-        	print getTitleFieldOfList('Date',  0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
228
-        	print getTitleFieldOfList('',      0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
227
+        	print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, 'align="center"', $sortfield, $sortorder, '', 1);
228
+        	print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, 'align="right"', $sortfield, $sortorder, '', 1);
229 229
         	print '</tr>';
230 230
         	print "\n";
231 231
 
@@ -234,37 +234,37 @@  discard block
 block discarded – undo
234 234
         	if (count($listofactions))
235 235
         	{
236 236
 	        	$cursorevent = 0;
237
-	        	foreach($listofactions as $action)
237
+	        	foreach ($listofactions as $action)
238 238
 	        	{
239 239
 	        		if ($max && $cursorevent >= $max) break;
240 240
 
241
-	        		$ref=$action->getNomUrl(1,-1);
242
-	        		$label=$action->getNomUrl(0,38);
241
+	        		$ref = $action->getNomUrl(1, -1);
242
+	        		$label = $action->getNomUrl(0, 38);
243 243
 
244 244
 	        		print '<tr class="oddeven">';
245 245
 	        		// Ref
246 246
 					print '<td>'.$ref.'</td>';
247 247
 					// Onwer
248 248
 	        		print '<td>';
249
-	        		if (! empty($action->userownerid))
249
+	        		if (!empty($action->userownerid))
250 250
 	        		{
251
-	        			$userstatic->fetch($action->userownerid);	// TODO Introduce a cache on users fetched
251
+	        			$userstatic->fetch($action->userownerid); // TODO Introduce a cache on users fetched
252 252
 	        			print $userstatic->getNomUrl(-1, '', 0, 0, 16, 0, '', '');
253 253
 	        		}
254 254
 	        		print '</td>';
255 255
 					// Type
256 256
 	        		print '<td>';
257
-					$imgpicto='';
258
-					if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
257
+					$imgpicto = '';
258
+					if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
259 259
 					{
260
-						if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
260
+						if ($action->type_picto) $imgpicto = img_picto('', $action->type_picto);
261 261
 						else {
262
-							if ($action->type_code == 'AC_RDV')       $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
263
-							elseif ($action->type_code == 'AC_TEL')   $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
264
-							elseif ($action->type_code == 'AC_FAX')   $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
265
-							elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
266
-							elseif ($action->type_code == 'AC_INT')   $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
267
-							elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
262
+							if ($action->type_code == 'AC_RDV')       $imgpicto = img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
263
+							elseif ($action->type_code == 'AC_TEL')   $imgpicto = img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
264
+							elseif ($action->type_code == 'AC_FAX')   $imgpicto = img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
265
+							elseif ($action->type_code == 'AC_EMAIL') $imgpicto = img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
266
+							elseif ($action->type_code == 'AC_INT')   $imgpicto = img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
267
+							elseif (!preg_match('/_AUTO/', $action->type_code)) $imgpicto = img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
268 268
 						}
269 269
 					}
270 270
 					print $imgpicto;
@@ -276,8 +276,8 @@  discard block
 block discarded – undo
276 276
 	        		print '<td align="center">'.dol_print_date($action->datep, 'dayhour', 'tzuserrel');
277 277
 	        		if ($action->datef)
278 278
 	        		{
279
-		        		$tmpa=dol_getdate($action->datep);
280
-		        		$tmpb=dol_getdate($action->datef);
279
+		        		$tmpa = dol_getdate($action->datep);
280
+		        		$tmpb = dol_getdate($action->datef);
281 281
 		        		if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
282 282
 		        		{
283 283
 		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	        		}
287 287
 	        		print '</td>';
288 288
 	        		print '<td align="right">';
289
-	        		if (! empty($action->author->id))
289
+	        		if (!empty($action->author->id))
290 290
 	        		{
291 291
 	        			print $action->getLibStatut(3);
292 292
 	        		}
@@ -327,42 +327,42 @@  discard block
 block discarded – undo
327 327
      *  @param  int             $nooutput       1=No output
328 328
      * 	@return	string
329 329
      */
330
-    function select_type_actions($selected='', $htmlname='actioncode', $excludetype='', $onlyautoornot=0, $hideinfohelp=0, $multiselect=0, $nooutput=0)
330
+    function select_type_actions($selected = '', $htmlname = 'actioncode', $excludetype = '', $onlyautoornot = 0, $hideinfohelp = 0, $multiselect = 0, $nooutput = 0)
331 331
     {
332 332
         // phpcs:enable
333
-        global $langs,$user,$form,$conf;
333
+        global $langs, $user, $form, $conf;
334 334
 
335
-        if (! is_object($form)) $form=new Form($this->db);
335
+        if (!is_object($form)) $form = new Form($this->db);
336 336
 
337 337
         require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
338 338
         require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
339
-        $caction=new CActionComm($this->db);
339
+        $caction = new CActionComm($this->db);
340 340
 
341 341
        	// Suggest a list with manual events or all auto events
342
-       	$arraylist=$caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
343
-       	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
342
+       	$arraylist = $caction->liste_array(1, 'code', $excludetype, $onlyautoornot);
343
+       	array_unshift($arraylist, '&nbsp;'); // Add empty line at start
344 344
        	//asort($arraylist);
345 345
 
346
-       	if ($selected == 'manual') $selected='AC_OTH';
347
-       	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
346
+       	if ($selected == 'manual') $selected = 'AC_OTH';
347
+       	if ($selected == 'auto')   $selected = 'AC_OTH_AUTO';
348 348
 
349
-       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
349
+       	if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
350 350
 
351
-       	$out='';
351
+       	$out = '';
352 352
 
353
-		if (! empty($multiselect))
353
+		if (!empty($multiselect))
354 354
 		{
355 355
 	        if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
356
-			$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
356
+			$out .= $form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
357 357
 		}
358 358
 		else
359 359
 		{
360
-			$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
360
+			$out .= $form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
361 361
 		}
362 362
 
363 363
         if ($user->admin && empty($onlyautoornot) && $hideinfohelp <= 0)
364 364
         {
365
-            $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
365
+            $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''), 1);
366 366
         }
367 367
 
368 368
         if ($nooutput) return $out;
Please login to merge, or discard this patch.
Braces   +87 added lines, -41 removed lines patch added patch discarded remove patch
@@ -128,9 +128,13 @@  discard block
 block discarded – undo
128 128
         if (! empty($conf->use_javascript_ajax) || $onlyselect)
129 129
         {
130 130
         	//var_dump($selected);
131
-        	if ($selected == 'done') $selected='100';
131
+        	if ($selected == 'done') {
132
+        	    $selected='100';
133
+        	}
132 134
             print '<select '.($canedit?'':'disabled ').'name="'.$htmlname.'" id="select'.$htmlname.'" class="flat'.($morecss?' '.$morecss:'').'">';
133
-            if ($showempty) print '<option value=""'.($selected == ''?' selected':'').'></option>';
135
+            if ($showempty) {
136
+                print '<option value=""'.($selected == ''?' selected':'').'></option>';
137
+            }
134 138
             foreach($listofstatus as $key => $val)
135 139
             {
136 140
                 print '<option value="'.$key.'"'.(($selected == $key && strlen($selected) == strlen($key)) || (($selected > 0 && $selected < 100) && $key == '50') ? ' selected' : '').'>'.$val.'</option>';
@@ -140,15 +144,16 @@  discard block
 block discarded – undo
140 144
                 }
141 145
             }
142 146
             print '</select>';
143
-            if ($selected == 0 || $selected == 100) $canedit=0;
147
+            if ($selected == 0 || $selected == 100) {
148
+                $canedit=0;
149
+            }
144 150
 
145 151
             if (empty($onlyselect))
146 152
             {
147 153
 	            print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat hideifna" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit&&($selected>=0)?'':' disabled').'>';
148 154
     	        print '<span class="hideonsmartphone hideifna">%</span>';
149 155
             }
150
-        }
151
-        else
156
+        } else
152 157
 		{
153 158
             print ' <input type="text" id="val'.$htmlname.'" name="percentage" class="flat" value="'.($selected>=0?$selected:'').'" size="2"'.($canedit?'':' disabled').'>%';
154 159
         }
@@ -179,28 +184,45 @@  discard block
 block discarded – undo
179 184
         $sortorder='DESC,DESC';
180 185
 
181 186
         $listofactions=ActionComm::getActions($this->db, $socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max?($max+1):0));
182
-		if (! is_array($listofactions)) dol_print_error($this->db,'FailedToGetActions');
187
+		if (! is_array($listofactions)) {
188
+		    dol_print_error($this->db,'FailedToGetActions');
189
+		}
183 190
 
184 191
         $num = count($listofactions);
185 192
         if ($num || $forceshowtitle)
186 193
         {
187
-        	if ($typeelement == 'invoice')               $title=$langs->trans('ActionsOnBill');
188
-        	elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') $title=$langs->trans('ActionsOnBill');
189
-        	elseif ($typeelement == 'propal')            $title=$langs->trans('ActionsOnPropal');
190
-        	elseif ($typeelement == 'supplier_proposal') $title=$langs->trans('ActionsOnSupplierProposal');
191
-        	elseif ($typeelement == 'order')             $title=$langs->trans('ActionsOnOrder');
192
-        	elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order')   $title=$langs->trans('ActionsOnOrder');
193
-        	elseif ($typeelement == 'shipping')          $title=$langs->trans('ActionsOnShipping');
194
-            elseif ($typeelement == 'fichinter')         $title=$langs->trans('ActionsOnFicheInter');
195
-            elseif ($typeelement == 'project')           $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
196
-            elseif ($typeelement == 'task')              $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
197
-            elseif ($typeelement == 'member')            $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
198
-            else $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
194
+        	if ($typeelement == 'invoice') {
195
+        	    $title=$langs->trans('ActionsOnBill');
196
+        	} elseif ($typeelement == 'invoice_supplier' || $typeelement == 'supplier_invoice') {
197
+        	    $title=$langs->trans('ActionsOnBill');
198
+        	} elseif ($typeelement == 'propal') {
199
+        	    $title=$langs->trans('ActionsOnPropal');
200
+        	} elseif ($typeelement == 'supplier_proposal') {
201
+        	    $title=$langs->trans('ActionsOnSupplierProposal');
202
+        	} elseif ($typeelement == 'order') {
203
+        	    $title=$langs->trans('ActionsOnOrder');
204
+        	} elseif ($typeelement == 'order_supplier' || $typeelement == 'supplier_order') {
205
+        	    $title=$langs->trans('ActionsOnOrder');
206
+        	} elseif ($typeelement == 'shipping') {
207
+        	    $title=$langs->trans('ActionsOnShipping');
208
+        	} elseif ($typeelement == 'fichinter') {
209
+                $title=$langs->trans('ActionsOnFicheInter');
210
+            } elseif ($typeelement == 'project') {
211
+                $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
212
+            } elseif ($typeelement == 'task') {
213
+                $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
214
+            } elseif ($typeelement == 'member') {
215
+                $title=$langs->trans('LatestLinkedEvents', $max?$max:'');
216
+            } else {
217
+                $title=$langs->trans("LatestLinkedEvents", $max?$max:'');
218
+            }
199 219
 
200 220
             $urlbacktopage=$_SERVER['PHP_SELF'].'?id='.$object->id.($moreparambacktopage?'&'.$moreparambacktopage:'');
201 221
 
202 222
             $projectid = $object->fk_project;
203
-            if ($typeelement == 'project') $projectid = $object->id;
223
+            if ($typeelement == 'project') {
224
+                $projectid = $object->id;
225
+            }
204 226
 
205 227
             $newcardbutton='';
206 228
 			if (! empty($conf->agenda->enabled))
@@ -236,7 +258,9 @@  discard block
 block discarded – undo
236 258
 	        	$cursorevent = 0;
237 259
 	        	foreach($listofactions as $action)
238 260
 	        	{
239
-	        		if ($max && $cursorevent >= $max) break;
261
+	        		if ($max && $cursorevent >= $max) {
262
+	        		    break;
263
+	        		}
240 264
 
241 265
 	        		$ref=$action->getNomUrl(1,-1);
242 266
 	        		$label=$action->getNomUrl(0,38);
@@ -257,14 +281,22 @@  discard block
 block discarded – undo
257 281
 					$imgpicto='';
258 282
 					if (! empty($conf->global->AGENDA_USE_EVENT_TYPE))
259 283
 					{
260
-						if ($action->type_picto) $imgpicto=img_picto('', $action->type_picto);
261
-						else {
262
-							if ($action->type_code == 'AC_RDV')       $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
263
-							elseif ($action->type_code == 'AC_TEL')   $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
264
-							elseif ($action->type_code == 'AC_FAX')   $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
265
-							elseif ($action->type_code == 'AC_EMAIL') $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
266
-							elseif ($action->type_code == 'AC_INT')   $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
267
-							elseif (! preg_match('/_AUTO/', $action->type_code)) $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
284
+						if ($action->type_picto) {
285
+						    $imgpicto=img_picto('', $action->type_picto);
286
+						} else {
287
+							if ($action->type_code == 'AC_RDV') {
288
+							    $imgpicto=img_picto('', 'object_group', '', false, 0, 0, '', 'paddingright').' ';
289
+							} elseif ($action->type_code == 'AC_TEL') {
290
+							    $imgpicto=img_picto('', 'object_phoning', '', false, 0, 0, '', 'paddingright').' ';
291
+							} elseif ($action->type_code == 'AC_FAX') {
292
+							    $imgpicto=img_picto('', 'object_phoning_fax', '', false, 0, 0, '', 'paddingright').' ';
293
+							} elseif ($action->type_code == 'AC_EMAIL') {
294
+							    $imgpicto=img_picto('', 'object_email', '', false, 0, 0, '', 'paddingright').' ';
295
+							} elseif ($action->type_code == 'AC_INT') {
296
+							    $imgpicto=img_picto('', 'object_intervention', '', false, 0, 0, '', 'paddingright').' ';
297
+							} elseif (! preg_match('/_AUTO/', $action->type_code)) {
298
+							    $imgpicto=img_picto('', 'object_action', '', false, 0, 0, '', 'paddingright').' ';
299
+							}
268 300
 						}
269 301
 					}
270 302
 					print $imgpicto;
@@ -280,9 +312,12 @@  discard block
 block discarded – undo
280 312
 		        		$tmpb=dol_getdate($action->datef);
281 313
 		        		if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year'])
282 314
 		        		{
283
-		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
315
+		        			if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes'] && $tmpa['seconds'] != $tmpb['seconds']) {
316
+		        			    print '-'.dol_print_date($action->datef, 'hour', 'tzuserrel');
317
+		        			}
318
+		        		} else {
319
+		        		    print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
284 320
 		        		}
285
-		        		else print '-'.dol_print_date($action->datef, 'dayhour', 'tzuserrel');
286 321
 	        		}
287 322
 	        		print '</td>';
288 323
 	        		print '<td align="right">';
@@ -295,8 +330,7 @@  discard block
 block discarded – undo
295 330
 
296 331
 	        		$cursorevent++;
297 332
 	        	}
298
-        	}
299
-        	else
333
+        	} else
300 334
         	{
301 335
         		print '<tr class="oddeven"><td colspan="6" class="opacitymedium">'.$langs->trans("None").'</td></tr>';
302 336
         	}
@@ -332,7 +366,9 @@  discard block
 block discarded – undo
332 366
         // phpcs:enable
333 367
         global $langs,$user,$form,$conf;
334 368
 
335
-        if (! is_object($form)) $form=new Form($this->db);
369
+        if (! is_object($form)) {
370
+            $form=new Form($this->db);
371
+        }
336 372
 
337 373
         require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
338 374
         require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
@@ -343,19 +379,26 @@  discard block
 block discarded – undo
343 379
        	array_unshift($arraylist,'&nbsp;');     // Add empty line at start
344 380
        	//asort($arraylist);
345 381
 
346
-       	if ($selected == 'manual') $selected='AC_OTH';
347
-       	if ($selected == 'auto')   $selected='AC_OTH_AUTO';
382
+       	if ($selected == 'manual') {
383
+       	    $selected='AC_OTH';
384
+       	}
385
+       	if ($selected == 'auto') {
386
+       	    $selected='AC_OTH_AUTO';
387
+       	}
348 388
 
349
-       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) unset($arraylist['AC_OTH_AUTO']);
389
+       	if (! empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO)) {
390
+       	    unset($arraylist['AC_OTH_AUTO']);
391
+       	}
350 392
 
351 393
        	$out='';
352 394
 
353 395
 		if (! empty($multiselect))
354 396
 		{
355
-	        if (!is_array($selected) && !empty($selected)) $selected = explode(',', $selected);
397
+	        if (!is_array($selected) && !empty($selected)) {
398
+	            $selected = explode(',', $selected);
399
+	        }
356 400
 			$out.=$form->multiselectarray($htmlname, $arraylist, $selected, 0, 0, 'centpercent', 0, 0);
357
-		}
358
-		else
401
+		} else
359 402
 		{
360 403
 			$out.=$form->selectarray($htmlname, $arraylist, $selected, 0, 0, 0, '', 0, 0, 0, '', 'minwidth200', 1);
361 404
 		}
@@ -365,8 +408,11 @@  discard block
 block discarded – undo
365 408
             $out.=info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup").($hideinfohelp == -1 ? ". ".$langs->trans("YouCanSetDefaultValueInModuleSetup") : ''),1);
366 409
         }
367 410
 
368
-        if ($nooutput) return $out;
369
-        else print $out;
411
+        if ($nooutput) {
412
+            return $out;
413
+        } else {
414
+            print $out;
415
+        }
370 416
         return '';
371 417
     }
372 418
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formmailing.class.php 2 patches
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -27,33 +27,33 @@
 block discarded – undo
27 27
  */
28 28
 class FormMailing extends Form
29 29
 {
30
-	/**
31
-	 * @var string[] Error codes (or messages)
32
-	 */
33
-	public $errors = array();
34
-
35
-	/**
36
-	 * Output a select with destinaries status
37
-	 *
38
-	 * @param string   $selectedid     The selected id
39
-	 * @param string   $htmlname       Name of controm
40
-	 * @param integer  $show_empty     Show empty option
41
-	 * @return string HTML select
42
-	 */
30
+    /**
31
+     * @var string[] Error codes (or messages)
32
+     */
33
+    public $errors = array();
34
+
35
+    /**
36
+     * Output a select with destinaries status
37
+     *
38
+     * @param string   $selectedid     The selected id
39
+     * @param string   $htmlname       Name of controm
40
+     * @param integer  $show_empty     Show empty option
41
+     * @return string HTML select
42
+     */
43 43
     public function selectDestinariesStatus($selectedid='', $htmlname='dest_status', $show_empty=0)
44 44
     {
45 45
 
46
-		global $langs;
47
-		$langs->load("mails");
46
+        global $langs;
47
+        $langs->load("mails");
48 48
 
49
-		require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
50
-		$mailing = new Mailing($this->db);
49
+        require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
50
+        $mailing = new Mailing($this->db);
51 51
 
52
-		$options = array();
52
+        $options = array();
53 53
 
54
-		if ($show_empty) {
55
-			$options[-2] = '';   // Note -1 is used for error
56
-		}
54
+        if ($show_empty) {
55
+            $options[-2] = '';   // Note -1 is used for error
56
+        }
57 57
 
58 58
         $options = $options + $mailing->statut_dest;
59 59
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  *  \ingroup    core
21 21
  *	\brief      File of predefined functions for HTML forms for mailing module
22 22
  */
23
-require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
23
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
24 24
 
25 25
 /**
26 26
  *  Class to offer components to list and upload files
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * @param integer  $show_empty     Show empty option
41 41
 	 * @return string HTML select
42 42
 	 */
43
-    public function selectDestinariesStatus($selectedid='', $htmlname='dest_status', $show_empty=0)
43
+    public function selectDestinariesStatus($selectedid = '', $htmlname = 'dest_status', $show_empty = 0)
44 44
     {
45 45
 
46 46
 		global $langs;
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 		$options = array();
53 53
 
54 54
 		if ($show_empty) {
55
-			$options[-2] = '';   // Note -1 is used for error
55
+			$options[-2] = ''; // Note -1 is used for error
56 56
 		}
57 57
 
58 58
         $options = $options + $mailing->statut_dest;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/doleditor.class.php 3 patches
Braces   +26 added lines, -9 removed lines patch added patch discarded remove patch
@@ -70,8 +70,12 @@  discard block
 block discarded – undo
70 70
 
71 71
     	dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname);
72 72
 
73
-    	if (! $rows) $rows=round($height/20);
74
-    	if (! $cols) $cols=($width?round($width/6):80);
73
+    	if (! $rows) {
74
+    	    $rows=round($height/20);
75
+    	}
76
+    	if (! $cols) {
77
+    	    $cols=($width?round($width/6):80);
78
+    	}
75 79
 		$shorttoolbarname=preg_replace('/_encoded$/','',$toolbarname);
76 80
 
77 81
         // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
@@ -81,8 +85,12 @@  discard block
 block discarded – undo
81 85
         $this->readonly=$readonly;
82 86
 
83 87
         // Check if extended editor is ok. If not we force textarea
84
-        if ((empty($conf->fckeditor->enabled) && $okforextendededitor != 'ace') || empty($okforextendededitor)) $this->tool = 'textarea';
85
-		if ($okforextendededitor === 'ace') $this->tool='ace';
88
+        if ((empty($conf->fckeditor->enabled) && $okforextendededitor != 'ace') || empty($okforextendededitor)) {
89
+            $this->tool = 'textarea';
90
+        }
91
+		if ($okforextendededitor === 'ace') {
92
+		    $this->tool='ace';
93
+		}
86 94
         //if ($conf->dol_use_jmobile) $this->tool = 'textarea';       // ckeditor and ace seems ok with mobile
87 95
 
88 96
         // Define content and some properties
@@ -100,7 +108,9 @@  discard block
 block discarded – undo
100 108
         	$this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ;
101 109
         	$this->editor->Value	= $content;
102 110
         	$this->editor->Height   = $height;
103
-        	if (! empty($width)) $this->editor->Width = $width;
111
+        	if (! empty($width)) {
112
+        	    $this->editor->Width = $width;
113
+        	}
104 114
         	$this->editor->ToolbarSet = $shorttoolbarname;         // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js
105 115
         	$this->editor->Config['AutoDetectLanguage'] = 'true';  // Language of user (browser)
106 116
         	$this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
@@ -163,9 +173,11 @@  discard block
 block discarded – undo
163 173
     	$found=0;
164 174
 		$out='';
165 175
 
166
-        if ($this->tool == 'fckeditor') // not used anymore
176
+        if ($this->tool == 'fckeditor') {
177
+            // not used anymore
167 178
         {
168 179
 			$found=1;
180
+        }
169 181
             $this->editor->Create();
170 182
         }
171 183
         if (in_array($this->tool,array('textarea','ckeditor')))
@@ -179,7 +191,9 @@  discard block
 block discarded – undo
179 191
 
180 192
             if ($this->tool == 'ckeditor' && ! empty($conf->use_javascript_ajax))
181 193
             {
182
-            	if (! defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR','1');
194
+            	if (! defined('REQUIRE_CKEDITOR')) {
195
+            	    define('REQUIRE_CKEDITOR','1');
196
+            	}
183 197
 
184 198
             	if (! empty($conf->global->FCKEDITOR_SKIN)) {
185 199
 					$skin = $conf->global->FCKEDITOR_SKIN;
@@ -343,7 +357,10 @@  discard block
 block discarded – undo
343 357
             $out.= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.';
344 358
         }
345 359
 
346
-        if ($noprint) return $out;
347
-        else print $out;
360
+        if ($noprint) {
361
+            return $out;
362
+        } else {
363
+            print $out;
364
+        }
348 365
     }
349 366
 }
Please login to merge, or discard this patch.
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -30,19 +30,19 @@  discard block
 block discarded – undo
30 30
 {
31 31
     var $tool;      // Store the selected tool
32 32
 
33
-	// If using fckeditor
34
-	var $editor;
33
+    // If using fckeditor
34
+    var $editor;
35 35
 
36
-	// If not using fckeditor
37
-	var $content;
38
-	var $htmlname;
39
-	var $toolbarname;
40
-	var $toolbarstartexpanded;
41
-	var $rows;
42
-	var $cols;
43
-	var $height;
44
-	var $width;
45
-	var $readonly;
36
+    // If not using fckeditor
37
+    var $content;
38
+    var $htmlname;
39
+    var $toolbarname;
40
+    var $toolbarstartexpanded;
41
+    var $rows;
42
+    var $cols;
43
+    var $height;
44
+    var $width;
45
+    var $readonly;
46 46
 
47 47
 
48 48
     /**
@@ -57,22 +57,22 @@  discard block
 block discarded – undo
57 57
      *                       		             			'In' each window has its own toolbar
58 58
      *                              		      			'Out:name' share toolbar into the div called 'name'
59 59
      *      @param  boolean	$toolbarstartexpanded  			Bar is visible or not at start
60
-	 *		@param	int		$uselocalbrowser				Enabled to add links to local object with local browser. If false, only external images can be added in content.
61
-	 *      @param  boolean|string	$okforextendededitor    True=Allow usage of extended editor tool if qualified (like ckeditor). If 'textarea', force use of simple textarea. If 'ace', force use of Ace.
62
-	 *      												Warning: If you use 'ace', don't forget to also include ace.js in page header. Also, the button "save" must have class="buttonforacesave".
60
+     *		@param	int		$uselocalbrowser				Enabled to add links to local object with local browser. If false, only external images can be added in content.
61
+     *      @param  boolean|string	$okforextendededitor    True=Allow usage of extended editor tool if qualified (like ckeditor). If 'textarea', force use of simple textarea. If 'ace', force use of Ace.
62
+     *      												Warning: If you use 'ace', don't forget to also include ace.js in page header. Also, the button "save" must have class="buttonforacesave".
63 63
      *      @param  int		$rows                   		Size of rows for textarea tool
64
-	 *      @param  string	$cols                   		Size of cols for textarea tool (textarea number of cols '70' or percent 'x%')
65
-	 *      @param	int		$readonly						0=Read/Edit, 1=Read only
66
-	 */
64
+     *      @param  string	$cols                   		Size of cols for textarea tool (textarea number of cols '70' or percent 'x%')
65
+     *      @param	int		$readonly						0=Read/Edit, 1=Read only
66
+     */
67 67
     function __construct($htmlname, $content, $width='', $height=200, $toolbarname='Basic', $toolbarlocation='In', $toolbarstartexpanded=false, $uselocalbrowser=true, $okforextendededitor=true, $rows=0, $cols=0, $readonly=0)
68 68
     {
69
-    	global $conf,$langs;
69
+        global $conf,$langs;
70 70
 
71
-    	dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname);
71
+        dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname);
72 72
 
73
-    	if (! $rows) $rows=round($height/20);
74
-    	if (! $cols) $cols=($width?round($width/6):80);
75
-		$shorttoolbarname=preg_replace('/_encoded$/','',$toolbarname);
73
+        if (! $rows) $rows=round($height/20);
74
+        if (! $cols) $cols=($width?round($width/6):80);
75
+        $shorttoolbarname=preg_replace('/_encoded$/','',$toolbarname);
76 76
 
77 77
         // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
78 78
         $defaulteditor='ckeditor';
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
         // Check if extended editor is ok. If not we force textarea
84 84
         if ((empty($conf->fckeditor->enabled) && $okforextendededitor != 'ace') || empty($okforextendededitor)) $this->tool = 'textarea';
85
-		if ($okforextendededitor === 'ace') $this->tool='ace';
85
+        if ($okforextendededitor === 'ace') $this->tool='ace';
86 86
         //if ($conf->dol_use_jmobile) $this->tool = 'textarea';       // ckeditor and ace seems ok with mobile
87 87
 
88 88
         // Define content and some properties
@@ -91,50 +91,50 @@  discard block
 block discarded – undo
91 91
             $content=dol_htmlentitiesbr($content);  // If content is not HTML, we convert to HTML.
92 92
         }
93 93
         if ($this->tool == 'fckeditor')
94
-    	{
95
-        	require_once DOL_DOCUMENT_ROOT.'/includes/fckeditor/fckeditor.php';
96
-
97
-    		$content=dol_htmlentitiesbr($content);	// If content is not HTML, we convert to HTML.
98
-
99
-        	$this->editor = new FCKeditor($htmlname);
100
-        	$this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ;
101
-        	$this->editor->Value	= $content;
102
-        	$this->editor->Height   = $height;
103
-        	if (! empty($width)) $this->editor->Width = $width;
104
-        	$this->editor->ToolbarSet = $shorttoolbarname;         // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js
105
-        	$this->editor->Config['AutoDetectLanguage'] = 'true';  // Language of user (browser)
106
-        	$this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
107
-        	$this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded;
108
-
109
-    		// Rem: Le forcage de ces 2 parametres ne semble pas fonctionner.
110
-    		// Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart.
111
-    		// Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ?
112
-        	$modulepart='fckeditor';
113
-    		$this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file=';
114
-    		$this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/' ;
115
-
116
-        	$this->editor->Config['LinkBrowser']=($uselocalbrowser?'true':'false');
117
-        	$this->editor->Config['ImageBrowser']=($uselocalbrowser?'true':'false');
118
-
119
-        	if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js'))
120
-        	{
121
-        		$this->editor->Config['CustomConfigurationsPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js';
122
-        		$this->editor->Config['SkinPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/';
123
-    		}
124
-    	}
125
-
126
-    	// Define some properties
94
+        {
95
+            require_once DOL_DOCUMENT_ROOT.'/includes/fckeditor/fckeditor.php';
96
+
97
+            $content=dol_htmlentitiesbr($content);	// If content is not HTML, we convert to HTML.
98
+
99
+            $this->editor = new FCKeditor($htmlname);
100
+            $this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ;
101
+            $this->editor->Value	= $content;
102
+            $this->editor->Height   = $height;
103
+            if (! empty($width)) $this->editor->Width = $width;
104
+            $this->editor->ToolbarSet = $shorttoolbarname;         // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js
105
+            $this->editor->Config['AutoDetectLanguage'] = 'true';  // Language of user (browser)
106
+            $this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
107
+            $this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded;
108
+
109
+            // Rem: Le forcage de ces 2 parametres ne semble pas fonctionner.
110
+            // Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart.
111
+            // Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ?
112
+            $modulepart='fckeditor';
113
+            $this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file=';
114
+            $this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/' ;
115
+
116
+            $this->editor->Config['LinkBrowser']=($uselocalbrowser?'true':'false');
117
+            $this->editor->Config['ImageBrowser']=($uselocalbrowser?'true':'false');
118
+
119
+            if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js'))
120
+            {
121
+                $this->editor->Config['CustomConfigurationsPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js';
122
+                $this->editor->Config['SkinPath'] = DOL_URL_ROOT.'/theme/'.$conf->theme.'/fckeditor/';
123
+            }
124
+        }
125
+
126
+        // Define some properties
127 127
         if (in_array($this->tool,array('textarea','ckeditor','ace')))
128 128
         {
129
-    	    $this->content				= $content;
130
-    	    $this->htmlname 			= $htmlname;
131
-    	    $this->toolbarname			= $shorttoolbarname;
132
-    	    $this->toolbarstartexpanded = $toolbarstartexpanded;
129
+            $this->content				= $content;
130
+            $this->htmlname 			= $htmlname;
131
+            $this->toolbarname			= $shorttoolbarname;
132
+            $this->toolbarstartexpanded = $toolbarstartexpanded;
133 133
             $this->rows					= max(ROWS_3,$rows);
134 134
             $this->cols					= (preg_match('/%/',$cols)?$cols:max(40,$cols));	// If $cols is a percent, we keep it, otherwise, we take max
135 135
             $this->height				= $height;
136 136
             $this->width				= $width;
137
-    	}
137
+        }
138 138
     }
139 139
 
140 140
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -152,20 +152,20 @@  discard block
 block discarded – undo
152 152
     function Create($noprint=0, $morejs='', $disallowAnyContent=true, $titlecontent='', $option='')
153 153
     {
154 154
         // phpcs:enable
155
-    	global $conf,$langs;
155
+        global $conf,$langs;
156 156
 
157
-    	$fullpage=false;
158
-    	if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT))
159
-    	{
160
-    	   $disallowAnyContent=empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT);      // Only predefined list of html tags are allowed or all
161
-    	}
157
+        $fullpage=false;
158
+        if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT))
159
+        {
160
+            $disallowAnyContent=empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT);      // Only predefined list of html tags are allowed or all
161
+        }
162 162
 
163
-    	$found=0;
164
-		$out='';
163
+        $found=0;
164
+        $out='';
165 165
 
166 166
         if ($this->tool == 'fckeditor') // not used anymore
167 167
         {
168
-			$found=1;
168
+            $found=1;
169 169
             $this->editor->Create();
170 170
         }
171 171
         if (in_array($this->tool,array('textarea','ckeditor')))
@@ -179,12 +179,12 @@  discard block
 block discarded – undo
179 179
 
180 180
             if ($this->tool == 'ckeditor' && ! empty($conf->use_javascript_ajax))
181 181
             {
182
-            	if (! defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR','1');
182
+                if (! defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR','1');
183 183
 
184
-            	if (! empty($conf->global->FCKEDITOR_SKIN)) {
185
-					$skin = $conf->global->FCKEDITOR_SKIN;
186
-				} else {
187
-					// $skin = 'moono-lisa'; // default with ckeditor 4.6 : moono-lisa
184
+                if (! empty($conf->global->FCKEDITOR_SKIN)) {
185
+                    $skin = $conf->global->FCKEDITOR_SKIN;
186
+                } else {
187
+                    // $skin = 'moono-lisa'; // default with ckeditor 4.6 : moono-lisa
188 188
 
189 189
                     /**
190 190
                      * Alixar:
@@ -195,10 +195,10 @@  discard block
 block discarded – undo
195 195
                     $skin = CKEDITOR_SKIN;  // In AlixarDispatcher defineConstants()
196 196
                 }
197 197
 
198
-            	$htmlencode_force=preg_match('/_encoded$/',$this->toolbarname)?'true':'false';
198
+                $htmlencode_force=preg_match('/_encoded$/',$this->toolbarname)?'true':'false';
199 199
 
200
-            	$out.= '<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.' toolbarname='.$this->toolbarname.' -->'."\n";
201
-            	$out.= '<script type="text/javascript">
200
+                $out.= '<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.' toolbarname='.$this->toolbarname.' -->'."\n";
201
+                $out.= '<script type="text/javascript">
202 202
             			$(document).ready(function () {
203 203
                             /* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
204 204
                             /* should be editor=CKEDITOR.replace but what if serveral editors ? */
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
                                                         });
234 234
                                                 }
235 235
                                             }';
236
-            	if ($this->uselocalbrowser)
237
-            	{
236
+                if ($this->uselocalbrowser)
237
+                {
238 238
                     $out.= ','."\n";
239 239
                     // To use filemanager with old fckeditor (GPL)
240 240
                     $out.= '    filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
                     //$out.= '    filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\',';
244 244
                     $out.= "\n";
245 245
                     // To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes
246
-					/* $out.= '    filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html\',
246
+                    /* $out.= '    filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html\',
247 247
                                filebrowserImageBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Images\',
248 248
                                filebrowserFlashBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Flash\',
249 249
                                filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files\',
@@ -254,10 +254,10 @@  discard block
 block discarded – undo
254 254
                                filebrowserWindowHeight : \'500\',
255 255
                                filebrowserImageWindowWidth : \'900\',
256 256
                                filebrowserImageWindowHeight : \'500\'';
257
-            	}
258
-            	$out.= '	})'.$morejs;
259
-            	$out.= '});'."\n";
260
-            	$out.= '</script>'."\n";
257
+                }
258
+                $out.= '	})'.$morejs;
259
+                $out.= '});'."\n";
260
+                $out.= '</script>'."\n";
261 261
             }
262 262
         }
263 263
 
@@ -265,19 +265,19 @@  discard block
 block discarded – undo
265 265
         // Warning: ace.js and ext-statusbar.js must be loaded by the parent page.
266 266
         if (preg_match('/^ace/', $this->tool))
267 267
         {
268
-        	$found=1;
269
-			$format=$option;
268
+            $found=1;
269
+            $format=$option;
270 270
 
271 271
             $out.= "\n".'<!-- Output Ace editor -->'."\n";
272 272
 
273
-			if ($titlecontent)
274
-			{
275
-	            $out.= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">'.$titlecontent;
276
-	            $out.= ' &nbsp; - &nbsp; <a id="morelines" href="#" class="right morelines'.$this->htmlname.'">'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'</a> &nbsp; &nbsp; ';
277
-	            $out.= '</div>';
278
-	            $out.= '<script type="text/javascript" language="javascript">'."\n";
279
-	            $out.= 'jQuery(document).ready(function() {'."\n";
280
-	            $out.= '	var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
273
+            if ($titlecontent)
274
+            {
275
+                $out.= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">'.$titlecontent;
276
+                $out.= ' &nbsp; - &nbsp; <a id="morelines" href="#" class="right morelines'.$this->htmlname.'">'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'</a> &nbsp; &nbsp; ';
277
+                $out.= '</div>';
278
+                $out.= '<script type="text/javascript" language="javascript">'."\n";
279
+                $out.= 'jQuery(document).ready(function() {'."\n";
280
+                $out.= '	var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
281 281
 	    	    		   	var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar;									// Init status bar. Need lib ext-statusbar
282 282
 	        			   	var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.'"));	// Init status bar. Need lib ext-statusbar
283 283
 	            			var oldNbOfLines = 0
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 									}
300 300
 							});
301 301
 						})';
302
-	            $out.= '</script>'."\n";
303
-			}
302
+                $out.= '</script>'."\n";
303
+            }
304 304
 
305 305
             $out.= '<pre id="'.$this->htmlname.'aceeditorid" style="'.($this->width?'width: '.$this->width.'px; ':'');
306 306
             $out.= ($this->height?' height: '.$this->height.'px; ':'');
307 307
             //$out.=" min-height: 100px;";
308 308
             $out.= '">';
309
-        	$out.= htmlspecialchars($this->content);
310
-        	$out.= '</pre>';
311
-        	$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">';
312
-        	$out.= htmlspecialchars($this->content);
313
-        	$out.= '</textarea>';
309
+            $out.= htmlspecialchars($this->content);
310
+            $out.= '</pre>';
311
+            $out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">';
312
+            $out.= htmlspecialchars($this->content);
313
+            $out.= '</textarea>';
314 314
 
315
-        	$out.= '<script type="text/javascript" language="javascript">'."\n";
316
-        	$out.= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
315
+            $out.= '<script type="text/javascript" language="javascript">'."\n";
316
+            $out.= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
317 317
 
318 318
 				    aceEditor.session.setMode("ace/mode/'.$format.'");
319 319
 					aceEditor.setOptions({
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 					//aceEditor.getSession().setMode("ace/mode/javascript_expression");
334 334
 					'."\n";
335 335
 
336
-        	$out.= 'jQuery(document).ready(function() {
336
+            $out.= 'jQuery(document).ready(function() {
337 337
 						jQuery(".buttonforacesave").click(function() {
338 338
         					console.log("We click on savefile button for component '.$this->htmlname.'");
339 339
         					var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid")
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 							else return false;*/
344 344
 	        			});
345 345
 					})';
346
-        	$out.= '</script>'."\n";
346
+            $out.= '</script>'."\n";
347 347
         }
348 348
 
349 349
         if (empty($found))
Please login to merge, or discard this patch.
Spacing   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
  */
29 29
 class DolEditor
30 30
 {
31
-    var $tool;      // Store the selected tool
31
+    var $tool; // Store the selected tool
32 32
 
33 33
 	// If using fckeditor
34 34
 	var $editor;
@@ -64,57 +64,57 @@  discard block
 block discarded – undo
64 64
 	 *      @param  string	$cols                   		Size of cols for textarea tool (textarea number of cols '70' or percent 'x%')
65 65
 	 *      @param	int		$readonly						0=Read/Edit, 1=Read only
66 66
 	 */
67
-    function __construct($htmlname, $content, $width='', $height=200, $toolbarname='Basic', $toolbarlocation='In', $toolbarstartexpanded=false, $uselocalbrowser=true, $okforextendededitor=true, $rows=0, $cols=0, $readonly=0)
67
+    function __construct($htmlname, $content, $width = '', $height = 200, $toolbarname = 'Basic', $toolbarlocation = 'In', $toolbarstartexpanded = false, $uselocalbrowser = true, $okforextendededitor = true, $rows = 0, $cols = 0, $readonly = 0)
68 68
     {
69
-    	global $conf,$langs;
69
+    	global $conf, $langs;
70 70
 
71 71
     	dol_syslog(get_class($this)."::DolEditor htmlname=".$htmlname." width=".$width." height=".$height." toolbarname=".$toolbarname);
72 72
 
73
-    	if (! $rows) $rows=round($height/20);
74
-    	if (! $cols) $cols=($width?round($width/6):80);
75
-		$shorttoolbarname=preg_replace('/_encoded$/','',$toolbarname);
73
+    	if (!$rows) $rows = round($height / 20);
74
+    	if (!$cols) $cols = ($width ?round($width / 6) : 80);
75
+		$shorttoolbarname = preg_replace('/_encoded$/', '', $toolbarname);
76 76
 
77 77
         // Name of extended editor to use (FCKEDITOR_EDITORNAME can be 'ckeditor' or 'fckeditor')
78
-        $defaulteditor='ckeditor';
79
-        $this->tool=empty($conf->global->FCKEDITOR_EDITORNAME)?$defaulteditor:$conf->global->FCKEDITOR_EDITORNAME;
80
-        $this->uselocalbrowser=$uselocalbrowser;
81
-        $this->readonly=$readonly;
78
+        $defaulteditor = 'ckeditor';
79
+        $this->tool = empty($conf->global->FCKEDITOR_EDITORNAME) ? $defaulteditor : $conf->global->FCKEDITOR_EDITORNAME;
80
+        $this->uselocalbrowser = $uselocalbrowser;
81
+        $this->readonly = $readonly;
82 82
 
83 83
         // Check if extended editor is ok. If not we force textarea
84 84
         if ((empty($conf->fckeditor->enabled) && $okforextendededitor != 'ace') || empty($okforextendededitor)) $this->tool = 'textarea';
85
-		if ($okforextendededitor === 'ace') $this->tool='ace';
85
+		if ($okforextendededitor === 'ace') $this->tool = 'ace';
86 86
         //if ($conf->dol_use_jmobile) $this->tool = 'textarea';       // ckeditor and ace seems ok with mobile
87 87
 
88 88
         // Define content and some properties
89 89
         if ($this->tool == 'ckeditor')
90 90
         {
91
-            $content=dol_htmlentitiesbr($content);  // If content is not HTML, we convert to HTML.
91
+            $content = dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
92 92
         }
93 93
         if ($this->tool == 'fckeditor')
94 94
     	{
95 95
         	require_once DOL_DOCUMENT_ROOT.'/includes/fckeditor/fckeditor.php';
96 96
 
97
-    		$content=dol_htmlentitiesbr($content);	// If content is not HTML, we convert to HTML.
97
+    		$content = dol_htmlentitiesbr($content); // If content is not HTML, we convert to HTML.
98 98
 
99 99
         	$this->editor = new FCKeditor($htmlname);
100
-        	$this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/' ;
101
-        	$this->editor->Value	= $content;
100
+        	$this->editor->BasePath = DOL_URL_ROOT.'/includes/fckeditor/';
101
+        	$this->editor->Value = $content;
102 102
         	$this->editor->Height   = $height;
103
-        	if (! empty($width)) $this->editor->Width = $width;
104
-        	$this->editor->ToolbarSet = $shorttoolbarname;         // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js
105
-        	$this->editor->Config['AutoDetectLanguage'] = 'true';  // Language of user (browser)
103
+        	if (!empty($width)) $this->editor->Width = $width;
104
+        	$this->editor->ToolbarSet = $shorttoolbarname; // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js
105
+        	$this->editor->Config['AutoDetectLanguage'] = 'true'; // Language of user (browser)
106 106
         	$this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In';
107 107
         	$this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded;
108 108
 
109 109
     		// Rem: Le forcage de ces 2 parametres ne semble pas fonctionner.
110 110
     		// Dolibarr utilise toujours liens avec modulepart='fckeditor' quelque soit modulepart.
111 111
     		// Ou se trouve donc cette valeur /viewimage.php?modulepart=fckeditor&file=' ?
112
-        	$modulepart='fckeditor';
112
+        	$modulepart = 'fckeditor';
113 113
     		$this->editor->Config['UserFilesPath'] = '/viewimage.php?modulepart='.$modulepart.'&entity='.$conf->entity.'&file=';
114
-    		$this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/' ;
114
+    		$this->editor->Config['UserFilesAbsolutePath'] = DOL_DATA_ROOT.'/'.$modulepart.'/';
115 115
 
116
-        	$this->editor->Config['LinkBrowser']=($uselocalbrowser?'true':'false');
117
-        	$this->editor->Config['ImageBrowser']=($uselocalbrowser?'true':'false');
116
+        	$this->editor->Config['LinkBrowser'] = ($uselocalbrowser ? 'true' : 'false');
117
+        	$this->editor->Config['ImageBrowser'] = ($uselocalbrowser ? 'true' : 'false');
118 118
 
119 119
         	if (file_exists(DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/fckeditor/fckconfig.js'))
120 120
         	{
@@ -124,15 +124,15 @@  discard block
 block discarded – undo
124 124
     	}
125 125
 
126 126
     	// Define some properties
127
-        if (in_array($this->tool,array('textarea','ckeditor','ace')))
127
+        if (in_array($this->tool, array('textarea', 'ckeditor', 'ace')))
128 128
         {
129
-    	    $this->content				= $content;
129
+    	    $this->content = $content;
130 130
     	    $this->htmlname 			= $htmlname;
131
-    	    $this->toolbarname			= $shorttoolbarname;
131
+    	    $this->toolbarname = $shorttoolbarname;
132 132
     	    $this->toolbarstartexpanded = $toolbarstartexpanded;
133
-            $this->rows					= max(ROWS_3,$rows);
134
-            $this->cols					= (preg_match('/%/',$cols)?$cols:max(40,$cols));	// If $cols is a percent, we keep it, otherwise, we take max
135
-            $this->height				= $height;
133
+            $this->rows					= max(ROWS_3, $rows);
134
+            $this->cols					= (preg_match('/%/', $cols) ? $cols : max(40, $cols)); // If $cols is a percent, we keep it, otherwise, we take max
135
+            $this->height = $height;
136 136
             $this->width				= $width;
137 137
     	}
138 138
     }
@@ -149,39 +149,39 @@  discard block
 block discarded – undo
149 149
      *  @param	string	$option				 For ACE editor, set the source language ('html', 'php', 'javascript', ...)
150 150
      *  @return	void|string
151 151
      */
152
-    function Create($noprint=0, $morejs='', $disallowAnyContent=true, $titlecontent='', $option='')
152
+    function Create($noprint = 0, $morejs = '', $disallowAnyContent = true, $titlecontent = '', $option = '')
153 153
     {
154 154
         // phpcs:enable
155
-    	global $conf,$langs;
155
+    	global $conf, $langs;
156 156
 
157
-    	$fullpage=false;
157
+    	$fullpage = false;
158 158
     	if (isset($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT))
159 159
     	{
160
-    	   $disallowAnyContent=empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT);      // Only predefined list of html tags are allowed or all
160
+    	   $disallowAnyContent = empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT); // Only predefined list of html tags are allowed or all
161 161
     	}
162 162
 
163
-    	$found=0;
164
-		$out='';
163
+    	$found = 0;
164
+		$out = '';
165 165
 
166 166
         if ($this->tool == 'fckeditor') // not used anymore
167 167
         {
168
-			$found=1;
168
+			$found = 1;
169 169
             $this->editor->Create();
170 170
         }
171
-        if (in_array($this->tool,array('textarea','ckeditor')))
171
+        if (in_array($this->tool, array('textarea', 'ckeditor')))
172 172
         {
173
-            $found=1;
173
+            $found = 1;
174 174
             //$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" '.($this->readonly?' disabled':'').' rows="'.$this->rows.'"'.(preg_match('/%/',$this->cols)?' style="margin-top: 5px; width: '.$this->cols.'"':' cols="'.$this->cols.'"').' class="flat">';
175 175
             // TODO We do not put the disabled tag because on a read form, it change style with grey.
176
-            $out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" rows="'.$this->rows.'"'.(preg_match('/%/',$this->cols)?' style="margin-top: 5px; width: '.$this->cols.'"':' cols="'.$this->cols.'"').' class="flat">';
177
-            $out.= $this->content;
178
-            $out.= '</textarea>';
176
+            $out .= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" rows="'.$this->rows.'"'.(preg_match('/%/', $this->cols) ? ' style="margin-top: 5px; width: '.$this->cols.'"' : ' cols="'.$this->cols.'"').' class="flat">';
177
+            $out .= $this->content;
178
+            $out .= '</textarea>';
179 179
 
180
-            if ($this->tool == 'ckeditor' && ! empty($conf->use_javascript_ajax))
180
+            if ($this->tool == 'ckeditor' && !empty($conf->use_javascript_ajax))
181 181
             {
182
-            	if (! defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR','1');
182
+            	if (!defined('REQUIRE_CKEDITOR')) define('REQUIRE_CKEDITOR', '1');
183 183
 
184
-            	if (! empty($conf->global->FCKEDITOR_SKIN)) {
184
+            	if (!empty($conf->global->FCKEDITOR_SKIN)) {
185 185
 					$skin = $conf->global->FCKEDITOR_SKIN;
186 186
 				} else {
187 187
 					// $skin = 'moono-lisa'; // default with ckeditor 4.6 : moono-lisa
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
                      * When updating ckeditor, the moono-lisa skin disappears 
193 193
                      * and includes kama and moono.
194 194
                      */
195
-                    $skin = CKEDITOR_SKIN;  // In AlixarDispatcher defineConstants()
195
+                    $skin = CKEDITOR_SKIN; // In AlixarDispatcher defineConstants()
196 196
                 }
197 197
 
198
-            	$htmlencode_force=preg_match('/_encoded$/',$this->toolbarname)?'true':'false';
198
+            	$htmlencode_force = preg_match('/_encoded$/', $this->toolbarname) ? 'true' : 'false';
199 199
 
200
-            	$out.= '<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.' toolbarname='.$this->toolbarname.' -->'."\n";
201
-            	$out.= '<script type="text/javascript">
200
+            	$out .= '<!-- Output ckeditor $disallowAnyContent='.$disallowAnyContent.' toolbarname='.$this->toolbarname.' -->'."\n";
201
+            	$out .= '<script type="text/javascript">
202 202
             			$(document).ready(function () {
203 203
                             /* if (CKEDITOR.loadFullCore) CKEDITOR.loadFullCore(); */
204 204
                             /* should be editor=CKEDITOR.replace but what if serveral editors ? */
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
             					{
207 207
             						/* property:xxx is same than CKEDITOR.config.property = xxx */
208 208
             						customConfig : ckeditorConfig,
209
-            						readOnly : '.($this->readonly?'true':'false').',
209
+            						readOnly : '.($this->readonly ? 'true' : 'false').',
210 210
                             		htmlEncodeOutput :'.$htmlencode_force.',
211
-            						allowedContent :'.($disallowAnyContent?'false':'true').',
211
+            						allowedContent :'.($disallowAnyContent ? 'false' : 'true').',
212 212
             						extraAllowedContent : \'\',
213
-            						fullPage : '.($fullpage?'true':'false').',
213
+            						fullPage : '.($fullpage ? 'true' : 'false').',
214 214
                             		toolbar: \''.$this->toolbarname.'\',
215 215
             						toolbarStartupExpanded: '.($this->toolbarstartexpanded ? 'true' : 'false').',
216 216
             						width: '.($this->width ? '\''.$this->width.'\'' : '\'\'').',
@@ -235,13 +235,13 @@  discard block
 block discarded – undo
235 235
                                             }';
236 236
             	if ($this->uselocalbrowser)
237 237
             	{
238
-                    $out.= ','."\n";
238
+                    $out .= ','."\n";
239 239
                     // To use filemanager with old fckeditor (GPL)
240
-                    $out.= '    filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
241
-                    $out.= '    filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
240
+                    $out .= '    filebrowserBrowseUrl : ckeditorFilebrowserBrowseUrl,';
241
+                    $out .= '    filebrowserImageBrowseUrl : ckeditorFilebrowserImageBrowseUrl,';
242 242
                     //$out.= '    filebrowserUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=File\',';
243 243
                     //$out.= '    filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/fckeditor/editor/filemanagerdol/connectors/php/upload.php?Type=Image\',';
244
-                    $out.= "\n";
244
+                    $out .= "\n";
245 245
                     // To use filemanager with ckfinder (Non free) and ckfinder directory is inside htdocs/includes
246 246
 					/* $out.= '    filebrowserBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html\',
247 247
                                filebrowserImageBrowseUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/ckfinder.html?Type=Images\',
@@ -250,14 +250,14 @@  discard block
 block discarded – undo
250 250
                                filebrowserImageUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images\',
251 251
                                filebrowserFlashUploadUrl : \''.DOL_URL_ROOT.'/includes/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash\','."\n";
252 252
 					*/
253
-                    $out.= '    filebrowserWindowWidth : \'900\',
253
+                    $out .= '    filebrowserWindowWidth : \'900\',
254 254
                                filebrowserWindowHeight : \'500\',
255 255
                                filebrowserImageWindowWidth : \'900\',
256 256
                                filebrowserImageWindowHeight : \'500\'';
257 257
             	}
258
-            	$out.= '	})'.$morejs;
259
-            	$out.= '});'."\n";
260
-            	$out.= '</script>'."\n";
258
+            	$out .= '	})'.$morejs;
259
+            	$out .= '});'."\n";
260
+            	$out .= '</script>'."\n";
261 261
             }
262 262
         }
263 263
 
@@ -265,19 +265,19 @@  discard block
 block discarded – undo
265 265
         // Warning: ace.js and ext-statusbar.js must be loaded by the parent page.
266 266
         if (preg_match('/^ace/', $this->tool))
267 267
         {
268
-        	$found=1;
269
-			$format=$option;
268
+        	$found = 1;
269
+			$format = $option;
270 270
 
271
-            $out.= "\n".'<!-- Output Ace editor -->'."\n";
271
+            $out .= "\n".'<!-- Output Ace editor -->'."\n";
272 272
 
273 273
 			if ($titlecontent)
274 274
 			{
275
-	            $out.= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">'.$titlecontent;
276
-	            $out.= ' &nbsp; - &nbsp; <a id="morelines" href="#" class="right morelines'.$this->htmlname.'">'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'</a> &nbsp; &nbsp; ';
277
-	            $out.= '</div>';
278
-	            $out.= '<script type="text/javascript" language="javascript">'."\n";
279
-	            $out.= 'jQuery(document).ready(function() {'."\n";
280
-	            $out.= '	var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
275
+	            $out .= '<div class="aceeditorstatusbar" id="statusBar'.$this->htmlname.'">'.$titlecontent;
276
+	            $out .= ' &nbsp; - &nbsp; <a id="morelines" href="#" class="right morelines'.$this->htmlname.'">'.dol_escape_htmltag($langs->trans("ShowMoreLines")).'</a> &nbsp; &nbsp; ';
277
+	            $out .= '</div>';
278
+	            $out .= '<script type="text/javascript" language="javascript">'."\n";
279
+	            $out .= 'jQuery(document).ready(function() {'."\n";
280
+	            $out .= '	var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
281 281
 	    	    		   	var StatusBar = window.ace.require("ace/ext/statusbar").StatusBar;									// Init status bar. Need lib ext-statusbar
282 282
 	        			   	var statusBar = new StatusBar(aceEditor, document.getElementById("statusBar'.$this->htmlname.'"));	// Init status bar. Need lib ext-statusbar
283 283
 	            			var oldNbOfLines = 0
@@ -299,21 +299,21 @@  discard block
 block discarded – undo
299 299
 									}
300 300
 							});
301 301
 						})';
302
-	            $out.= '</script>'."\n";
302
+	            $out .= '</script>'."\n";
303 303
 			}
304 304
 
305
-            $out.= '<pre id="'.$this->htmlname.'aceeditorid" style="'.($this->width?'width: '.$this->width.'px; ':'');
306
-            $out.= ($this->height?' height: '.$this->height.'px; ':'');
305
+            $out .= '<pre id="'.$this->htmlname.'aceeditorid" style="'.($this->width ? 'width: '.$this->width.'px; ' : '');
306
+            $out .= ($this->height ? ' height: '.$this->height.'px; ' : '');
307 307
             //$out.=" min-height: 100px;";
308
-            $out.= '">';
309
-        	$out.= htmlspecialchars($this->content);
310
-        	$out.= '</pre>';
311
-        	$out.= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">';
312
-        	$out.= htmlspecialchars($this->content);
313
-        	$out.= '</textarea>';
308
+            $out .= '">';
309
+        	$out .= htmlspecialchars($this->content);
310
+        	$out .= '</pre>';
311
+        	$out .= '<textarea id="'.$this->htmlname.'" name="'.$this->htmlname.'" style="width:0px; height: 0px; display: none;">';
312
+        	$out .= htmlspecialchars($this->content);
313
+        	$out .= '</textarea>';
314 314
 
315
-        	$out.= '<script type="text/javascript" language="javascript">'."\n";
316
-        	$out.= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
315
+        	$out .= '<script type="text/javascript" language="javascript">'."\n";
316
+        	$out .= 'var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid");
317 317
 
318 318
 				    aceEditor.session.setMode("ace/mode/'.$format.'");
319 319
 					aceEditor.setOptions({
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 					   enableLiveAutocompletion: false, // the editor completes the statement while you are typing. Need lib ext-language_tools.js
322 322
 					   showPrintMargin: false, // hides the vertical limiting strip
323 323
 					   minLines: 10,
324
-					   maxLines: '.(empty($this->height)?'34':(round($this->height/10))).',
324
+					   maxLines: '.(empty($this->height) ? '34' : (round($this->height / 10))).',
325 325
 				       fontSize: "110%" // ensures that the editor fits in the environment
326 326
 					});
327 327
 
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 					//aceEditor.getSession().setMode("ace/mode/javascript_expression");
334 334
 					'."\n";
335 335
 
336
-        	$out.= 'jQuery(document).ready(function() {
336
+        	$out .= 'jQuery(document).ready(function() {
337 337
 						jQuery(".buttonforacesave").click(function() {
338 338
         					console.log("We click on savefile button for component '.$this->htmlname.'");
339 339
         					var aceEditor = window.ace.edit("'.$this->htmlname.'aceeditorid")
@@ -343,12 +343,12 @@  discard block
 block discarded – undo
343 343
 							else return false;*/
344 344
 	        			});
345 345
 					})';
346
-        	$out.= '</script>'."\n";
346
+        	$out .= '</script>'."\n";
347 347
         }
348 348
 
349 349
         if (empty($found))
350 350
         {
351
-            $out.= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.';
351
+            $out .= 'Error, unknown value for tool '.$this->tool.' in DolEditor Create function.';
352 352
         }
353 353
 
354 354
         if ($noprint) return $out;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formcompany.class.php 3 patches
Indentation   +700 added lines, -700 removed lines patch added patch discarded remove patch
@@ -31,589 +31,589 @@  discard block
 block discarded – undo
31 31
  */
32 32
 class FormCompany
33 33
 {
34
-	/**
34
+    /**
35 35
      * @var DoliDB Database handler.
36 36
      */
37 37
     public $db;
38 38
 
39
-	/**
40
-	 * @var string Error code (or message)
41
-	 */
42
-	public $error='';
39
+    /**
40
+     * @var string Error code (or message)
41
+     */
42
+    public $error='';
43 43
 
44
-	/**
45
-	 *	Constructor
46
-	 *
47
-	 *	@param	DoliDB	$db		Database handler
48
-	 */
49
-	function __construct($db)
50
-	{
51
-		$this->db = $db;
52
-	}
44
+    /**
45
+     *	Constructor
46
+     *
47
+     *	@param	DoliDB	$db		Database handler
48
+     */
49
+    function __construct($db)
50
+    {
51
+        $this->db = $db;
52
+    }
53 53
 
54 54
 
55 55
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
56
-	/**
57
-	 *    	Return list of labels (translated) of third parties type
58
-	 *
59
-	 *		@param	int		$mode		0=Return id+label, 1=Return code+label
60
-	 *      @param  string	$filter     Add a SQL filter to select
61
-	 *    	@return array      			Array of types
62
-	 */
63
-	function typent_array($mode=0, $filter='')
64
-	{
56
+    /**
57
+     *    	Return list of labels (translated) of third parties type
58
+     *
59
+     *		@param	int		$mode		0=Return id+label, 1=Return code+label
60
+     *      @param  string	$filter     Add a SQL filter to select
61
+     *    	@return array      			Array of types
62
+     */
63
+    function typent_array($mode=0, $filter='')
64
+    {
65 65
         // phpcs:enable
66
-		global $langs,$mysoc;
67
-
68
-		$effs = array();
69
-
70
-		$sql = "SELECT id, code, libelle";
71
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
72
-		$sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
73
-		if ($filter) $sql.=" ".$filter;
74
-		$sql.= " ORDER by position, id";
75
-		dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
76
-		$resql=$this->db->query($sql);
77
-		if ($resql)
78
-		{
79
-			$num = $this->db->num_rows($resql);
80
-			$i = 0;
81
-
82
-			while ($i < $num)
83
-			{
84
-				$objp = $this->db->fetch_object($resql);
85
-				if (! $mode) $key=$objp->id;
86
-				else $key=$objp->code;
87
-				if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
88
-				else $effs[$key] = $objp->libelle;
89
-				if ($effs[$key]=='-') $effs[$key]='';
90
-				$i++;
91
-			}
92
-			$this->db->free($resql);
93
-		}
94
-
95
-		return $effs;
96
-	}
66
+        global $langs,$mysoc;
67
+
68
+        $effs = array();
69
+
70
+        $sql = "SELECT id, code, libelle";
71
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
72
+        $sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
73
+        if ($filter) $sql.=" ".$filter;
74
+        $sql.= " ORDER by position, id";
75
+        dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
76
+        $resql=$this->db->query($sql);
77
+        if ($resql)
78
+        {
79
+            $num = $this->db->num_rows($resql);
80
+            $i = 0;
81
+
82
+            while ($i < $num)
83
+            {
84
+                $objp = $this->db->fetch_object($resql);
85
+                if (! $mode) $key=$objp->id;
86
+                else $key=$objp->code;
87
+                if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
88
+                else $effs[$key] = $objp->libelle;
89
+                if ($effs[$key]=='-') $effs[$key]='';
90
+                $i++;
91
+            }
92
+            $this->db->free($resql);
93
+        }
94
+
95
+        return $effs;
96
+    }
97 97
 
98 98
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
99
-	/**
100
-	 *	Renvoie la liste des types d'effectifs possibles (pas de traduction car nombre)
101
-	 *
102
-	 *	@param	int		$mode		0=renvoi id+libelle, 1=renvoi code+libelle
103
-	 *	@param  string	$filter     Add a SQL filter to select
104
-	 *  @return array				Array of types d'effectifs
105
-	 */
106
-	function effectif_array($mode=0, $filter='')
107
-	{
99
+    /**
100
+     *	Renvoie la liste des types d'effectifs possibles (pas de traduction car nombre)
101
+     *
102
+     *	@param	int		$mode		0=renvoi id+libelle, 1=renvoi code+libelle
103
+     *	@param  string	$filter     Add a SQL filter to select
104
+     *  @return array				Array of types d'effectifs
105
+     */
106
+    function effectif_array($mode=0, $filter='')
107
+    {
108 108
         // phpcs:enable
109
-		$effs = array();
110
-
111
-		$sql = "SELECT id, code, libelle";
112
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
113
-		$sql.= " WHERE active = 1";
114
-		if ($filter) $sql.=" ".$filter;
115
-		$sql .= " ORDER BY id ASC";
116
-		dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
117
-		$resql=$this->db->query($sql);
118
-		if ($resql)
119
-		{
120
-			$num = $this->db->num_rows($resql);
121
-			$i = 0;
122
-
123
-			while ($i < $num)
124
-			{
125
-				$objp = $this->db->fetch_object($resql);
126
-				if (! $mode) $key=$objp->id;
127
-				else $key=$objp->code;
128
-
129
-				$effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
130
-				$i++;
131
-			}
132
-			$this->db->free($resql);
133
-		}
134
-		return $effs;
135
-	}
109
+        $effs = array();
110
+
111
+        $sql = "SELECT id, code, libelle";
112
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
113
+        $sql.= " WHERE active = 1";
114
+        if ($filter) $sql.=" ".$filter;
115
+        $sql .= " ORDER BY id ASC";
116
+        dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
117
+        $resql=$this->db->query($sql);
118
+        if ($resql)
119
+        {
120
+            $num = $this->db->num_rows($resql);
121
+            $i = 0;
122
+
123
+            while ($i < $num)
124
+            {
125
+                $objp = $this->db->fetch_object($resql);
126
+                if (! $mode) $key=$objp->id;
127
+                else $key=$objp->code;
128
+
129
+                $effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
130
+                $i++;
131
+            }
132
+            $this->db->free($resql);
133
+        }
134
+        return $effs;
135
+    }
136 136
 
137 137
 
138 138
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
139
-	/**
140
-	 *  Affiche formulaire de selection des modes de reglement
141
-	 *
142
-	 *  @param	int		$page        	Page
143
-	 *  @param  int		$selected    	Id or code preselected
144
-	 *  @param  string	$htmlname   	Nom du formulaire select
145
-	 *	@param	int		$empty			Add empty value in list
146
-	 *	@return	void
147
-	 */
148
-	function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
149
-	{
139
+    /**
140
+     *  Affiche formulaire de selection des modes de reglement
141
+     *
142
+     *  @param	int		$page        	Page
143
+     *  @param  int		$selected    	Id or code preselected
144
+     *  @param  string	$htmlname   	Nom du formulaire select
145
+     *	@param	int		$empty			Add empty value in list
146
+     *	@return	void
147
+     */
148
+    function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
149
+    {
150 150
         // phpcs:enable
151
-		global $user, $langs;
152
-
153
-		print '<form method="post" action="'.$page.'">';
154
-		print '<input type="hidden" name="action" value="setprospectlevel">';
155
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
156
-
157
-		dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
158
-		$sql = "SELECT code, label";
159
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
160
-		$sql.= " WHERE active > 0";
161
-		$sql.= " ORDER BY sortorder";
162
-		$resql = $this->db->query($sql);
163
-		if ($resql)
164
-		{
165
-			$options = array();
166
-
167
-			if ($empty) {
168
-				$options[''] = '';
169
-			}
170
-
171
-			while ($obj = $this->db->fetch_object($resql)) {
172
-				$level = $langs->trans($obj->code);
173
-
174
-				if ($level == $obj->code) {
175
-					$level = $langs->trans($obj->label);
176
-				}
177
-
178
-				$options[$obj->code] = $level;
179
-			}
180
-
181
-			print Form::selectarray($htmlname, $options, $selected);
182
-		}
183
-		else dol_print_error($this->db);
184
-		if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
185
-		print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186
-		print '</form>';
187
-	}
151
+        global $user, $langs;
152
+
153
+        print '<form method="post" action="'.$page.'">';
154
+        print '<input type="hidden" name="action" value="setprospectlevel">';
155
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
156
+
157
+        dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
158
+        $sql = "SELECT code, label";
159
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
160
+        $sql.= " WHERE active > 0";
161
+        $sql.= " ORDER BY sortorder";
162
+        $resql = $this->db->query($sql);
163
+        if ($resql)
164
+        {
165
+            $options = array();
166
+
167
+            if ($empty) {
168
+                $options[''] = '';
169
+            }
170
+
171
+            while ($obj = $this->db->fetch_object($resql)) {
172
+                $level = $langs->trans($obj->code);
173
+
174
+                if ($level == $obj->code) {
175
+                    $level = $langs->trans($obj->label);
176
+                }
177
+
178
+                $options[$obj->code] = $level;
179
+            }
180
+
181
+            print Form::selectarray($htmlname, $options, $selected);
182
+        }
183
+        else dol_print_error($this->db);
184
+        if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
185
+        print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186
+        print '</form>';
187
+    }
188 188
 
189 189
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
190
-	/**
191
-	 *   Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
192
-	 *   Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
193
-	 *   La cle de la liste est le code (il peut y avoir plusieurs entree pour
194
-	 *   un code donnee mais dans ce cas, le champ pays differe).
195
-	 *   Ainsi les liens avec les departements se font sur un departement independemment de son nom.
196
-	 *
197
-	 *   @param     string	$selected        	Code state preselected
198
-	 *   @param     int		$country_codeid     0=list for all countries, otherwise country code or country rowid to show
199
-	 *   @param     string	$htmlname			Id of department
200
-	 *   @return	void
201
-	 */
202
-	function select_departement($selected='',$country_codeid=0, $htmlname='state_id')
203
-	{
190
+    /**
191
+     *   Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
192
+     *   Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
193
+     *   La cle de la liste est le code (il peut y avoir plusieurs entree pour
194
+     *   un code donnee mais dans ce cas, le champ pays differe).
195
+     *   Ainsi les liens avec les departements se font sur un departement independemment de son nom.
196
+     *
197
+     *   @param     string	$selected        	Code state preselected
198
+     *   @param     int		$country_codeid     0=list for all countries, otherwise country code or country rowid to show
199
+     *   @param     string	$htmlname			Id of department
200
+     *   @return	void
201
+     */
202
+    function select_departement($selected='',$country_codeid=0, $htmlname='state_id')
203
+    {
204 204
         // phpcs:enable
205
-		print $this->select_state($selected,$country_codeid, $htmlname);
206
-	}
205
+        print $this->select_state($selected,$country_codeid, $htmlname);
206
+    }
207 207
 
208 208
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
209
-	/**
210
-	 *    Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
211
-	 *    Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
212
-	 *    La cle de la liste est le code (il peut y avoir plusieurs entree pour
213
-	 *    un code donnee mais dans ce cas, le champ pays differe).
214
-	 *    Ainsi les liens avec les departements se font sur un departement independemment de son nom.
215
-	 *
216
-	 *    @param	string	$selected        	Code state preselected (mus be state id)
217
-	 *    @param    integer	$country_codeid    	Country code or id: 0=list for all countries, otherwise country code or country rowid to show
218
-	 *    @param    string	$htmlname			Id of department. If '', we want only the string with <option>
219
-	 * 	  @return	string						String with HTML select
220
-	 *    @see select_country
221
-	 */
222
-	function select_state($selected='',$country_codeid=0, $htmlname='state_id')
223
-	{
209
+    /**
210
+     *    Retourne la liste deroulante des departements/province/cantons tout pays confondu ou pour un pays donne.
211
+     *    Dans le cas d'une liste tout pays confondus, l'affichage fait une rupture sur le pays.
212
+     *    La cle de la liste est le code (il peut y avoir plusieurs entree pour
213
+     *    un code donnee mais dans ce cas, le champ pays differe).
214
+     *    Ainsi les liens avec les departements se font sur un departement independemment de son nom.
215
+     *
216
+     *    @param	string	$selected        	Code state preselected (mus be state id)
217
+     *    @param    integer	$country_codeid    	Country code or id: 0=list for all countries, otherwise country code or country rowid to show
218
+     *    @param    string	$htmlname			Id of department. If '', we want only the string with <option>
219
+     * 	  @return	string						String with HTML select
220
+     *    @see select_country
221
+     */
222
+    function select_state($selected='',$country_codeid=0, $htmlname='state_id')
223
+    {
224 224
         // phpcs:enable
225
-		global $conf,$langs,$user;
226
-
227
-		dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
228
-
229
-		$langs->load("dict");
230
-
231
-		$out='';
232
-
233
-		// Serch departements/cantons/province active d'une region et pays actif
234
-		$sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
235
-		$sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
236
-		$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
237
-		$sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
238
-		if ($country_codeid && is_numeric($country_codeid))   $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
239
-		if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
240
-		$sql .= " ORDER BY c.code, d.code_departement";
241
-
242
-		$result=$this->db->query($sql);
243
-		if ($result)
244
-		{
245
-			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
246
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
247
-			$num = $this->db->num_rows($result);
248
-			$i = 0;
249
-			dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
250
-			if ($num)
251
-			{
252
-				$country='';
253
-				while ($i < $num)
254
-				{
255
-					$obj = $this->db->fetch_object($result);
256
-					if ($obj->code == '0')		// Le code peut etre une chaine
257
-					{
258
-						$out.= '<option value="0">&nbsp;</option>';
259
-					}
260
-					else {
261
-						if (! $country || $country != $obj->country)
262
-						{
263
-							// Affiche la rupture si on est en mode liste multipays
264
-							if (! $country_codeid && $obj->country_code)
265
-							{
266
-								$out.= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
267
-								$country=$obj->country;
268
-							}
269
-						}
270
-
271
-						if ((! empty($selected) && $selected == $obj->rowid)
272
-						 || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
273
-						{
274
-							$out.= '<option value="'.$obj->rowid.'" selected>';
275
-						}
276
-						else
277
-						{
278
-							$out.= '<option value="'.$obj->rowid.'">';
279
-						}
280
-
281
-						// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
282
-						if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
283
-						($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
284
-							if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
285
-								$out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
286
-							}
287
-							else {
288
-								$out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
289
-							}
290
-						}
291
-						else {
292
-							if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
293
-								$out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
294
-							}
295
-							else {
296
-								$out.= ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
297
-							}
298
-						}
299
-
300
-						$out.= '</option>';
301
-					}
302
-					$i++;
303
-				}
304
-			}
305
-			if (! empty($htmlname)) $out.= '</select>';
306
-			if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
307
-		}
308
-		else
309
-		{
310
-			dol_print_error($this->db);
311
-		}
312
-
313
-		// Make select dynamic
314
-		if (! empty($htmlname))
315
-		{
316
-			include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
317
-			$out .= ajax_combobox($htmlname);
318
-		}
319
-
320
-		return $out;
321
-	}
225
+        global $conf,$langs,$user;
226
+
227
+        dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
228
+
229
+        $langs->load("dict");
230
+
231
+        $out='';
232
+
233
+        // Serch departements/cantons/province active d'une region et pays actif
234
+        $sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
235
+        $sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
236
+        $sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
237
+        $sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
238
+        if ($country_codeid && is_numeric($country_codeid))   $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
239
+        if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
240
+        $sql .= " ORDER BY c.code, d.code_departement";
241
+
242
+        $result=$this->db->query($sql);
243
+        if ($result)
244
+        {
245
+            if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
246
+            if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
247
+            $num = $this->db->num_rows($result);
248
+            $i = 0;
249
+            dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
250
+            if ($num)
251
+            {
252
+                $country='';
253
+                while ($i < $num)
254
+                {
255
+                    $obj = $this->db->fetch_object($result);
256
+                    if ($obj->code == '0')		// Le code peut etre une chaine
257
+                    {
258
+                        $out.= '<option value="0">&nbsp;</option>';
259
+                    }
260
+                    else {
261
+                        if (! $country || $country != $obj->country)
262
+                        {
263
+                            // Affiche la rupture si on est en mode liste multipays
264
+                            if (! $country_codeid && $obj->country_code)
265
+                            {
266
+                                $out.= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
267
+                                $country=$obj->country;
268
+                            }
269
+                        }
270
+
271
+                        if ((! empty($selected) && $selected == $obj->rowid)
272
+                         || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
273
+                        {
274
+                            $out.= '<option value="'.$obj->rowid.'" selected>';
275
+                        }
276
+                        else
277
+                        {
278
+                            $out.= '<option value="'.$obj->rowid.'">';
279
+                        }
280
+
281
+                        // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
282
+                        if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
283
+                        ($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
284
+                            if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
285
+                                $out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
286
+                            }
287
+                            else {
288
+                                $out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
289
+                            }
290
+                        }
291
+                        else {
292
+                            if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
293
+                                $out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
294
+                            }
295
+                            else {
296
+                                $out.= ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
297
+                            }
298
+                        }
299
+
300
+                        $out.= '</option>';
301
+                    }
302
+                    $i++;
303
+                }
304
+            }
305
+            if (! empty($htmlname)) $out.= '</select>';
306
+            if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
307
+        }
308
+        else
309
+        {
310
+            dol_print_error($this->db);
311
+        }
312
+
313
+        // Make select dynamic
314
+        if (! empty($htmlname))
315
+        {
316
+            include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
317
+            $out .= ajax_combobox($htmlname);
318
+        }
319
+
320
+        return $out;
321
+    }
322 322
 
323 323
 
324 324
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
325
-	/**
326
-	 *   Retourne la liste deroulante des regions actives dont le pays est actif
327
-	 *   La cle de la liste est le code (il peut y avoir plusieurs entree pour
328
-	 *   un code donnee mais dans ce cas, le champ pays et lang differe).
329
-	 *   Ainsi les liens avec les regions se font sur une region independemment de son name.
330
-	 *
331
-	 *   @param		string		$selected		Preselected value
332
-	 *   @param		string		$htmlname		Name of HTML select field
333
-	 *   @return	void
334
-	 */
335
-	function select_region($selected='',$htmlname='region_id')
336
-	{
325
+    /**
326
+     *   Retourne la liste deroulante des regions actives dont le pays est actif
327
+     *   La cle de la liste est le code (il peut y avoir plusieurs entree pour
328
+     *   un code donnee mais dans ce cas, le champ pays et lang differe).
329
+     *   Ainsi les liens avec les regions se font sur une region independemment de son name.
330
+     *
331
+     *   @param		string		$selected		Preselected value
332
+     *   @param		string		$htmlname		Name of HTML select field
333
+     *   @return	void
334
+     */
335
+    function select_region($selected='',$htmlname='region_id')
336
+    {
337 337
         // phpcs:enable
338
-		global $conf,$langs;
339
-		$langs->load("dict");
340
-
341
-		$sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
342
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
343
-		$sql.= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
344
-		$sql.= " ORDER BY c.code, c.label ASC";
345
-
346
-		dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
347
-		$resql=$this->db->query($sql);
348
-		if ($resql)
349
-		{
350
-			print '<select class="flat" name="'.$htmlname.'">';
351
-			$num = $this->db->num_rows($resql);
352
-			$i = 0;
353
-			if ($num)
354
-			{
355
-				$country='';
356
-				while ($i < $num)
357
-				{
358
-					$obj = $this->db->fetch_object($resql);
359
-					if ($obj->code == 0) {
360
-						print '<option value="0">&nbsp;</option>';
361
-					}
362
-					else {
363
-						if ($country == '' || $country != $obj->country)
364
-						{
365
-							// Show break
366
-							$key=$langs->trans("Country".strtoupper($obj->country_code));
367
-							$valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
368
-							print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
369
-							$country=$obj->country;
370
-						}
371
-
372
-						if ($selected > 0 && $selected == $obj->code)
373
-						{
374
-							print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
375
-						}
376
-						else
377
-						{
378
-							print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
379
-						}
380
-					}
381
-					$i++;
382
-				}
383
-			}
384
-			print '</select>';
385
-		}
386
-		else
387
-		{
388
-			dol_print_error($this->db);
389
-		}
390
-	}
338
+        global $conf,$langs;
339
+        $langs->load("dict");
340
+
341
+        $sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
342
+        $sql.= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
343
+        $sql.= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
344
+        $sql.= " ORDER BY c.code, c.label ASC";
345
+
346
+        dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
347
+        $resql=$this->db->query($sql);
348
+        if ($resql)
349
+        {
350
+            print '<select class="flat" name="'.$htmlname.'">';
351
+            $num = $this->db->num_rows($resql);
352
+            $i = 0;
353
+            if ($num)
354
+            {
355
+                $country='';
356
+                while ($i < $num)
357
+                {
358
+                    $obj = $this->db->fetch_object($resql);
359
+                    if ($obj->code == 0) {
360
+                        print '<option value="0">&nbsp;</option>';
361
+                    }
362
+                    else {
363
+                        if ($country == '' || $country != $obj->country)
364
+                        {
365
+                            // Show break
366
+                            $key=$langs->trans("Country".strtoupper($obj->country_code));
367
+                            $valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
368
+                            print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
369
+                            $country=$obj->country;
370
+                        }
371
+
372
+                        if ($selected > 0 && $selected == $obj->code)
373
+                        {
374
+                            print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
375
+                        }
376
+                        else
377
+                        {
378
+                            print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
379
+                        }
380
+                    }
381
+                    $i++;
382
+                }
383
+            }
384
+            print '</select>';
385
+        }
386
+        else
387
+        {
388
+            dol_print_error($this->db);
389
+        }
390
+    }
391 391
 
392 392
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
393
-	/**
394
-	 *  Return combo list with people title
395
-	 *
396
-	 *  @param  string	$selected   	Title preselected
397
-	 * 	@param	string	$htmlname		Name of HTML select combo field
398
-	 *  @param  string  $morecss        Add more css on SELECT element
399
-	 *  @return	string					String with HTML select
400
-	 */
401
-	function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100')
402
-	{
393
+    /**
394
+     *  Return combo list with people title
395
+     *
396
+     *  @param  string	$selected   	Title preselected
397
+     * 	@param	string	$htmlname		Name of HTML select combo field
398
+     *  @param  string  $morecss        Add more css on SELECT element
399
+     *  @return	string					String with HTML select
400
+     */
401
+    function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100')
402
+    {
403 403
         // phpcs:enable
404
-		global $conf,$langs,$user;
405
-		$langs->load("dict");
406
-
407
-		$out='';
408
-
409
-		$sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
410
-		$sql.= " WHERE active = 1";
411
-
412
-		dol_syslog("Form::select_civility", LOG_DEBUG);
413
-		$resql=$this->db->query($sql);
414
-		if ($resql)
415
-		{
416
-			$out.= '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
417
-			$out.= '<option value="">&nbsp;</option>';
418
-			$num = $this->db->num_rows($resql);
419
-			$i = 0;
420
-			if ($num)
421
-			{
422
-				while ($i < $num)
423
-				{
424
-					$obj = $this->db->fetch_object($resql);
425
-					if ($selected == $obj->code)
426
-					{
427
-						$out.= '<option value="'.$obj->code.'" selected>';
428
-					}
429
-					else
430
-					{
431
-						$out.= '<option value="'.$obj->code.'">';
432
-					}
433
-					// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
434
-					$out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label!='-'?$obj->label:''));
435
-					$out.= '</option>';
436
-					$i++;
437
-				}
438
-			}
439
-			$out.= '</select>';
440
-			if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
441
-		}
442
-		else
443
-		{
444
-			dol_print_error($this->db);
445
-		}
446
-
447
-		return $out;
448
-	}
404
+        global $conf,$langs,$user;
405
+        $langs->load("dict");
406
+
407
+        $out='';
408
+
409
+        $sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
410
+        $sql.= " WHERE active = 1";
411
+
412
+        dol_syslog("Form::select_civility", LOG_DEBUG);
413
+        $resql=$this->db->query($sql);
414
+        if ($resql)
415
+        {
416
+            $out.= '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
417
+            $out.= '<option value="">&nbsp;</option>';
418
+            $num = $this->db->num_rows($resql);
419
+            $i = 0;
420
+            if ($num)
421
+            {
422
+                while ($i < $num)
423
+                {
424
+                    $obj = $this->db->fetch_object($resql);
425
+                    if ($selected == $obj->code)
426
+                    {
427
+                        $out.= '<option value="'.$obj->code.'" selected>';
428
+                    }
429
+                    else
430
+                    {
431
+                        $out.= '<option value="'.$obj->code.'">';
432
+                    }
433
+                    // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
434
+                    $out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label!='-'?$obj->label:''));
435
+                    $out.= '</option>';
436
+                    $i++;
437
+                }
438
+            }
439
+            $out.= '</select>';
440
+            if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
441
+        }
442
+        else
443
+        {
444
+            dol_print_error($this->db);
445
+        }
446
+
447
+        return $out;
448
+    }
449 449
 
450 450
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
451
-	/**
452
-	 *    Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
453
-	 *    Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays.
454
-	 *
455
-	 *    @param	string		$selected        	Code forme juridique a pre-selectionne
456
-	 *    @param    mixed		$country_codeid		0=liste tous pays confondus, sinon code du pays a afficher
457
-	 *    @param    string		$filter          	Add a SQL filter on list
458
-	 *    @return	void
459
-	 *    @deprecated Use print xxx->select_juridicalstatus instead
460
-	 *    @see select_juridicalstatus()
461
-	 */
462
-	function select_forme_juridique($selected='', $country_codeid=0, $filter='')
463
-	{
451
+    /**
452
+     *    Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
453
+     *    Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays.
454
+     *
455
+     *    @param	string		$selected        	Code forme juridique a pre-selectionne
456
+     *    @param    mixed		$country_codeid		0=liste tous pays confondus, sinon code du pays a afficher
457
+     *    @param    string		$filter          	Add a SQL filter on list
458
+     *    @return	void
459
+     *    @deprecated Use print xxx->select_juridicalstatus instead
460
+     *    @see select_juridicalstatus()
461
+     */
462
+    function select_forme_juridique($selected='', $country_codeid=0, $filter='')
463
+    {
464 464
         // phpcs:enable
465
-		print $this->select_juridicalstatus($selected, $country_codeid, $filter);
466
-	}
465
+        print $this->select_juridicalstatus($selected, $country_codeid, $filter);
466
+    }
467 467
 
468 468
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
469
-	/**
470
-	 *    Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
471
-	 *    Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays
472
-	 *
473
-	 *    @param	string		$selected        	Preselected code of juridical type
474
-	 *    @param    int			$country_codeid     0=list for all countries, otherwise list only country requested
469
+    /**
470
+     *    Retourne la liste deroulante des formes juridiques tous pays confondus ou pour un pays donne.
471
+     *    Dans le cas d'une liste tous pays confondu, on affiche une rupture sur le pays
472
+     *
473
+     *    @param	string		$selected        	Preselected code of juridical type
474
+     *    @param    int			$country_codeid     0=list for all countries, otherwise list only country requested
475 475
      *    @param    string		$filter          	Add a SQL filter on list
476 476
      *    @param	string		$htmlname			HTML name of select
477 477
      *    @return	string							String with HTML select
478
-	 */
479
-	function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
480
-	{
478
+     */
479
+    function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
480
+    {
481 481
         // phpcs:enable
482
-		global $conf,$langs,$user;
483
-		$langs->load("dict");
484
-
485
-		$out='';
486
-
487
-		// On recherche les formes juridiques actives des pays actifs
488
-		$sql  = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
489
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
490
-		$sql .= " WHERE f.fk_pays=c.rowid";
491
-		$sql .= " AND f.active = 1 AND c.active = 1";
492
-		if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'";
493
-		if ($filter) $sql .= " ".$filter;
494
-		$sql .= " ORDER BY c.code";
495
-
496
-		dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
497
-		$resql=$this->db->query($sql);
498
-		if ($resql)
499
-		{
500
-			$out.= '<div id="particulier2" class="visible">';
501
-			$out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
502
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';	// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
503
-
504
-			$num = $this->db->num_rows($resql);
505
-			if ($num)
506
-			{
507
-				$i = 0;
508
-				$country=''; $arraydata=array();
509
-				while ($i < $num)
510
-				{
511
-					$obj = $this->db->fetch_object($resql);
512
-
513
-					if ($obj->code)		// We exclude empty line, we will add it later
514
-					{
515
-						$labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
516
-						$labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:''));	// $obj->label is already in output charset (converted by database driver)
517
-						$arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
518
-					}
519
-					$i++;
520
-				}
521
-
522
-				$arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
523
-				if (empty($country_codeid))	// Introduce empty value (if $country_codeid not empty, empty value was already added)
524
-				{
525
-					$arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
526
-				}
527
-
528
-				foreach($arraydata as $key => $val)
529
-				{
530
-					if (! $country || $country != $val['country'])
531
-					{
532
-						// Show break when we are in multi country mode
533
-						if (empty($country_codeid) && $val['country_code'])
534
-						{
535
-							$out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
536
-							$country=$val['country'];
537
-						}
538
-					}
539
-
540
-					if ($selected > 0 && $selected == $val['code'])
541
-					{
542
-						$out.= '<option value="'.$val['code'].'" selected>';
543
-					}
544
-					else
545
-					{
546
-						$out.= '<option value="'.$val['code'].'">';
547
-					}
548
-					// If translation exists, we use it, otherwise we use default label in database
549
-					$out.= $val['label'];
550
-					$out.= '</option>';
551
-				}
552
-			}
553
-			$out.= '</select>';
554
-			if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
555
-
556
-		    // Make select dynamic
557
-        	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
558
-	        $out .= ajax_combobox($htmlname);
559
-
560
-			$out.= '</div>';
561
-		}
562
-		else
563
-		{
564
-			dol_print_error($this->db);
565
-		}
566
-
567
-		return $out;
568
-	}
569
-
570
-
571
-	/**
572
-	 *  Output list of third parties.
573
-	 *
574
-	 *  @param  object		$object         Object we try to find contacts
575
-	 *  @param  string		$var_id         Name of id field
576
-	 *  @param  string		$selected       Pre-selected third party
577
-	 *  @param  string		$htmlname       Name of HTML form
578
-	 * 	@param	array		$limitto		Disable answers that are not id in this array list
579
-	 *  @param	int			$forceid		This is to force another object id than object->id
482
+        global $conf,$langs,$user;
483
+        $langs->load("dict");
484
+
485
+        $out='';
486
+
487
+        // On recherche les formes juridiques actives des pays actifs
488
+        $sql  = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
489
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
490
+        $sql .= " WHERE f.fk_pays=c.rowid";
491
+        $sql .= " AND f.active = 1 AND c.active = 1";
492
+        if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'";
493
+        if ($filter) $sql .= " ".$filter;
494
+        $sql .= " ORDER BY c.code";
495
+
496
+        dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
497
+        $resql=$this->db->query($sql);
498
+        if ($resql)
499
+        {
500
+            $out.= '<div id="particulier2" class="visible">';
501
+            $out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
502
+            if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';	// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
503
+
504
+            $num = $this->db->num_rows($resql);
505
+            if ($num)
506
+            {
507
+                $i = 0;
508
+                $country=''; $arraydata=array();
509
+                while ($i < $num)
510
+                {
511
+                    $obj = $this->db->fetch_object($resql);
512
+
513
+                    if ($obj->code)		// We exclude empty line, we will add it later
514
+                    {
515
+                        $labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
516
+                        $labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:''));	// $obj->label is already in output charset (converted by database driver)
517
+                        $arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
518
+                    }
519
+                    $i++;
520
+                }
521
+
522
+                $arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
523
+                if (empty($country_codeid))	// Introduce empty value (if $country_codeid not empty, empty value was already added)
524
+                {
525
+                    $arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
526
+                }
527
+
528
+                foreach($arraydata as $key => $val)
529
+                {
530
+                    if (! $country || $country != $val['country'])
531
+                    {
532
+                        // Show break when we are in multi country mode
533
+                        if (empty($country_codeid) && $val['country_code'])
534
+                        {
535
+                            $out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
536
+                            $country=$val['country'];
537
+                        }
538
+                    }
539
+
540
+                    if ($selected > 0 && $selected == $val['code'])
541
+                    {
542
+                        $out.= '<option value="'.$val['code'].'" selected>';
543
+                    }
544
+                    else
545
+                    {
546
+                        $out.= '<option value="'.$val['code'].'">';
547
+                    }
548
+                    // If translation exists, we use it, otherwise we use default label in database
549
+                    $out.= $val['label'];
550
+                    $out.= '</option>';
551
+                }
552
+            }
553
+            $out.= '</select>';
554
+            if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
555
+
556
+            // Make select dynamic
557
+            include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
558
+            $out .= ajax_combobox($htmlname);
559
+
560
+            $out.= '</div>';
561
+        }
562
+        else
563
+        {
564
+            dol_print_error($this->db);
565
+        }
566
+
567
+        return $out;
568
+    }
569
+
570
+
571
+    /**
572
+     *  Output list of third parties.
573
+     *
574
+     *  @param  object		$object         Object we try to find contacts
575
+     *  @param  string		$var_id         Name of id field
576
+     *  @param  string		$selected       Pre-selected third party
577
+     *  @param  string		$htmlname       Name of HTML form
578
+     * 	@param	array		$limitto		Disable answers that are not id in this array list
579
+     *  @param	int			$forceid		This is to force another object id than object->id
580 580
      *  @param	string		$moreparam		String with more param to add into url when noajax search is used.
581 581
      *  @param	string		$morecss		More CSS on select component
582
-	 * 	@return int 						The selected third party ID
583
-	 */
584
-	function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='', $morecss='')
585
-	{
586
-		global $conf, $langs;
587
-
588
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
589
-		{
590
-			// Use Ajax search
591
-			$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
592
-
593
-			$socid=0; $name='';
594
-			if ($selected > 0)
595
-			{
596
-				$tmpthirdparty=new Societe($this->db);
597
-				$result = $tmpthirdparty->fetch($selected);
598
-				if ($result > 0)
599
-				{
600
-					$socid = $selected;
601
-					$name = $tmpthirdparty->name;
602
-				}
603
-			}
604
-
605
-
606
-			$events=array();
607
-			// Add an entry 'method' to say 'yes, we must execute url with param action = method';
608
-			// Add an entry 'url' to say which url to execute
609
-			// Add an entry htmlname to say which element we must change once url is called
610
-			// Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return  0 or >0 lines
611
-			// To refresh contacts list on thirdparty list change
612
-			$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
613
-
614
-			if (count($events))	// If there is some ajax events to run once selection is done, we add code here to run events
615
-			{
616
-				print '<script type="text/javascript">
582
+     * 	@return int 						The selected third party ID
583
+     */
584
+    function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='', $morecss='')
585
+    {
586
+        global $conf, $langs;
587
+
588
+        if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
589
+        {
590
+            // Use Ajax search
591
+            $minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
592
+
593
+            $socid=0; $name='';
594
+            if ($selected > 0)
595
+            {
596
+                $tmpthirdparty=new Societe($this->db);
597
+                $result = $tmpthirdparty->fetch($selected);
598
+                if ($result > 0)
599
+                {
600
+                    $socid = $selected;
601
+                    $name = $tmpthirdparty->name;
602
+                }
603
+            }
604
+
605
+
606
+            $events=array();
607
+            // Add an entry 'method' to say 'yes, we must execute url with param action = method';
608
+            // Add an entry 'url' to say which url to execute
609
+            // Add an entry htmlname to say which element we must change once url is called
610
+            // Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return  0 or >0 lines
611
+            // To refresh contacts list on thirdparty list change
612
+            $events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
613
+
614
+            if (count($events))	// If there is some ajax events to run once selection is done, we add code here to run events
615
+            {
616
+                print '<script type="text/javascript">
617 617
 				jQuery(document).ready(function() {
618 618
 					$("#search_'.$htmlname.'").change(function() {
619 619
 						var obj = '.json_encode($events).';
@@ -661,72 +661,72 @@  discard block
 block discarded – undo
661 661
 					};
662 662
 				});
663 663
 				</script>';
664
-			}
665
-
666
-			print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
667
-			print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
668
-			print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
669
-			return $socid;
670
-		}
671
-		else
672
-		{
673
-			// Search to list thirdparties
674
-			$sql = "SELECT s.rowid, s.nom as name FROM";
675
-			$sql.= " ".MAIN_DB_PREFIX."societe as s";
676
-			$sql.= " WHERE s.entity IN (".getEntity('societe').")";
677
-			// For ajax search we limit here. For combo list, we limit later
678
-			if (is_array($limitto) && count($limitto))
679
-			{
680
-				$sql.= " AND s.rowid IN (".join(',',$limitto).")";
681
-			}
682
-			$sql.= " ORDER BY s.nom ASC";
683
-
684
-			$resql = $this->db->query($sql);
685
-			if ($resql)
686
-			{
687
-				print '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"';
688
-				if ($conf->use_javascript_ajax)
689
-				{
690
-					$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
691
-					print ' onChange="'.$javaScript.'"';
692
-				}
693
-				print '>';
694
-				$num = $this->db->num_rows($resql);
695
-				$i = 0;
696
-				if ($num)
697
-				{
698
-					while ($i < $num)
699
-					{
700
-						$obj = $this->db->fetch_object($resql);
701
-						if ($i == 0) $firstCompany = $obj->rowid;
702
-						$disabled=0;
703
-						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
704
-						if ($selected > 0 && $selected == $obj->rowid)
705
-						{
706
-							print '<option value="'.$obj->rowid.'"';
707
-							if ($disabled) print ' disabled';
708
-							print ' selected>'.dol_trunc($obj->name,24).'</option>';
709
-							$firstCompany = $obj->rowid;
710
-						}
711
-						else
712
-						{
713
-							print '<option value="'.$obj->rowid.'"';
714
-							if ($disabled) print ' disabled';
715
-							print '>'.dol_trunc($obj->name,24).'</option>';
716
-						}
717
-						$i ++;
718
-					}
719
-				}
720
-				print "</select>\n";
721
-				return $firstCompany;
722
-			}
723
-			else
724
-			{
725
-				dol_print_error($this->db);
726
-				print 'Error sql';
727
-			}
728
-		}
729
-	}
664
+            }
665
+
666
+            print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
667
+            print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
668
+            print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
669
+            return $socid;
670
+        }
671
+        else
672
+        {
673
+            // Search to list thirdparties
674
+            $sql = "SELECT s.rowid, s.nom as name FROM";
675
+            $sql.= " ".MAIN_DB_PREFIX."societe as s";
676
+            $sql.= " WHERE s.entity IN (".getEntity('societe').")";
677
+            // For ajax search we limit here. For combo list, we limit later
678
+            if (is_array($limitto) && count($limitto))
679
+            {
680
+                $sql.= " AND s.rowid IN (".join(',',$limitto).")";
681
+            }
682
+            $sql.= " ORDER BY s.nom ASC";
683
+
684
+            $resql = $this->db->query($sql);
685
+            if ($resql)
686
+            {
687
+                print '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"';
688
+                if ($conf->use_javascript_ajax)
689
+                {
690
+                    $javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
691
+                    print ' onChange="'.$javaScript.'"';
692
+                }
693
+                print '>';
694
+                $num = $this->db->num_rows($resql);
695
+                $i = 0;
696
+                if ($num)
697
+                {
698
+                    while ($i < $num)
699
+                    {
700
+                        $obj = $this->db->fetch_object($resql);
701
+                        if ($i == 0) $firstCompany = $obj->rowid;
702
+                        $disabled=0;
703
+                        if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
704
+                        if ($selected > 0 && $selected == $obj->rowid)
705
+                        {
706
+                            print '<option value="'.$obj->rowid.'"';
707
+                            if ($disabled) print ' disabled';
708
+                            print ' selected>'.dol_trunc($obj->name,24).'</option>';
709
+                            $firstCompany = $obj->rowid;
710
+                        }
711
+                        else
712
+                        {
713
+                            print '<option value="'.$obj->rowid.'"';
714
+                            if ($disabled) print ' disabled';
715
+                            print '>'.dol_trunc($obj->name,24).'</option>';
716
+                        }
717
+                        $i ++;
718
+                    }
719
+                }
720
+                print "</select>\n";
721
+                return $firstCompany;
722
+            }
723
+            else
724
+            {
725
+                dol_print_error($this->db);
726
+                print 'Error sql';
727
+            }
728
+        }
729
+    }
730 730
 
731 731
     /**
732 732
      *  Return a select list with types of contacts
@@ -740,59 +740,59 @@  discard block
 block discarded – undo
740 740
      *  @param  string      $morecss        Add more css to select component
741 741
      *  @return	void
742 742
      */
743
-	function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
744
-	{
745
-	    global $user, $langs;
746
-
747
-		if (is_object($object) && method_exists($object, 'liste_type_contact'))
748
-		{
749
-			$lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
750
-			print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
751
-			if ($showempty) print '<option value="0"></option>';
752
-			foreach($lesTypes as $key=>$value)
753
-			{
754
-				print '<option value="'.$key.'"';
755
-				if ($key == $selected) print ' selected';
756
-				print '>'.$value.'</option>';
757
-			}
758
-			print "</select>";
759
-			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
760
-			print "\n";
761
-		}
762
-	}
743
+    function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
744
+    {
745
+        global $user, $langs;
746
+
747
+        if (is_object($object) && method_exists($object, 'liste_type_contact'))
748
+        {
749
+            $lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
750
+            print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
751
+            if ($showempty) print '<option value="0"></option>';
752
+            foreach($lesTypes as $key=>$value)
753
+            {
754
+                print '<option value="'.$key.'"';
755
+                if ($key == $selected) print ' selected';
756
+                print '>'.$value.'</option>';
757
+            }
758
+            print "</select>";
759
+            if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
760
+            print "\n";
761
+        }
762
+    }
763 763
 
764 764
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
765
-	/**
766
-	 *    Return a select list with zip codes and their town
767
-	 *
768
-	 *    @param	string		$selected				Preselected value
769
-	 *    @param    string		$htmlname				HTML select name
770
-	 *    @param    string		$fields					Fields
771
-	 *    @param    int			$fieldsize				Field size
772
-	 *    @param    int			$disableautocomplete    1 To disable ajax autocomplete features (browser autocomplete may still occurs)
773
-	 *    @param	string		$moreattrib				Add more attribute on HTML input field
774
-	 *    @param    string      $morecss                More css
775
-	 *    @return	string
776
-	 */
777
-	function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='',$morecss='')
778
-	{
765
+    /**
766
+     *    Return a select list with zip codes and their town
767
+     *
768
+     *    @param	string		$selected				Preselected value
769
+     *    @param    string		$htmlname				HTML select name
770
+     *    @param    string		$fields					Fields
771
+     *    @param    int			$fieldsize				Field size
772
+     *    @param    int			$disableautocomplete    1 To disable ajax autocomplete features (browser autocomplete may still occurs)
773
+     *    @param	string		$moreattrib				Add more attribute on HTML input field
774
+     *    @param    string      $morecss                More css
775
+     *    @return	string
776
+     */
777
+    function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='',$morecss='')
778
+    {
779 779
         // phpcs:enable
780
-		global $conf;
780
+        global $conf;
781 781
 
782
-		$out='';
782
+        $out='';
783 783
 
784
-		$size='';
785
-		if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
784
+        $size='';
785
+        if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
786 786
 
787
-		if ($conf->use_javascript_ajax && empty($disableautocomplete))
788
-		{
789
-			$out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
790
-			$moreattrib.=' autocomplete="off"';
791
-		}
792
-		$out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss?' '.$morecss:'').'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
787
+        if ($conf->use_javascript_ajax && empty($disableautocomplete))
788
+        {
789
+            $out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
790
+            $moreattrib.=' autocomplete="off"';
791
+        }
792
+        $out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss?' '.$morecss:'').'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
793 793
 
794
-		return $out;
795
-	}
794
+        return $out;
795
+    }
796 796
 
797 797
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
798 798
     /**
@@ -812,30 +812,30 @@  discard block
 block discarded – undo
812 812
 
813 813
         $formlength=0;
814 814
         if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
815
-        	if ($country_code == 'FR')
816
-        	{
817
-        		if (isset($idprof)) {
818
-        			if ($idprof==1) $formlength=9;
819
-        			else if ($idprof==2) $formlength=14;
820
-        			else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
821
-        			else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
822
-        		}
823
-        	}
824
-        	else if ($country_code == 'ES')
825
-        	{
826
-        		if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
827
-        		if ($idprof==2) $formlength=12; //NASS 12 digits without /
828
-        		if ($idprof==3) $formlength=5;  //CNAE 5 digits
829
-        		if ($idprof==4) $formlength=32; //depend of college
830
-        	}
815
+            if ($country_code == 'FR')
816
+            {
817
+                if (isset($idprof)) {
818
+                    if ($idprof==1) $formlength=9;
819
+                    else if ($idprof==2) $formlength=14;
820
+                    else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
821
+                    else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
822
+                }
823
+            }
824
+            else if ($country_code == 'ES')
825
+            {
826
+                if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
827
+                if ($idprof==2) $formlength=12; //NASS 12 digits without /
828
+                if ($idprof==3) $formlength=5;  //CNAE 5 digits
829
+                if ($idprof==4) $formlength=32; //depend of college
830
+            }
831 831
         }
832 832
 
833 833
         $selected=$preselected;
834 834
         if (! $selected && isset($idprof)) {
835
-        	if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
836
-        	else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
837
-        	else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
838
-        	else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
835
+            if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
836
+            else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
837
+            else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
838
+            else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
839 839
         }
840 840
 
841 841
         $maxlength=$formlength;
@@ -862,30 +862,30 @@  discard block
 block discarded – undo
862 862
 
863 863
         $num = $this->db->num_rows($tax);
864 864
         $i = 0;
865
-    	if ($num)
866
-    	{
867
-    		$valors=explode(":", $tax);
868
-
869
-    		if (count($valors) > 1)
870
-    		{
871
-    			//montar select
872
-    			print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
873
-    			while ($i <= (count($valors))-1)
874
-    			{
875
-    				if ($selected == $valors[$i])
876
-    				{
877
-    					print '<option value="'.$valors[$i].'" selected>';
878
-    				}
879
-    				else
880
-    				{
881
-    					print '<option value="'.$valors[$i].'">';
882
-    				}
883
-    				print $valors[$i];
884
-    				print '</option>';
885
-    				$i++;
886
-    			}
887
-    			print'</select>';
888
-    		}
889
-    	}
865
+        if ($num)
866
+        {
867
+            $valors=explode(":", $tax);
868
+
869
+            if (count($valors) > 1)
870
+            {
871
+                //montar select
872
+                print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
873
+                while ($i <= (count($valors))-1)
874
+                {
875
+                    if ($selected == $valors[$i])
876
+                    {
877
+                        print '<option value="'.$valors[$i].'" selected>';
878
+                    }
879
+                    else
880
+                    {
881
+                        print '<option value="'.$valors[$i].'">';
882
+                    }
883
+                    print $valors[$i];
884
+                    print '</option>';
885
+                    $i++;
886
+                }
887
+                print'</select>';
888
+            }
889
+        }
890 890
     }
891 891
 }
Please login to merge, or discard this patch.
Spacing   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	/**
40 40
 	 * @var string Error code (or message)
41 41
 	 */
42
-	public $error='';
42
+	public $error = '';
43 43
 
44 44
 	/**
45 45
 	 *	Constructor
@@ -60,20 +60,20 @@  discard block
 block discarded – undo
60 60
 	 *      @param  string	$filter     Add a SQL filter to select
61 61
 	 *    	@return array      			Array of types
62 62
 	 */
63
-	function typent_array($mode=0, $filter='')
63
+	function typent_array($mode = 0, $filter = '')
64 64
 	{
65 65
         // phpcs:enable
66
-		global $langs,$mysoc;
66
+		global $langs, $mysoc;
67 67
 
68 68
 		$effs = array();
69 69
 
70 70
 		$sql = "SELECT id, code, libelle";
71
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
72
-		$sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
73
-		if ($filter) $sql.=" ".$filter;
74
-		$sql.= " ORDER by position, id";
71
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_typent";
72
+		$sql .= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id) ? '0' : $mysoc->country_id).")";
73
+		if ($filter) $sql .= " ".$filter;
74
+		$sql .= " ORDER by position, id";
75 75
 		dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
76
-		$resql=$this->db->query($sql);
76
+		$resql = $this->db->query($sql);
77 77
 		if ($resql)
78 78
 		{
79 79
 			$num = $this->db->num_rows($resql);
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 			while ($i < $num)
83 83
 			{
84 84
 				$objp = $this->db->fetch_object($resql);
85
-				if (! $mode) $key=$objp->id;
86
-				else $key=$objp->code;
85
+				if (!$mode) $key = $objp->id;
86
+				else $key = $objp->code;
87 87
 				if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
88 88
 				else $effs[$key] = $objp->libelle;
89
-				if ($effs[$key]=='-') $effs[$key]='';
89
+				if ($effs[$key] == '-') $effs[$key] = '';
90 90
 				$i++;
91 91
 			}
92 92
 			$this->db->free($resql);
@@ -103,18 +103,18 @@  discard block
 block discarded – undo
103 103
 	 *	@param  string	$filter     Add a SQL filter to select
104 104
 	 *  @return array				Array of types d'effectifs
105 105
 	 */
106
-	function effectif_array($mode=0, $filter='')
106
+	function effectif_array($mode = 0, $filter = '')
107 107
 	{
108 108
         // phpcs:enable
109 109
 		$effs = array();
110 110
 
111 111
 		$sql = "SELECT id, code, libelle";
112 112
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
113
-		$sql.= " WHERE active = 1";
114
-		if ($filter) $sql.=" ".$filter;
113
+		$sql .= " WHERE active = 1";
114
+		if ($filter) $sql .= " ".$filter;
115 115
 		$sql .= " ORDER BY id ASC";
116 116
 		dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
117
-		$resql=$this->db->query($sql);
117
+		$resql = $this->db->query($sql);
118 118
 		if ($resql)
119 119
 		{
120 120
 			$num = $this->db->num_rows($resql);
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
 			while ($i < $num)
124 124
 			{
125 125
 				$objp = $this->db->fetch_object($resql);
126
-				if (! $mode) $key=$objp->id;
127
-				else $key=$objp->code;
126
+				if (!$mode) $key = $objp->id;
127
+				else $key = $objp->code;
128 128
 
129
-				$effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
129
+				$effs[$key] = $objp->libelle != '-' ? $objp->libelle : '';
130 130
 				$i++;
131 131
 			}
132 132
 			$this->db->free($resql);
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 	 *	@param	int		$empty			Add empty value in list
146 146
 	 *	@return	void
147 147
 	 */
148
-	function form_prospect_level($page, $selected='', $htmlname='prospect_level_id', $empty=0)
148
+	function form_prospect_level($page, $selected = '', $htmlname = 'prospect_level_id', $empty = 0)
149 149
 	{
150 150
         // phpcs:enable
151 151
 		global $user, $langs;
@@ -154,11 +154,11 @@  discard block
 block discarded – undo
154 154
 		print '<input type="hidden" name="action" value="setprospectlevel">';
155 155
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
156 156
 
157
-		dol_syslog(get_class($this).'::form_prospect_level',LOG_DEBUG);
157
+		dol_syslog(get_class($this).'::form_prospect_level', LOG_DEBUG);
158 158
 		$sql = "SELECT code, label";
159
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
160
-		$sql.= " WHERE active > 0";
161
-		$sql.= " ORDER BY sortorder";
159
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
160
+		$sql .= " WHERE active > 0";
161
+		$sql .= " ORDER BY sortorder";
162 162
 		$resql = $this->db->query($sql);
163 163
 		if ($resql)
164 164
 		{
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 			print Form::selectarray($htmlname, $options, $selected);
182 182
 		}
183 183
 		else dol_print_error($this->db);
184
-		if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
184
+		if (!empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
185 185
 		print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186 186
 		print '</form>';
187 187
 	}
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
 	 *   @param     string	$htmlname			Id of department
200 200
 	 *   @return	void
201 201
 	 */
202
-	function select_departement($selected='',$country_codeid=0, $htmlname='state_id')
202
+	function select_departement($selected = '', $country_codeid = 0, $htmlname = 'state_id')
203 203
 	{
204 204
         // phpcs:enable
205
-		print $this->select_state($selected,$country_codeid, $htmlname);
205
+		print $this->select_state($selected, $country_codeid, $htmlname);
206 206
 	}
207 207
 
208 208
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -219,91 +219,91 @@  discard block
 block discarded – undo
219 219
 	 * 	  @return	string						String with HTML select
220 220
 	 *    @see select_country
221 221
 	 */
222
-	function select_state($selected='',$country_codeid=0, $htmlname='state_id')
222
+	function select_state($selected = '', $country_codeid = 0, $htmlname = 'state_id')
223 223
 	{
224 224
         // phpcs:enable
225
-		global $conf,$langs,$user;
225
+		global $conf, $langs, $user;
226 226
 
227
-		dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid,LOG_DEBUG);
227
+		dol_syslog(get_class($this)."::select_departement selected=".$selected.", country_codeid=".$country_codeid, LOG_DEBUG);
228 228
 
229 229
 		$langs->load("dict");
230 230
 
231
-		$out='';
231
+		$out = '';
232 232
 
233 233
 		// Serch departements/cantons/province active d'une region et pays actif
234 234
 		$sql = "SELECT d.rowid, d.code_departement as code, d.nom as name, d.active, c.label as country, c.code as country_code, r.nom as region_name FROM";
235
-		$sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
235
+		$sql .= " ".MAIN_DB_PREFIX."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
236 236
 		$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
237 237
 		$sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
238 238
 		if ($country_codeid && is_numeric($country_codeid))   $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
239
-		if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
239
+		if ($country_codeid && !is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
240 240
 		$sql .= " ORDER BY c.code, d.code_departement";
241 241
 
242
-		$result=$this->db->query($sql);
242
+		$result = $this->db->query($sql);
243 243
 		if ($result)
244 244
 		{
245
-			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
246
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
245
+			if (!empty($htmlname)) $out .= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
246
+			if ($country_codeid) $out .= '<option value="0">&nbsp;</option>';
247 247
 			$num = $this->db->num_rows($result);
248 248
 			$i = 0;
249
-			dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
249
+			dol_syslog(get_class($this)."::select_departement num=".$num, LOG_DEBUG);
250 250
 			if ($num)
251 251
 			{
252
-				$country='';
252
+				$country = '';
253 253
 				while ($i < $num)
254 254
 				{
255 255
 					$obj = $this->db->fetch_object($result);
256 256
 					if ($obj->code == '0')		// Le code peut etre une chaine
257 257
 					{
258
-						$out.= '<option value="0">&nbsp;</option>';
258
+						$out .= '<option value="0">&nbsp;</option>';
259 259
 					}
260 260
 					else {
261
-						if (! $country || $country != $obj->country)
261
+						if (!$country || $country != $obj->country)
262 262
 						{
263 263
 							// Affiche la rupture si on est en mode liste multipays
264
-							if (! $country_codeid && $obj->country_code)
264
+							if (!$country_codeid && $obj->country_code)
265 265
 							{
266
-								$out.= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
267
-								$country=$obj->country;
266
+								$out .= '<option value="-1" disabled>----- '.$obj->country." -----</option>\n";
267
+								$country = $obj->country;
268 268
 							}
269 269
 						}
270 270
 
271
-						if ((! empty($selected) && $selected == $obj->rowid)
272
-						 || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
271
+						if ((!empty($selected) && $selected == $obj->rowid)
272
+						 || (empty($selected) && !empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
273 273
 						{
274
-							$out.= '<option value="'.$obj->rowid.'" selected>';
274
+							$out .= '<option value="'.$obj->rowid.'" selected>';
275 275
 						}
276 276
 						else
277 277
 						{
278
-							$out.= '<option value="'.$obj->rowid.'">';
278
+							$out .= '<option value="'.$obj->rowid.'">';
279 279
 						}
280 280
 
281 281
 						// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
282 282
 						if (!empty($conf->global->MAIN_SHOW_STATE_CODE) &&
283 283
 						($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
284
-							if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
285
-								$out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
284
+							if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
285
+								$out .= $obj->region_name.' - '.$obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
286 286
 							}
287 287
 							else {
288
-								$out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
288
+								$out .= $obj->code.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
289 289
 							}
290 290
 						}
291 291
 						else {
292
-							if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
293
-								$out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
292
+							if (!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
293
+								$out .= $obj->region_name.' - '.($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
294 294
 							}
295 295
 							else {
296
-								$out.= ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
296
+								$out .= ($langs->trans($obj->code) != $obj->code ? $langs->trans($obj->code) : ($obj->name != '-' ? $obj->name : ''));
297 297
 							}
298 298
 						}
299 299
 
300
-						$out.= '</option>';
300
+						$out .= '</option>';
301 301
 					}
302 302
 					$i++;
303 303
 				}
304 304
 			}
305
-			if (! empty($htmlname)) $out.= '</select>';
306
-			if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
305
+			if (!empty($htmlname)) $out .= '</select>';
306
+			if (!empty($htmlname) && $user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
307 307
 		}
308 308
 		else
309 309
 		{
@@ -311,9 +311,9 @@  discard block
 block discarded – undo
311 311
 		}
312 312
 
313 313
 		// Make select dynamic
314
-		if (! empty($htmlname))
314
+		if (!empty($htmlname))
315 315
 		{
316
-			include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
316
+			include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
317 317
 			$out .= ajax_combobox($htmlname);
318 318
 		}
319 319
 
@@ -332,19 +332,19 @@  discard block
 block discarded – undo
332 332
 	 *   @param		string		$htmlname		Name of HTML select field
333 333
 	 *   @return	void
334 334
 	 */
335
-	function select_region($selected='',$htmlname='region_id')
335
+	function select_region($selected = '', $htmlname = 'region_id')
336 336
 	{
337 337
         // phpcs:enable
338
-		global $conf,$langs;
338
+		global $conf, $langs;
339 339
 		$langs->load("dict");
340 340
 
341 341
 		$sql = "SELECT r.rowid, r.code_region as code, r.nom as label, r.active, c.code as country_code, c.label as country";
342
-		$sql.= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
343
-		$sql.= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
344
-		$sql.= " ORDER BY c.code, c.label ASC";
342
+		$sql .= " FROM ".MAIN_DB_PREFIX."c_regions as r, ".MAIN_DB_PREFIX."c_country as c";
343
+		$sql .= " WHERE r.fk_pays=c.rowid AND r.active = 1 and c.active = 1";
344
+		$sql .= " ORDER BY c.code, c.label ASC";
345 345
 
346 346
 		dol_syslog(get_class($this)."::select_region", LOG_DEBUG);
347
-		$resql=$this->db->query($sql);
347
+		$resql = $this->db->query($sql);
348 348
 		if ($resql)
349 349
 		{
350 350
 			print '<select class="flat" name="'.$htmlname.'">';
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 			$i = 0;
353 353
 			if ($num)
354 354
 			{
355
-				$country='';
355
+				$country = '';
356 356
 				while ($i < $num)
357 357
 				{
358 358
 					$obj = $this->db->fetch_object($resql);
@@ -363,10 +363,10 @@  discard block
 block discarded – undo
363 363
 						if ($country == '' || $country != $obj->country)
364 364
 						{
365 365
 							// Show break
366
-							$key=$langs->trans("Country".strtoupper($obj->country_code));
367
-							$valuetoshow=($key != "Country".strtoupper($obj->country_code))?$obj->country_code." - ".$key:$obj->country;
366
+							$key = $langs->trans("Country".strtoupper($obj->country_code));
367
+							$valuetoshow = ($key != "Country".strtoupper($obj->country_code)) ? $obj->country_code." - ".$key : $obj->country;
368 368
 							print '<option value="-1" disabled>----- '.$valuetoshow." -----</option>\n";
369
-							$country=$obj->country;
369
+							$country = $obj->country;
370 370
 						}
371 371
 
372 372
 						if ($selected > 0 && $selected == $obj->code)
@@ -398,23 +398,23 @@  discard block
 block discarded – undo
398 398
 	 *  @param  string  $morecss        Add more css on SELECT element
399 399
 	 *  @return	string					String with HTML select
400 400
 	 */
401
-	function select_civility($selected='',$htmlname='civility_id',$morecss='maxwidth100')
401
+	function select_civility($selected = '', $htmlname = 'civility_id', $morecss = 'maxwidth100')
402 402
 	{
403 403
         // phpcs:enable
404
-		global $conf,$langs,$user;
404
+		global $conf, $langs, $user;
405 405
 		$langs->load("dict");
406 406
 
407
-		$out='';
407
+		$out = '';
408 408
 
409 409
 		$sql = "SELECT rowid, code, label, active FROM ".MAIN_DB_PREFIX."c_civility";
410
-		$sql.= " WHERE active = 1";
410
+		$sql .= " WHERE active = 1";
411 411
 
412 412
 		dol_syslog("Form::select_civility", LOG_DEBUG);
413
-		$resql=$this->db->query($sql);
413
+		$resql = $this->db->query($sql);
414 414
 		if ($resql)
415 415
 		{
416
-			$out.= '<select class="flat'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
417
-			$out.= '<option value="">&nbsp;</option>';
416
+			$out .= '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
417
+			$out .= '<option value="">&nbsp;</option>';
418 418
 			$num = $this->db->num_rows($resql);
419 419
 			$i = 0;
420 420
 			if ($num)
@@ -424,20 +424,20 @@  discard block
 block discarded – undo
424 424
 					$obj = $this->db->fetch_object($resql);
425 425
 					if ($selected == $obj->code)
426 426
 					{
427
-						$out.= '<option value="'.$obj->code.'" selected>';
427
+						$out .= '<option value="'.$obj->code.'" selected>';
428 428
 					}
429 429
 					else
430 430
 					{
431
-						$out.= '<option value="'.$obj->code.'">';
431
+						$out .= '<option value="'.$obj->code.'">';
432 432
 					}
433 433
 					// Si traduction existe, on l'utilise, sinon on prend le libelle par defaut
434
-					$out.= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label!='-'?$obj->label:''));
435
-					$out.= '</option>';
434
+					$out .= ($langs->trans("Civility".$obj->code) != "Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->label != '-' ? $obj->label : ''));
435
+					$out .= '</option>';
436 436
 					$i++;
437 437
 				}
438 438
 			}
439
-			$out.= '</select>';
440
-			if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
439
+			$out .= '</select>';
440
+			if ($user->admin) $out .= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
441 441
 		}
442 442
 		else
443 443
 		{
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
 	 *    @deprecated Use print xxx->select_juridicalstatus instead
460 460
 	 *    @see select_juridicalstatus()
461 461
 	 */
462
-	function select_forme_juridique($selected='', $country_codeid=0, $filter='')
462
+	function select_forme_juridique($selected = '', $country_codeid = 0, $filter = '')
463 463
 	{
464 464
         // phpcs:enable
465 465
 		print $this->select_juridicalstatus($selected, $country_codeid, $filter);
@@ -476,13 +476,13 @@  discard block
 block discarded – undo
476 476
      *    @param	string		$htmlname			HTML name of select
477 477
      *    @return	string							String with HTML select
478 478
 	 */
479
-	function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code')
479
+	function select_juridicalstatus($selected = '', $country_codeid = 0, $filter = '', $htmlname = 'forme_juridique_code')
480 480
 	{
481 481
         // phpcs:enable
482
-		global $conf,$langs,$user;
482
+		global $conf, $langs, $user;
483 483
 		$langs->load("dict");
484 484
 
485
-		$out='';
485
+		$out = '';
486 486
 
487 487
 		// On recherche les formes juridiques actives des pays actifs
488 488
 		$sql  = "SELECT f.rowid, f.code as code , f.libelle as label, f.active, c.label as country, c.code as country_code";
@@ -494,70 +494,70 @@  discard block
 block discarded – undo
494 494
 		$sql .= " ORDER BY c.code";
495 495
 
496 496
 		dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
497
-		$resql=$this->db->query($sql);
497
+		$resql = $this->db->query($sql);
498 498
 		if ($resql)
499 499
 		{
500
-			$out.= '<div id="particulier2" class="visible">';
501
-			$out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
502
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';	// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
500
+			$out .= '<div id="particulier2" class="visible">';
501
+			$out .= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
502
+			if ($country_codeid) $out .= '<option value="0">&nbsp;</option>'; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
503 503
 
504 504
 			$num = $this->db->num_rows($resql);
505 505
 			if ($num)
506 506
 			{
507 507
 				$i = 0;
508
-				$country=''; $arraydata=array();
508
+				$country = ''; $arraydata = array();
509 509
 				while ($i < $num)
510 510
 				{
511 511
 					$obj = $this->db->fetch_object($resql);
512 512
 
513 513
 					if ($obj->code)		// We exclude empty line, we will add it later
514 514
 					{
515
-						$labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
516
-						$labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:''));	// $obj->label is already in output charset (converted by database driver)
517
-						$arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
515
+						$labelcountry = (($langs->trans("Country".$obj->country_code) != "Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
516
+						$labeljs = (($langs->trans("JuridicalStatus".$obj->code) != "JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label != '-' ? $obj->label : '')); // $obj->label is already in output charset (converted by database driver)
517
+						$arraydata[$obj->code] = array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
518 518
 					}
519 519
 					$i++;
520 520
 				}
521 521
 
522
-				$arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
522
+				$arraydata = dol_sort_array($arraydata, 'label_sort', 'ASC');
523 523
 				if (empty($country_codeid))	// Introduce empty value (if $country_codeid not empty, empty value was already added)
524 524
 				{
525
-					$arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
525
+					$arraydata[0] = array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
526 526
 				}
527 527
 
528
-				foreach($arraydata as $key => $val)
528
+				foreach ($arraydata as $key => $val)
529 529
 				{
530
-					if (! $country || $country != $val['country'])
530
+					if (!$country || $country != $val['country'])
531 531
 					{
532 532
 						// Show break when we are in multi country mode
533 533
 						if (empty($country_codeid) && $val['country_code'])
534 534
 						{
535
-							$out.= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
536
-							$country=$val['country'];
535
+							$out .= '<option value="0" disabled class="selectoptiondisabledwhite">----- '.$val['country']." -----</option>\n";
536
+							$country = $val['country'];
537 537
 						}
538 538
 					}
539 539
 
540 540
 					if ($selected > 0 && $selected == $val['code'])
541 541
 					{
542
-						$out.= '<option value="'.$val['code'].'" selected>';
542
+						$out .= '<option value="'.$val['code'].'" selected>';
543 543
 					}
544 544
 					else
545 545
 					{
546
-						$out.= '<option value="'.$val['code'].'">';
546
+						$out .= '<option value="'.$val['code'].'">';
547 547
 					}
548 548
 					// If translation exists, we use it, otherwise we use default label in database
549
-					$out.= $val['label'];
550
-					$out.= '</option>';
549
+					$out .= $val['label'];
550
+					$out .= '</option>';
551 551
 				}
552 552
 			}
553
-			$out.= '</select>';
554
-			if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
553
+			$out .= '</select>';
554
+			if ($user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
555 555
 
556 556
 		    // Make select dynamic
557
-        	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
557
+        	include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php';
558 558
 	        $out .= ajax_combobox($htmlname);
559 559
 
560
-			$out.= '</div>';
560
+			$out .= '</div>';
561 561
 		}
562 562
 		else
563 563
 		{
@@ -581,19 +581,19 @@  discard block
 block discarded – undo
581 581
      *  @param	string		$morecss		More CSS on select component
582 582
 	 * 	@return int 						The selected third party ID
583 583
 	 */
584
-	function selectCompaniesForNewContact($object, $var_id, $selected='', $htmlname='newcompany', $limitto='', $forceid=0, $moreparam='', $morecss='')
584
+	function selectCompaniesForNewContact($object, $var_id, $selected = '', $htmlname = 'newcompany', $limitto = '', $forceid = 0, $moreparam = '', $morecss = '')
585 585
 	{
586 586
 		global $conf, $langs;
587 587
 
588
-		if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
588
+		if (!empty($conf->use_javascript_ajax) && !empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT))
589 589
 		{
590 590
 			// Use Ajax search
591
-			$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT)?$conf->global->COMPANY_USE_SEARCH_TO_SELECT:2);
591
+			$minLength = (is_numeric($conf->global->COMPANY_USE_SEARCH_TO_SELECT) ? $conf->global->COMPANY_USE_SEARCH_TO_SELECT : 2);
592 592
 
593
-			$socid=0; $name='';
593
+			$socid = 0; $name = '';
594 594
 			if ($selected > 0)
595 595
 			{
596
-				$tmpthirdparty=new Societe($this->db);
596
+				$tmpthirdparty = new Societe($this->db);
597 597
 				$result = $tmpthirdparty->fetch($selected);
598 598
 				if ($result > 0)
599 599
 				{
@@ -603,13 +603,13 @@  discard block
 block discarded – undo
603 603
 			}
604 604
 
605 605
 
606
-			$events=array();
606
+			$events = array();
607 607
 			// Add an entry 'method' to say 'yes, we must execute url with param action = method';
608 608
 			// Add an entry 'url' to say which url to execute
609 609
 			// Add an entry htmlname to say which element we must change once url is called
610 610
 			// Add entry params => array('cssid' => 'attr') to say to remov or add attribute attr if answer of url return  0 or >0 lines
611 611
 			// To refresh contacts list on thirdparty list change
612
-			$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
612
+			$events[] = array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php', 1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
613 613
 
614 614
 			if (count($events))	// If there is some ajax events to run once selection is done, we add code here to run events
615 615
 			{
@@ -665,29 +665,29 @@  discard block
 block discarded – undo
665 665
 
666 666
 			print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
667 667
 			print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
668
-			print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
668
+			print ajax_autocompleter(($socid ? $socid : -1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
669 669
 			return $socid;
670 670
 		}
671 671
 		else
672 672
 		{
673 673
 			// Search to list thirdparties
674 674
 			$sql = "SELECT s.rowid, s.nom as name FROM";
675
-			$sql.= " ".MAIN_DB_PREFIX."societe as s";
676
-			$sql.= " WHERE s.entity IN (".getEntity('societe').")";
675
+			$sql .= " ".MAIN_DB_PREFIX."societe as s";
676
+			$sql .= " WHERE s.entity IN (".getEntity('societe').")";
677 677
 			// For ajax search we limit here. For combo list, we limit later
678 678
 			if (is_array($limitto) && count($limitto))
679 679
 			{
680
-				$sql.= " AND s.rowid IN (".join(',',$limitto).")";
680
+				$sql .= " AND s.rowid IN (".join(',', $limitto).")";
681 681
 			}
682
-			$sql.= " ORDER BY s.nom ASC";
682
+			$sql .= " ORDER BY s.nom ASC";
683 683
 
684 684
 			$resql = $this->db->query($sql);
685 685
 			if ($resql)
686 686
 			{
687
-				print '<select class="flat'.($morecss?' '.$morecss:'').'" id="'.$htmlname.'" name="'.$htmlname.'"';
687
+				print '<select class="flat'.($morecss ? ' '.$morecss : '').'" id="'.$htmlname.'" name="'.$htmlname.'"';
688 688
 				if ($conf->use_javascript_ajax)
689 689
 				{
690
-					$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid>0?$forceid:$object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
690
+					$javaScript = "window.location='".$_SERVER['PHP_SELF']."?".$var_id."=".($forceid > 0 ? $forceid : $object->id).$moreparam."&".$htmlname."=' + form.".$htmlname.".options[form.".$htmlname.".selectedIndex].value;";
691 691
 					print ' onChange="'.$javaScript.'"';
692 692
 				}
693 693
 				print '>';
@@ -699,22 +699,22 @@  discard block
 block discarded – undo
699 699
 					{
700 700
 						$obj = $this->db->fetch_object($resql);
701 701
 						if ($i == 0) $firstCompany = $obj->rowid;
702
-						$disabled=0;
703
-						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
702
+						$disabled = 0;
703
+						if (is_array($limitto) && count($limitto) && !in_array($obj->rowid, $limitto)) $disabled = 1;
704 704
 						if ($selected > 0 && $selected == $obj->rowid)
705 705
 						{
706 706
 							print '<option value="'.$obj->rowid.'"';
707 707
 							if ($disabled) print ' disabled';
708
-							print ' selected>'.dol_trunc($obj->name,24).'</option>';
708
+							print ' selected>'.dol_trunc($obj->name, 24).'</option>';
709 709
 							$firstCompany = $obj->rowid;
710 710
 						}
711 711
 						else
712 712
 						{
713 713
 							print '<option value="'.$obj->rowid.'"';
714 714
 							if ($disabled) print ' disabled';
715
-							print '>'.dol_trunc($obj->name,24).'</option>';
715
+							print '>'.dol_trunc($obj->name, 24).'</option>';
716 716
 						}
717
-						$i ++;
717
+						$i++;
718 718
 					}
719 719
 				}
720 720
 				print "</select>\n";
@@ -740,23 +740,23 @@  discard block
 block discarded – undo
740 740
      *  @param  string      $morecss        Add more css to select component
741 741
      *  @return	void
742 742
      */
743
-	function selectTypeContact($object, $selected, $htmlname = 'type', $source='internal', $sortorder='position', $showempty=0, $morecss='')
743
+	function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '')
744 744
 	{
745 745
 	    global $user, $langs;
746 746
 
747 747
 		if (is_object($object) && method_exists($object, 'liste_type_contact'))
748 748
 		{
749 749
 			$lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
750
-			print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
750
+			print '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
751 751
 			if ($showempty) print '<option value="0"></option>';
752
-			foreach($lesTypes as $key=>$value)
752
+			foreach ($lesTypes as $key=>$value)
753 753
 			{
754 754
 				print '<option value="'.$key.'"';
755 755
 				if ($key == $selected) print ' selected';
756 756
 				print '>'.$value.'</option>';
757 757
 			}
758 758
 			print "</select>";
759
-			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
759
+			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
760 760
 			print "\n";
761 761
 		}
762 762
 	}
@@ -774,22 +774,22 @@  discard block
 block discarded – undo
774 774
 	 *    @param    string      $morecss                More css
775 775
 	 *    @return	string
776 776
 	 */
777
-	function select_ziptown($selected='', $htmlname='zipcode', $fields='', $fieldsize=0, $disableautocomplete=0, $moreattrib='',$morecss='')
777
+	function select_ziptown($selected = '', $htmlname = 'zipcode', $fields = '', $fieldsize = 0, $disableautocomplete = 0, $moreattrib = '', $morecss = '')
778 778
 	{
779 779
         // phpcs:enable
780 780
 		global $conf;
781 781
 
782
-		$out='';
782
+		$out = '';
783 783
 
784
-		$size='';
785
-		if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
784
+		$size = '';
785
+		if (!empty($fieldsize)) $size = 'size="'.$fieldsize.'"';
786 786
 
787 787
 		if ($conf->use_javascript_ajax && empty($disableautocomplete))
788 788
 		{
789
-			$out.= ajax_multiautocompleter($htmlname,$fields,DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
790
-			$moreattrib.=' autocomplete="off"';
789
+			$out .= ajax_multiautocompleter($htmlname, $fields, DOL_URL_ROOT.'/core/ajax/ziptown.php')."\n";
790
+			$moreattrib .= ' autocomplete="off"';
791 791
 		}
792
-		$out.= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss?' '.$morecss:'').'" type="text"'.($moreattrib?' '.$moreattrib:'').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
792
+		$out .= '<input id="'.$htmlname.'" class="maxwidthonsmartphone'.($morecss ? ' '.$morecss : '').'" type="text"'.($moreattrib ? ' '.$moreattrib : '').' name="'.$htmlname.'" '.$size.' value="'.$selected.'">'."\n";
793 793
 
794 794
 		return $out;
795 795
 	}
@@ -805,43 +805,43 @@  discard block
 block discarded – undo
805 805
      *  @param  string  $morecss        More css
806 806
      *  @return	string					HTML string with prof id
807 807
      */
808
-    function get_input_id_prof($idprof,$htmlname,$preselected,$country_code,$morecss='maxwidth100onsmartphone quatrevingtpercent')
808
+    function get_input_id_prof($idprof, $htmlname, $preselected, $country_code, $morecss = 'maxwidth100onsmartphone quatrevingtpercent')
809 809
     {
810 810
         // phpcs:enable
811
-        global $conf,$langs;
811
+        global $conf, $langs;
812 812
 
813
-        $formlength=0;
813
+        $formlength = 0;
814 814
         if (empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
815 815
         	if ($country_code == 'FR')
816 816
         	{
817 817
         		if (isset($idprof)) {
818
-        			if ($idprof==1) $formlength=9;
819
-        			else if ($idprof==2) $formlength=14;
820
-        			else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
821
-        			else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
818
+        			if ($idprof == 1) $formlength = 9;
819
+        			else if ($idprof == 2) $formlength = 14;
820
+        			else if ($idprof == 3) $formlength = 5; // 4 chiffres et 1 lettre depuis janvier
821
+        			else if ($idprof == 4) $formlength = 32; // No maximum as we need to include a town name in this id
822 822
         		}
823 823
         	}
824 824
         	else if ($country_code == 'ES')
825 825
         	{
826
-        		if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
827
-        		if ($idprof==2) $formlength=12; //NASS 12 digits without /
828
-        		if ($idprof==3) $formlength=5;  //CNAE 5 digits
829
-        		if ($idprof==4) $formlength=32; //depend of college
826
+        		if ($idprof == 1) $formlength = 9; //CIF/NIF/NIE 9 digits
827
+        		if ($idprof == 2) $formlength = 12; //NASS 12 digits without /
828
+        		if ($idprof == 3) $formlength = 5; //CNAE 5 digits
829
+        		if ($idprof == 4) $formlength = 32; //depend of college
830 830
         	}
831 831
         }
832 832
 
833
-        $selected=$preselected;
834
-        if (! $selected && isset($idprof)) {
835
-        	if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
836
-        	else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
837
-        	else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
838
-        	else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
833
+        $selected = $preselected;
834
+        if (!$selected && isset($idprof)) {
835
+        	if ($idprof == 1 && !empty($this->idprof1)) $selected = $this->idprof1;
836
+        	else if ($idprof == 2 && !empty($this->idprof2)) $selected = $this->idprof2;
837
+        	else if ($idprof == 3 && !empty($this->idprof3)) $selected = $this->idprof3;
838
+        	else if ($idprof == 4 && !empty($this->idprof4)) $selected = $this->idprof4;
839 839
         }
840 840
 
841
-        $maxlength=$formlength;
842
-        if (empty($formlength)) { $formlength=24; $maxlength=128; }
841
+        $maxlength = $formlength;
842
+        if (empty($formlength)) { $formlength = 24; $maxlength = 128; }
843 843
 
844
-        $out = '<input type="text" '.($morecss?'class="'.$morecss.'" ':'').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
844
+        $out = '<input type="text" '.($morecss ? 'class="'.$morecss.'" ' : '').'name="'.$htmlname.'" id="'.$htmlname.'" maxlength="'.$maxlength.'" value="'.$selected.'">';
845 845
 
846 846
         return $out;
847 847
     }
@@ -858,19 +858,19 @@  discard block
 block discarded – undo
858 858
     function select_localtax($local, $selected, $htmlname)
859 859
     {
860 860
         // phpcs:enable
861
-        $tax=get_localtax_by_third($local);
861
+        $tax = get_localtax_by_third($local);
862 862
 
863 863
         $num = $this->db->num_rows($tax);
864 864
         $i = 0;
865 865
     	if ($num)
866 866
     	{
867
-    		$valors=explode(":", $tax);
867
+    		$valors = explode(":", $tax);
868 868
 
869 869
     		if (count($valors) > 1)
870 870
     		{
871 871
     			//montar select
872 872
     			print '<select class="flat" name="'.$htmlname.'" id="'.$htmlname.'">';
873
-    			while ($i <= (count($valors))-1)
873
+    			while ($i <= (count($valors)) - 1)
874 874
     			{
875 875
     				if ($selected == $valors[$i])
876 876
     				{
Please login to merge, or discard this patch.
Braces   +153 added lines, -81 removed lines patch added patch discarded remove patch
@@ -70,7 +70,9 @@  discard block
 block discarded – undo
70 70
 		$sql = "SELECT id, code, libelle";
71 71
 		$sql.= " FROM ".MAIN_DB_PREFIX."c_typent";
72 72
 		$sql.= " WHERE active = 1 AND (fk_country IS NULL OR fk_country = ".(empty($mysoc->country_id)?'0':$mysoc->country_id).")";
73
-		if ($filter) $sql.=" ".$filter;
73
+		if ($filter) {
74
+		    $sql.=" ".$filter;
75
+		}
74 76
 		$sql.= " ORDER by position, id";
75 77
 		dol_syslog(get_class($this).'::typent_array', LOG_DEBUG);
76 78
 		$resql=$this->db->query($sql);
@@ -82,11 +84,19 @@  discard block
 block discarded – undo
82 84
 			while ($i < $num)
83 85
 			{
84 86
 				$objp = $this->db->fetch_object($resql);
85
-				if (! $mode) $key=$objp->id;
86
-				else $key=$objp->code;
87
-				if ($langs->trans($objp->code) != $objp->code) $effs[$key] = $langs->trans($objp->code);
88
-				else $effs[$key] = $objp->libelle;
89
-				if ($effs[$key]=='-') $effs[$key]='';
87
+				if (! $mode) {
88
+				    $key=$objp->id;
89
+				} else {
90
+				    $key=$objp->code;
91
+				}
92
+				if ($langs->trans($objp->code) != $objp->code) {
93
+				    $effs[$key] = $langs->trans($objp->code);
94
+				} else {
95
+				    $effs[$key] = $objp->libelle;
96
+				}
97
+				if ($effs[$key]=='-') {
98
+				    $effs[$key]='';
99
+				}
90 100
 				$i++;
91 101
 			}
92 102
 			$this->db->free($resql);
@@ -111,7 +121,9 @@  discard block
 block discarded – undo
111 121
 		$sql = "SELECT id, code, libelle";
112 122
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_effectif";
113 123
 		$sql.= " WHERE active = 1";
114
-		if ($filter) $sql.=" ".$filter;
124
+		if ($filter) {
125
+		    $sql.=" ".$filter;
126
+		}
115 127
 		$sql .= " ORDER BY id ASC";
116 128
 		dol_syslog(get_class($this).'::effectif_array', LOG_DEBUG);
117 129
 		$resql=$this->db->query($sql);
@@ -123,8 +135,11 @@  discard block
 block discarded – undo
123 135
 			while ($i < $num)
124 136
 			{
125 137
 				$objp = $this->db->fetch_object($resql);
126
-				if (! $mode) $key=$objp->id;
127
-				else $key=$objp->code;
138
+				if (! $mode) {
139
+				    $key=$objp->id;
140
+				} else {
141
+				    $key=$objp->code;
142
+				}
128 143
 
129 144
 				$effs[$key] = $objp->libelle!='-'?$objp->libelle:'';
130 145
 				$i++;
@@ -179,9 +194,12 @@  discard block
 block discarded – undo
179 194
 			}
180 195
 
181 196
 			print Form::selectarray($htmlname, $options, $selected);
197
+		} else {
198
+		    dol_print_error($this->db);
199
+		}
200
+		if (! empty($htmlname) && $user->admin) {
201
+		    print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
182 202
 		}
183
-		else dol_print_error($this->db);
184
-		if (! empty($htmlname) && $user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
185 203
 		print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
186 204
 		print '</form>';
187 205
 	}
@@ -235,15 +253,23 @@  discard block
 block discarded – undo
235 253
 		$sql .= " ".MAIN_DB_PREFIX ."c_departements as d, ".MAIN_DB_PREFIX."c_regions as r,".MAIN_DB_PREFIX."c_country as c";
236 254
 		$sql .= " WHERE d.fk_region=r.code_region and r.fk_pays=c.rowid";
237 255
 		$sql .= " AND d.active = 1 AND r.active = 1 AND c.active = 1";
238
-		if ($country_codeid && is_numeric($country_codeid))   $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
239
-		if ($country_codeid && ! is_numeric($country_codeid)) $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
256
+		if ($country_codeid && is_numeric($country_codeid)) {
257
+		    $sql .= " AND c.rowid = '".$this->db->escape($country_codeid)."'";
258
+		}
259
+		if ($country_codeid && ! is_numeric($country_codeid)) {
260
+		    $sql .= " AND c.code = '".$this->db->escape($country_codeid)."'";
261
+		}
240 262
 		$sql .= " ORDER BY c.code, d.code_departement";
241 263
 
242 264
 		$result=$this->db->query($sql);
243 265
 		if ($result)
244 266
 		{
245
-			if (!empty($htmlname)) $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
246
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';
267
+			if (!empty($htmlname)) {
268
+			    $out.= '<select id="'.$htmlname.'" class="flat maxwidth200onsmartphone minwidth300" name="'.$htmlname.'">';
269
+			}
270
+			if ($country_codeid) {
271
+			    $out.= '<option value="0">&nbsp;</option>';
272
+			}
247 273
 			$num = $this->db->num_rows($result);
248 274
 			$i = 0;
249 275
 			dol_syslog(get_class($this)."::select_departement num=".$num,LOG_DEBUG);
@@ -253,11 +279,12 @@  discard block
 block discarded – undo
253 279
 				while ($i < $num)
254 280
 				{
255 281
 					$obj = $this->db->fetch_object($result);
256
-					if ($obj->code == '0')		// Le code peut etre une chaine
282
+					if ($obj->code == '0') {
283
+					    // Le code peut etre une chaine
257 284
 					{
258 285
 						$out.= '<option value="0">&nbsp;</option>';
259 286
 					}
260
-					else {
287
+					} else {
261 288
 						if (! $country || $country != $obj->country)
262 289
 						{
263 290
 							// Affiche la rupture si on est en mode liste multipays
@@ -272,8 +299,7 @@  discard block
 block discarded – undo
272 299
 						 || (empty($selected) && ! empty($conf->global->MAIN_FORCE_DEFAULT_STATE_ID) && $conf->global->MAIN_FORCE_DEFAULT_STATE_ID == $obj->rowid))
273 300
 						{
274 301
 							$out.= '<option value="'.$obj->rowid.'" selected>';
275
-						}
276
-						else
302
+						} else
277 303
 						{
278 304
 							$out.= '<option value="'.$obj->rowid.'">';
279 305
 						}
@@ -283,16 +309,13 @@  discard block
 block discarded – undo
283 309
 						($conf->global->MAIN_SHOW_STATE_CODE == 1 || $conf->global->MAIN_SHOW_STATE_CODE == 2 || $conf->global->MAIN_SHOW_STATE_CODE === 'all')) {
284 310
 							if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
285 311
 								$out.= $obj->region_name . ' - ' . $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
286
-							}
287
-							else {
312
+							} else {
288 313
 								$out.= $obj->code . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
289 314
 							}
290
-						}
291
-						else {
315
+						} else {
292 316
 							if(!empty($conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT) && $conf->global->MAIN_SHOW_REGION_IN_STATE_SELECT == 1) {
293 317
 								$out.= $obj->region_name . ' - ' . ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
294
-							}
295
-							else {
318
+							} else {
296 319
 								$out.= ($langs->trans($obj->code)!=$obj->code?$langs->trans($obj->code):($obj->name!='-'?$obj->name:''));
297 320
 							}
298 321
 						}
@@ -302,10 +325,13 @@  discard block
 block discarded – undo
302 325
 					$i++;
303 326
 				}
304 327
 			}
305
-			if (! empty($htmlname)) $out.= '</select>';
306
-			if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
307
-		}
308
-		else
328
+			if (! empty($htmlname)) {
329
+			    $out.= '</select>';
330
+			}
331
+			if (! empty($htmlname) && $user->admin) {
332
+			    $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
333
+			}
334
+		} else
309 335
 		{
310 336
 			dol_print_error($this->db);
311 337
 		}
@@ -358,8 +384,7 @@  discard block
 block discarded – undo
358 384
 					$obj = $this->db->fetch_object($resql);
359 385
 					if ($obj->code == 0) {
360 386
 						print '<option value="0">&nbsp;</option>';
361
-					}
362
-					else {
387
+					} else {
363 388
 						if ($country == '' || $country != $obj->country)
364 389
 						{
365 390
 							// Show break
@@ -372,8 +397,7 @@  discard block
 block discarded – undo
372 397
 						if ($selected > 0 && $selected == $obj->code)
373 398
 						{
374 399
 							print '<option value="'.$obj->code.'" selected>'.$obj->label.'</option>';
375
-						}
376
-						else
400
+						} else
377 401
 						{
378 402
 							print '<option value="'.$obj->code.'">'.$obj->label.'</option>';
379 403
 						}
@@ -382,8 +406,7 @@  discard block
 block discarded – undo
382 406
 				}
383 407
 			}
384 408
 			print '</select>';
385
-		}
386
-		else
409
+		} else
387 410
 		{
388 411
 			dol_print_error($this->db);
389 412
 		}
@@ -425,8 +448,7 @@  discard block
 block discarded – undo
425 448
 					if ($selected == $obj->code)
426 449
 					{
427 450
 						$out.= '<option value="'.$obj->code.'" selected>';
428
-					}
429
-					else
451
+					} else
430 452
 					{
431 453
 						$out.= '<option value="'.$obj->code.'">';
432 454
 					}
@@ -437,9 +459,10 @@  discard block
 block discarded – undo
437 459
 				}
438 460
 			}
439 461
 			$out.= '</select>';
440
-			if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
441
-		}
442
-		else
462
+			if ($user->admin) {
463
+			    $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
464
+			}
465
+		} else
443 466
 		{
444 467
 			dol_print_error($this->db);
445 468
 		}
@@ -489,8 +512,12 @@  discard block
 block discarded – undo
489 512
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_forme_juridique as f, ".MAIN_DB_PREFIX."c_country as c";
490 513
 		$sql .= " WHERE f.fk_pays=c.rowid";
491 514
 		$sql .= " AND f.active = 1 AND c.active = 1";
492
-		if ($country_codeid) $sql .= " AND c.code = '".$country_codeid."'";
493
-		if ($filter) $sql .= " ".$filter;
515
+		if ($country_codeid) {
516
+		    $sql .= " AND c.code = '".$country_codeid."'";
517
+		}
518
+		if ($filter) {
519
+		    $sql .= " ".$filter;
520
+		}
494 521
 		$sql .= " ORDER BY c.code";
495 522
 
496 523
 		dol_syslog(get_class($this)."::select_juridicalstatus", LOG_DEBUG);
@@ -499,7 +526,10 @@  discard block
 block discarded – undo
499 526
 		{
500 527
 			$out.= '<div id="particulier2" class="visible">';
501 528
 			$out.= '<select class="flat minwidth200" name="'.$htmlname.'" id="'.$htmlname.'">';
502
-			if ($country_codeid) $out.= '<option value="0">&nbsp;</option>';	// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
529
+			if ($country_codeid) {
530
+			    $out.= '<option value="0">&nbsp;</option>';
531
+			}
532
+			// When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select.
503 533
 
504 534
 			$num = $this->db->num_rows($resql);
505 535
 			if ($num)
@@ -510,9 +540,11 @@  discard block
 block discarded – undo
510 540
 				{
511 541
 					$obj = $this->db->fetch_object($resql);
512 542
 
513
-					if ($obj->code)		// We exclude empty line, we will add it later
543
+					if ($obj->code) {
544
+					    // We exclude empty line, we will add it later
514 545
 					{
515 546
 						$labelcountry=(($langs->trans("Country".$obj->country_code)!="Country".$obj->country_code) ? $langs->trans("Country".$obj->country_code) : $obj->country);
547
+					}
516 548
 						$labeljs=(($langs->trans("JuridicalStatus".$obj->code)!="JuridicalStatus".$obj->code) ? $langs->trans("JuridicalStatus".$obj->code) : ($obj->label!='-'?$obj->label:''));	// $obj->label is already in output charset (converted by database driver)
517 549
 						$arraydata[$obj->code]=array('code'=>$obj->code, 'label'=>$labeljs, 'label_sort'=>$labelcountry.'_'.$labeljs, 'country_code'=>$obj->country_code, 'country'=>$labelcountry);
518 550
 					}
@@ -520,10 +552,12 @@  discard block
 block discarded – undo
520 552
 				}
521 553
 
522 554
 				$arraydata=dol_sort_array($arraydata, 'label_sort', 'ASC');
523
-				if (empty($country_codeid))	// Introduce empty value (if $country_codeid not empty, empty value was already added)
555
+				if (empty($country_codeid)) {
556
+				    // Introduce empty value (if $country_codeid not empty, empty value was already added)
524 557
 				{
525 558
 					$arraydata[0]=array('code'=>0, 'label'=>'', 'label_sort'=>'_', 'country_code'=>'', 'country'=>'');
526 559
 				}
560
+				}
527 561
 
528 562
 				foreach($arraydata as $key => $val)
529 563
 				{
@@ -540,8 +574,7 @@  discard block
 block discarded – undo
540 574
 					if ($selected > 0 && $selected == $val['code'])
541 575
 					{
542 576
 						$out.= '<option value="'.$val['code'].'" selected>';
543
-					}
544
-					else
577
+					} else
545 578
 					{
546 579
 						$out.= '<option value="'.$val['code'].'">';
547 580
 					}
@@ -551,15 +584,16 @@  discard block
 block discarded – undo
551 584
 				}
552 585
 			}
553 586
 			$out.= '</select>';
554
-			if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
587
+			if ($user->admin) {
588
+			    $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
589
+			}
555 590
 
556 591
 		    // Make select dynamic
557 592
         	include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
558 593
 	        $out .= ajax_combobox($htmlname);
559 594
 
560 595
 			$out.= '</div>';
561
-		}
562
-		else
596
+		} else
563 597
 		{
564 598
 			dol_print_error($this->db);
565 599
 		}
@@ -611,7 +645,8 @@  discard block
 block discarded – undo
611 645
 			// To refresh contacts list on thirdparty list change
612 646
 			$events[]=array('method' => 'getContacts', 'url' => dol_buildpath('/core/ajax/contacts.php',1), 'htmlname' => 'contactid', 'params' => array('add-customer-contact' => 'disabled'));
613 647
 
614
-			if (count($events))	// If there is some ajax events to run once selection is done, we add code here to run events
648
+			if (count($events)) {
649
+			    // If there is some ajax events to run once selection is done, we add code here to run events
615 650
 			{
616 651
 				print '<script type="text/javascript">
617 652
 				jQuery(document).ready(function() {
@@ -662,13 +697,13 @@  discard block
 block discarded – undo
662 697
 				});
663 698
 				</script>';
664 699
 			}
700
+			}
665 701
 
666 702
 			print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
667 703
 			print '<input type="text" size="30" id="search_'.$htmlname.'" name="search_'.$htmlname.'" value="'.$name.'" />';
668 704
 			print ajax_autocompleter(($socid?$socid:-1), $htmlname, DOL_URL_ROOT.'/societe/ajaxcompanies.php', '', $minLength, 0);
669 705
 			return $socid;
670
-		}
671
-		else
706
+		} else
672 707
 		{
673 708
 			// Search to list thirdparties
674 709
 			$sql = "SELECT s.rowid, s.nom as name FROM";
@@ -698,20 +733,27 @@  discard block
 block discarded – undo
698 733
 					while ($i < $num)
699 734
 					{
700 735
 						$obj = $this->db->fetch_object($resql);
701
-						if ($i == 0) $firstCompany = $obj->rowid;
736
+						if ($i == 0) {
737
+						    $firstCompany = $obj->rowid;
738
+						}
702 739
 						$disabled=0;
703
-						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
740
+						if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) {
741
+						    $disabled=1;
742
+						}
704 743
 						if ($selected > 0 && $selected == $obj->rowid)
705 744
 						{
706 745
 							print '<option value="'.$obj->rowid.'"';
707
-							if ($disabled) print ' disabled';
746
+							if ($disabled) {
747
+							    print ' disabled';
748
+							}
708 749
 							print ' selected>'.dol_trunc($obj->name,24).'</option>';
709 750
 							$firstCompany = $obj->rowid;
710
-						}
711
-						else
751
+						} else
712 752
 						{
713 753
 							print '<option value="'.$obj->rowid.'"';
714
-							if ($disabled) print ' disabled';
754
+							if ($disabled) {
755
+							    print ' disabled';
756
+							}
715 757
 							print '>'.dol_trunc($obj->name,24).'</option>';
716 758
 						}
717 759
 						$i ++;
@@ -719,8 +761,7 @@  discard block
 block discarded – undo
719 761
 				}
720 762
 				print "</select>\n";
721 763
 				return $firstCompany;
722
-			}
723
-			else
764
+			} else
724 765
 			{
725 766
 				dol_print_error($this->db);
726 767
 				print 'Error sql';
@@ -748,15 +789,21 @@  discard block
 block discarded – undo
748 789
 		{
749 790
 			$lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
750 791
 			print '<select class="flat valignmiddle'.($morecss?' '.$morecss:'').'" name="'.$htmlname.'" id="'.$htmlname.'">';
751
-			if ($showempty) print '<option value="0"></option>';
792
+			if ($showempty) {
793
+			    print '<option value="0"></option>';
794
+			}
752 795
 			foreach($lesTypes as $key=>$value)
753 796
 			{
754 797
 				print '<option value="'.$key.'"';
755
-				if ($key == $selected) print ' selected';
798
+				if ($key == $selected) {
799
+				    print ' selected';
800
+				}
756 801
 				print '>'.$value.'</option>';
757 802
 			}
758 803
 			print "</select>";
759
-			if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
804
+			if ($user->admin) {
805
+			    print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
806
+			}
760 807
 			print "\n";
761 808
 		}
762 809
 	}
@@ -782,7 +829,9 @@  discard block
 block discarded – undo
782 829
 		$out='';
783 830
 
784 831
 		$size='';
785
-		if (!empty($fieldsize)) $size='size="'.$fieldsize.'"';
832
+		if (!empty($fieldsize)) {
833
+		    $size='size="'.$fieldsize.'"';
834
+		}
786 835
 
787 836
 		if ($conf->use_javascript_ajax && empty($disableautocomplete))
788 837
 		{
@@ -815,27 +864,51 @@  discard block
 block discarded – undo
815 864
         	if ($country_code == 'FR')
816 865
         	{
817 866
         		if (isset($idprof)) {
818
-        			if ($idprof==1) $formlength=9;
819
-        			else if ($idprof==2) $formlength=14;
820
-        			else if ($idprof==3) $formlength=5;      // 4 chiffres et 1 lettre depuis janvier
821
-        			else if ($idprof==4) $formlength=32;     // No maximum as we need to include a town name in this id
867
+        			if ($idprof==1) {
868
+        			    $formlength=9;
869
+        			} else if ($idprof==2) {
870
+        			    $formlength=14;
871
+        			} else if ($idprof==3) {
872
+        			    $formlength=5;
873
+        			}
874
+        			// 4 chiffres et 1 lettre depuis janvier
875
+        			else if ($idprof==4) {
876
+        			    $formlength=32;
877
+        			}
878
+        			// No maximum as we need to include a town name in this id
822 879
         		}
823
-        	}
824
-        	else if ($country_code == 'ES')
880
+        	} else if ($country_code == 'ES')
825 881
         	{
826
-        		if ($idprof==1) $formlength=9;  //CIF/NIF/NIE 9 digits
827
-        		if ($idprof==2) $formlength=12; //NASS 12 digits without /
828
-        		if ($idprof==3) $formlength=5;  //CNAE 5 digits
829
-        		if ($idprof==4) $formlength=32; //depend of college
882
+        		if ($idprof==1) {
883
+        		    $formlength=9;
884
+        		}
885
+        		//CIF/NIF/NIE 9 digits
886
+        		if ($idprof==2) {
887
+        		    $formlength=12;
888
+        		}
889
+        		//NASS 12 digits without /
890
+        		if ($idprof==3) {
891
+        		    $formlength=5;
892
+        		}
893
+        		//CNAE 5 digits
894
+        		if ($idprof==4) {
895
+        		    $formlength=32;
896
+        		}
897
+        		//depend of college
830 898
         	}
831 899
         }
832 900
 
833 901
         $selected=$preselected;
834 902
         if (! $selected && isset($idprof)) {
835
-        	if ($idprof==1 && ! empty($this->idprof1)) $selected=$this->idprof1;
836
-        	else if ($idprof==2 && ! empty($this->idprof2)) $selected=$this->idprof2;
837
-        	else if ($idprof==3 && ! empty($this->idprof3)) $selected=$this->idprof3;
838
-        	else if ($idprof==4 && ! empty($this->idprof4)) $selected=$this->idprof4;
903
+        	if ($idprof==1 && ! empty($this->idprof1)) {
904
+        	    $selected=$this->idprof1;
905
+        	} else if ($idprof==2 && ! empty($this->idprof2)) {
906
+        	    $selected=$this->idprof2;
907
+        	} else if ($idprof==3 && ! empty($this->idprof3)) {
908
+        	    $selected=$this->idprof3;
909
+        	} else if ($idprof==4 && ! empty($this->idprof4)) {
910
+        	    $selected=$this->idprof4;
911
+        	}
839 912
         }
840 913
 
841 914
         $maxlength=$formlength;
@@ -875,8 +948,7 @@  discard block
 block discarded – undo
875 948
     				if ($selected == $valors[$i])
876 949
     				{
877 950
     					print '<option value="'.$valors[$i].'" selected>';
878
-    				}
879
-    				else
951
+    				} else
880 952
     				{
881 953
     					print '<option value="'.$valors[$i].'">';
882 954
     				}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/smtps.class.php 3 patches
Indentation   +1668 added lines, -1668 removed lines patch added patch discarded remove patch
@@ -45,188 +45,188 @@  discard block
 block discarded – undo
45 45
  */
46 46
 class SMTPs
47 47
 {
48
-	/**
49
-	 * Host Name or IP of SMTP Server to use
50
-	 */
51
-	var $_smtpsHost = 'localhost';
52
-
53
-	/**
54
-	 * SMTP Server Port definition. 25 is default value
55
-	 * This can be defined via a INI file or via a setter method
56
-	 */
57
-	var $_smtpsPort = '25';
58
-
59
-	/**
60
-	 * Secure SMTP Server access ID
61
-	 * This can be defined via a INI file or via a setter method
62
-	 */
63
-	var $_smtpsID = null;
64
-
65
-	/**
66
-	 * Secure SMTP Server access Password
67
-	 * This can be defined via a INI file or via a setter method
68
-	 */
69
-	var $_smtpsPW = null;
70
-
71
-	/**
72
-	 * Who sent the Message
73
-	 * This can be defined via a INI file or via a setter method
74
-	 */
75
-	var $_msgFrom = null;
76
-
77
-	/**
78
-	 * Where are replies and errors to be sent to
79
-	 * This can be defined via a INI file or via a setter method
80
-	 */
81
-	var $_msgReplyTo = null;
82
-
83
-	/**
84
-	 * Who will the Message be sent to; TO, CC, BCC
85
-	 * Multi-diminsional array containg addresses the message will
86
-	 * be sent TO, CC or BCC
87
-	 */
88
-	var $_msgRecipients = null;
89
-
90
-	/**
91
-	 * Message Subject
92
-	 */
93
-	var $_msgSubject = null;
94
-
95
-	/**
96
-	 * Message Content
97
-	 */
98
-	var $_msgContent = null;
99
-
100
-	/**
101
-	 * Custom X-Headers
102
-	 */
103
-	var $_msgXheader = null;
104
-
105
-	/**
106
-	 * Character set
107
-	 * Defaulted to 'iso-8859-1'
108
-	 */
109
-	var $_smtpsCharSet = 'iso-8859-1';
110
-
111
-	/**
112
-	 * Message Sensitivity
113
-	 * Defaults to ZERO - None
114
-	 */
115
-	var $_msgSensitivity = 0;
116
-
117
-	/**
118
-	 * Message Sensitivity
119
-	 */
120
-	var $_arySensitivity = array ( false,
121
-                                  'Personal',
122
-                                  'Private',
123
-                                  'Company Confidential' );
124
-
125
-	/**
126
-	 * Message Sensitivity
127
-	 * Defaults to 3 - Normal
128
-	 */
129
-	var $_msgPriority = 3;
130
-
131
-	/**
132
-	 * Message Priority
133
-	 */
134
-	var $_aryPriority = array ( 'Bulk',
48
+    /**
49
+     * Host Name or IP of SMTP Server to use
50
+     */
51
+    var $_smtpsHost = 'localhost';
52
+
53
+    /**
54
+     * SMTP Server Port definition. 25 is default value
55
+     * This can be defined via a INI file or via a setter method
56
+     */
57
+    var $_smtpsPort = '25';
58
+
59
+    /**
60
+     * Secure SMTP Server access ID
61
+     * This can be defined via a INI file or via a setter method
62
+     */
63
+    var $_smtpsID = null;
64
+
65
+    /**
66
+     * Secure SMTP Server access Password
67
+     * This can be defined via a INI file or via a setter method
68
+     */
69
+    var $_smtpsPW = null;
70
+
71
+    /**
72
+     * Who sent the Message
73
+     * This can be defined via a INI file or via a setter method
74
+     */
75
+    var $_msgFrom = null;
76
+
77
+    /**
78
+     * Where are replies and errors to be sent to
79
+     * This can be defined via a INI file or via a setter method
80
+     */
81
+    var $_msgReplyTo = null;
82
+
83
+    /**
84
+     * Who will the Message be sent to; TO, CC, BCC
85
+     * Multi-diminsional array containg addresses the message will
86
+     * be sent TO, CC or BCC
87
+     */
88
+    var $_msgRecipients = null;
89
+
90
+    /**
91
+     * Message Subject
92
+     */
93
+    var $_msgSubject = null;
94
+
95
+    /**
96
+     * Message Content
97
+     */
98
+    var $_msgContent = null;
99
+
100
+    /**
101
+     * Custom X-Headers
102
+     */
103
+    var $_msgXheader = null;
104
+
105
+    /**
106
+     * Character set
107
+     * Defaulted to 'iso-8859-1'
108
+     */
109
+    var $_smtpsCharSet = 'iso-8859-1';
110
+
111
+    /**
112
+     * Message Sensitivity
113
+     * Defaults to ZERO - None
114
+     */
115
+    var $_msgSensitivity = 0;
116
+
117
+    /**
118
+     * Message Sensitivity
119
+     */
120
+    var $_arySensitivity = array ( false,
121
+                                    'Personal',
122
+                                    'Private',
123
+                                    'Company Confidential' );
124
+
125
+    /**
126
+     * Message Sensitivity
127
+     * Defaults to 3 - Normal
128
+     */
129
+    var $_msgPriority = 3;
130
+
131
+    /**
132
+     * Message Priority
133
+     */
134
+    var $_aryPriority = array ( 'Bulk',
135 135
                                 'Highest',
136 136
                                 'High',
137 137
                                 'Normal',
138 138
                                 'Low',
139 139
                                 'Lowest' );
140 140
 
141
-	/**
142
-	 * Content-Transfer-Encoding
143
-	 * Defaulted to 0 - 7bit
144
-	 */
145
-	var $_smtpsTransEncodeType = 0;
146
-
147
-	/**
148
-	 * Content-Transfer-Encoding
149
-	 */
150
-	var $_smtpsTransEncodeTypes = array( '7bit',               // Simple 7-bit ASCII
151
-                                         '8bit',               // 8-bit coding with line termination characters
152
-                                         'base64',             // 3 octets encoded into 4 sextets with offset
153
-                                         'binary',             // Arbitrary binary stream
154
-                                         'mac-binhex40',       // Macintosh binary to hex encoding
155
-                                         'quoted-printable',   // Mostly 7-bit, with 8-bit characters encoded as "=HH"
156
-                                         'uuencode' );         // UUENCODE encoding
157
-
158
-	/**
159
-	 * Content-Transfer-Encoding
160
-	 * Defaulted to '7bit'
161
-	 */
162
-	var $_smtpsTransEncode = '7bit';
163
-
164
-	/**
165
-	 * Boundary String for MIME seperation
166
-	 */
167
-	var $_smtpsBoundary = null;
168
-
169
-	/**
170
-	 * Related Boundary
171
-	 */
172
-	var $_smtpsRelatedBoundary = null;
173
-
174
-	/**
175
-	 * Alternative Boundary
176
-	 */
177
-	var $_smtpsAlternativeBoundary = null;
178
-
179
-	/**
180
-	 * Determines the method inwhich the message are to be sent.
181
-	 * - 'sockets' [0] - conect via network to SMTP server - default
182
-	 * - 'pipe     [1] - use UNIX path to EXE
183
-	 * - 'phpmail  [2] - use the PHP built-in mail function
184
-	 * NOTE: Only 'sockets' is implemented
185
-	 */
186
-	var $_transportType = 0;
187
-
188
-	/**
189
-	 * If '$_transportType' is set to '1', then this variable is used
190
-	 * to define the UNIX file system path to the sendmail execuable
191
-	 */
192
-	var $_mailPath = '/usr/lib/sendmail';
193
-
194
-	/**
195
-	 * Sets the SMTP server timeout in seconds.
196
-	 */
197
-	var $_smtpTimeout = 10;
198
-
199
-	/**
200
-	 * Determines whether to calculate message MD5 checksum.
201
-	 */
202
-	var $_smtpMD5 = false;
203
-
204
-	/**
205
-	 * Class error codes and messages
206
-	 */
207
-	var $_smtpsErrors = null;
208
-
209
-	/**
210
-	 * Defines log level
211
-	 *  0 - no logging
212
-	 *  1 - connectivity logging
213
-	 *  2 - message generation logging
214
-	 *  3 - detail logging
215
-	 */
216
-	var $_log_level = 0;
217
-
218
-	/**
219
-	 * Place Class in" debug" mode
220
-	 */
221
-	var $_debug = false;
222
-
223
-
224
-	// @CHANGE LDR
225
-	var $log = '';
226
-	var $_errorsTo = '';
227
-	var $_deliveryReceipt = 0;
228
-	var $_trackId = '';
229
-	var $_moreInHeader = '';
141
+    /**
142
+     * Content-Transfer-Encoding
143
+     * Defaulted to 0 - 7bit
144
+     */
145
+    var $_smtpsTransEncodeType = 0;
146
+
147
+    /**
148
+     * Content-Transfer-Encoding
149
+     */
150
+    var $_smtpsTransEncodeTypes = array( '7bit',               // Simple 7-bit ASCII
151
+                                            '8bit',               // 8-bit coding with line termination characters
152
+                                            'base64',             // 3 octets encoded into 4 sextets with offset
153
+                                            'binary',             // Arbitrary binary stream
154
+                                            'mac-binhex40',       // Macintosh binary to hex encoding
155
+                                            'quoted-printable',   // Mostly 7-bit, with 8-bit characters encoded as "=HH"
156
+                                            'uuencode' );         // UUENCODE encoding
157
+
158
+    /**
159
+     * Content-Transfer-Encoding
160
+     * Defaulted to '7bit'
161
+     */
162
+    var $_smtpsTransEncode = '7bit';
163
+
164
+    /**
165
+     * Boundary String for MIME seperation
166
+     */
167
+    var $_smtpsBoundary = null;
168
+
169
+    /**
170
+     * Related Boundary
171
+     */
172
+    var $_smtpsRelatedBoundary = null;
173
+
174
+    /**
175
+     * Alternative Boundary
176
+     */
177
+    var $_smtpsAlternativeBoundary = null;
178
+
179
+    /**
180
+     * Determines the method inwhich the message are to be sent.
181
+     * - 'sockets' [0] - conect via network to SMTP server - default
182
+     * - 'pipe     [1] - use UNIX path to EXE
183
+     * - 'phpmail  [2] - use the PHP built-in mail function
184
+     * NOTE: Only 'sockets' is implemented
185
+     */
186
+    var $_transportType = 0;
187
+
188
+    /**
189
+     * If '$_transportType' is set to '1', then this variable is used
190
+     * to define the UNIX file system path to the sendmail execuable
191
+     */
192
+    var $_mailPath = '/usr/lib/sendmail';
193
+
194
+    /**
195
+     * Sets the SMTP server timeout in seconds.
196
+     */
197
+    var $_smtpTimeout = 10;
198
+
199
+    /**
200
+     * Determines whether to calculate message MD5 checksum.
201
+     */
202
+    var $_smtpMD5 = false;
203
+
204
+    /**
205
+     * Class error codes and messages
206
+     */
207
+    var $_smtpsErrors = null;
208
+
209
+    /**
210
+     * Defines log level
211
+     *  0 - no logging
212
+     *  1 - connectivity logging
213
+     *  2 - message generation logging
214
+     *  3 - detail logging
215
+     */
216
+    var $_log_level = 0;
217
+
218
+    /**
219
+     * Place Class in" debug" mode
220
+     */
221
+    var $_debug = false;
222
+
223
+
224
+    // @CHANGE LDR
225
+    var $log = '';
226
+    var $_errorsTo = '';
227
+    var $_deliveryReceipt = 0;
228
+    var $_trackId = '';
229
+    var $_moreInHeader = '';
230 230
 
231 231
 
232 232
     /**
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
      * @param	int		$_val		Value
236 236
      * @return	void
237 237
      */
238
-	function setDeliveryReceipt($_val = 0)
239
-	{
240
-		$this->_deliveryReceipt = $_val;
241
-	}
238
+    function setDeliveryReceipt($_val = 0)
239
+    {
240
+        $this->_deliveryReceipt = $_val;
241
+    }
242 242
 
243 243
     /**
244 244
      * get delivery receipt
245 245
      *
246 246
      * @return	int		Delivery receipt
247 247
      */
248
-	function getDeliveryReceipt()
249
-	{
250
-		return $this->_deliveryReceipt;
251
-	}
248
+    function getDeliveryReceipt()
249
+    {
250
+        return $this->_deliveryReceipt;
251
+    }
252 252
 
253 253
     /**
254 254
      * Set trackid
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
      * @param	string		$_val		Value
257 257
      * @return	void
258 258
      */
259
-	function setTrackId($_val = '')
260
-	{
261
-		$this->_trackId = $_val;
262
-	}
259
+    function setTrackId($_val = '')
260
+    {
261
+        $this->_trackId = $_val;
262
+    }
263 263
 
264 264
     /**
265 265
      * Set moreInHeader
@@ -267,30 +267,30 @@  discard block
 block discarded – undo
267 267
      * @param	string		$_val		Value
268 268
      * @return	void
269 269
      */
270
-	function setMoreInHeader($_val = '')
271
-	{
272
-		$this->_moreinheader = $_val;
273
-	}
270
+    function setMoreInHeader($_val = '')
271
+    {
272
+        $this->_moreinheader = $_val;
273
+    }
274 274
 
275
-	/**
275
+    /**
276 276
      * get trackid
277 277
      *
278 278
      * @return	string		Track id
279 279
      */
280
-	function getTrackId()
281
-	{
282
-		return $this->_trackId;
283
-	}
280
+    function getTrackId()
281
+    {
282
+        return $this->_trackId;
283
+    }
284 284
 
285
-	/**
286
-	 * get moreInHeader
287
-	 *
288
-	 * @return	string		moreInHeader
289
-	 */
290
-	function getMoreInHeader()
291
-	{
292
-	    return $this->_moreinheader;
293
-	}
285
+    /**
286
+     * get moreInHeader
287
+     *
288
+     * @return	string		moreInHeader
289
+     */
290
+    function getMoreInHeader()
291
+    {
292
+        return $this->_moreinheader;
293
+    }
294 294
 
295 295
     /**
296 296
      * Set errors to
@@ -298,11 +298,11 @@  discard block
 block discarded – undo
298 298
      * @param	string		$_strErrorsTo		Errors to
299 299
      * @return	void
300 300
      */
301
-	function setErrorsTo($_strErrorsTo)
302
-	{
303
-		if ( $_strErrorsTo )
304
-		$this->_errorsTo = $this->_strip_email($_strErrorsTo);
305
-	}
301
+    function setErrorsTo($_strErrorsTo)
302
+    {
303
+        if ( $_strErrorsTo )
304
+        $this->_errorsTo = $this->_strip_email($_strErrorsTo);
305
+    }
306 306
 
307 307
     /**
308 308
      * Get errors to
@@ -310,143 +310,143 @@  discard block
 block discarded – undo
310 310
      * @param	boolean		$_part		Variant
311 311
      * @return	string					Errors to
312 312
      */
313
-	function getErrorsTo($_part = true )
314
-	{
315
-		$_retValue = '';
316
-
317
-		if ( $_part === true )
318
-		$_retValue = $this->_errorsTo;
319
-		else
320
-		$_retValue = $this->_errorsTo[$_part];
321
-
322
-		return $_retValue;
323
-	}
324
-
325
-	/**
326
-	 * Set debug
327
-	 *
328
-	 * @param	boolean		$_vDebug		Value for debug
329
-	 * @return 	void
330
-	 */
331
-	function setDebug($_vDebug = false )
332
-	{
333
-		$this->_debug = $_vDebug;
334
-	}
335
-
336
-	/**
337
-	 * build RECIPIENT List, all addresses who will recieve this message
338
-	 *
339
-	 * @return void
340
-	 */
341
-	function buildRCPTlist()
342
-	{
343
-		// Pull TO list
344
-		$_aryToList = $this->getTO();
345
-	}
313
+    function getErrorsTo($_part = true )
314
+    {
315
+        $_retValue = '';
316
+
317
+        if ( $_part === true )
318
+        $_retValue = $this->_errorsTo;
319
+        else
320
+        $_retValue = $this->_errorsTo[$_part];
321
+
322
+        return $_retValue;
323
+    }
324
+
325
+    /**
326
+     * Set debug
327
+     *
328
+     * @param	boolean		$_vDebug		Value for debug
329
+     * @return 	void
330
+     */
331
+    function setDebug($_vDebug = false )
332
+    {
333
+        $this->_debug = $_vDebug;
334
+    }
335
+
336
+    /**
337
+     * build RECIPIENT List, all addresses who will recieve this message
338
+     *
339
+     * @return void
340
+     */
341
+    function buildRCPTlist()
342
+    {
343
+        // Pull TO list
344
+        $_aryToList = $this->getTO();
345
+    }
346 346
 
347 347
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
348
-	/**
349
-	 * Attempt a connection to mail server
350
-	 *
351
-	 * @return mixed  $_retVal   Boolean indicating success or failure on connection
352
-	 */
353
-	function _server_connect()
354
-	{
348
+    /**
349
+     * Attempt a connection to mail server
350
+     *
351
+     * @return mixed  $_retVal   Boolean indicating success or failure on connection
352
+     */
353
+    function _server_connect()
354
+    {
355 355
         // phpcs:enable
356
-		// Default return value
357
-		$_retVal = true;
358
-
359
-		// We have to make sure the HOST given is valid
360
-		// This is done here because '@fsockopen' will not give me this
361
-		// information if it failes to connect because it can't find the HOST
362
-		$host=$this->getHost();
363
-		$usetls = preg_match('@tls://@i',$host);
364
-
365
-		$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
366
-		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
367
-		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
368
-
369
-		// @CHANGE LDR
370
-		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
371
-
372
-		if ( (! is_ip($host)) && ((gethostbyname($host)) == $host))
373
-		{
374
-			$this->_setErr(99, $host . ' is either offline or is an invalid host name.');
375
-			$_retVal = false;
376
-		}
377
-		else
378
-		{
379
-			//See if we can connect to the SMTP server
380
-			if ($this->socket = @fsockopen(
381
-    			preg_replace('@tls://@i','',$this->getHost()),       // Host to 'hit', IP or domain
382
-    			$this->getPort(),       // which Port number to use
383
-    			$this->errno,           // actual system level error
384
-    			$this->errstr,          // and any text that goes with the error
385
-    			$this->_smtpTimeout
386
-			))  // timeout for reading/writing data over the socket
387
-			{
388
-				// Fix from PHP SMTP class by 'Chris Ryan'
389
-				// Sometimes the SMTP server takes a little longer to respond
390
-				// so we will give it a longer timeout for the first read
391
-				// Windows still does not have support for this timeout function
392
-				if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
393
-
394
-				// Check response from Server
395
-				if ( $_retVal = $this->server_parse($this->socket, "220") )
396
-				$_retVal = $this->socket;
397
-			}
398
-			// This connection attempt failed.
399
-			else
400
-			{
401
-				// @CHANGE LDR
402
-				if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
403
-				$this->_setErr($this->errno, $this->errstr);
404
-				$_retVal = false;
405
-			}
406
-		}
407
-
408
-		return $_retVal;
409
-	}
356
+        // Default return value
357
+        $_retVal = true;
358
+
359
+        // We have to make sure the HOST given is valid
360
+        // This is done here because '@fsockopen' will not give me this
361
+        // information if it failes to connect because it can't find the HOST
362
+        $host=$this->getHost();
363
+        $usetls = preg_match('@tls://@i',$host);
364
+
365
+        $host=preg_replace('@tcp://@i','',$host);	// Remove prefix
366
+        $host=preg_replace('@ssl://@i','',$host);	// Remove prefix
367
+        $host=preg_replace('@tls://@i','',$host);	// Remove prefix
368
+
369
+        // @CHANGE LDR
370
+        include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
371
+
372
+        if ( (! is_ip($host)) && ((gethostbyname($host)) == $host))
373
+        {
374
+            $this->_setErr(99, $host . ' is either offline or is an invalid host name.');
375
+            $_retVal = false;
376
+        }
377
+        else
378
+        {
379
+            //See if we can connect to the SMTP server
380
+            if ($this->socket = @fsockopen(
381
+                preg_replace('@tls://@i','',$this->getHost()),       // Host to 'hit', IP or domain
382
+                $this->getPort(),       // which Port number to use
383
+                $this->errno,           // actual system level error
384
+                $this->errstr,          // and any text that goes with the error
385
+                $this->_smtpTimeout
386
+            ))  // timeout for reading/writing data over the socket
387
+            {
388
+                // Fix from PHP SMTP class by 'Chris Ryan'
389
+                // Sometimes the SMTP server takes a little longer to respond
390
+                // so we will give it a longer timeout for the first read
391
+                // Windows still does not have support for this timeout function
392
+                if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
393
+
394
+                // Check response from Server
395
+                if ( $_retVal = $this->server_parse($this->socket, "220") )
396
+                $_retVal = $this->socket;
397
+            }
398
+            // This connection attempt failed.
399
+            else
400
+            {
401
+                // @CHANGE LDR
402
+                if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
403
+                $this->_setErr($this->errno, $this->errstr);
404
+                $_retVal = false;
405
+            }
406
+        }
407
+
408
+        return $_retVal;
409
+    }
410 410
 
411 411
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
412
-	/**
413
-	 * Attempt mail server authentication for a secure connection
414
-	 *
415
-	 * @return boolean|null  $_retVal   Boolean indicating success or failure of authentication
416
-	 */
417
-	function _server_authenticate()
418
-	{
412
+    /**
413
+     * Attempt mail server authentication for a secure connection
414
+     *
415
+     * @return boolean|null  $_retVal   Boolean indicating success or failure of authentication
416
+     */
417
+    function _server_authenticate()
418
+    {
419 419
         // phpcs:enable
420
-		global $conf;
421
-
422
-		// Send the RFC2554 specified EHLO.
423
-		// This improvment as provided by 'SirSir' to
424
-		// accomodate both SMTP AND ESMTP capable servers
425
-		$host=$this->getHost();
426
-		$usetls = preg_match('@tls://@i',$host);
427
-
428
-		$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
429
-		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
430
-		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
431
-
432
-		if ($usetls) $host='tls://'.$host;
433
-
434
-		$hosth = $host;
435
-
436
-		if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
437
-		{
438
-			// If the from to is 'aaa <[email protected]>', we will keep 'ccc.com'
439
-			$hosth = $this->getFrom('addr');
440
-			$hosth = preg_replace('/^.*</', '', $hosth);
441
-			$hosth = preg_replace('/>.*$/', '', $hosth);
442
-			$hosth = preg_replace('/.*@/', '', $hosth);
443
-		}
444
-
445
-		if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') )
446
-		{
447
-			if ($usetls)
448
-			{
449
-			    /*
420
+        global $conf;
421
+
422
+        // Send the RFC2554 specified EHLO.
423
+        // This improvment as provided by 'SirSir' to
424
+        // accomodate both SMTP AND ESMTP capable servers
425
+        $host=$this->getHost();
426
+        $usetls = preg_match('@tls://@i',$host);
427
+
428
+        $host=preg_replace('@tcp://@i','',$host);	// Remove prefix
429
+        $host=preg_replace('@ssl://@i','',$host);	// Remove prefix
430
+        $host=preg_replace('@tls://@i','',$host);	// Remove prefix
431
+
432
+        if ($usetls) $host='tls://'.$host;
433
+
434
+        $hosth = $host;
435
+
436
+        if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
437
+        {
438
+            // If the from to is 'aaa <[email protected]>', we will keep 'ccc.com'
439
+            $hosth = $this->getFrom('addr');
440
+            $hosth = preg_replace('/^.*</', '', $hosth);
441
+            $hosth = preg_replace('/>.*$/', '', $hosth);
442
+            $hosth = preg_replace('/.*@/', '', $hosth);
443
+        }
444
+
445
+        if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') )
446
+        {
447
+            if ($usetls)
448
+            {
449
+                /*
450 450
 			    The following dialog illustrates how a client and server can start a TLS STARTTLS session
451 451
 			    S: <waits for connection on TCP port 25>
452 452
 			    C: <opens connection>
@@ -465,130 +465,130 @@  discard block
 block discarded – undo
465 465
                 S: 250 AUTH LOGIN
466 466
 			    C: <continues by sending an SMTP command
467 467
 			    */
468
-				if (!$_retVal = $this->socket_send_str('STARTTLS', 220))
469
-				{
470
-					$this->_setErr(131, 'STARTTLS connection is not supported.');
471
-					return $_retVal;
472
-				}
473
-
474
-				// Before 5.6.7:
475
-				// STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT
476
-				// STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
477
-				// PHP >= 5.6.7:
478
-				// STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
479
-				// STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
480
-
481
-				$crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
482
-				if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
483
-					$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
484
-					$crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
485
-				}
486
-
487
-				if (!stream_socket_enable_crypto($this->socket, true, $crypto_method))
488
-				{
489
-					$this->_setErr(132, 'STARTTLS connection failed.');
490
-					return $_retVal;
491
-				}
492
-				// Most server servers expect a 2nd pass of EHLO after TLS is established to get another time
493
-				// the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
494
-				if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250'))
495
-				{
496
-					$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
497
-					return $_retVal;
498
-				}
499
-			}
500
-			// Send Authentication to Server
501
-			// Check for errors along the way
502
-			$this->socket_send_str('AUTH LOGIN', '334');
503
-
504
-			// User name will not return any error, server will take anything we give it.
505
-			$this->socket_send_str(base64_encode($this->_smtpsID), '334');
506
-
507
-			// The error here just means the ID/password combo doesn't work.
508
-			// There is not a method to determine which is the problem, ID or password
509
-			if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
510
-			$this->_setErr(130, 'Invalid Authentication Credentials.');
511
-		}
512
-		else
513
-		{
514
-			$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
515
-		}
516
-
517
-		return $_retVal;
518
-	}
519
-
520
-	/**
521
-	 * Now send the message
522
-	 *
523
-	 * @param  boolean $_bolTestMsg  whether to run this method in 'Test' mode.
524
-	 * @param  boolean $_bolDebug    whether to log all communication between this Class and the Mail Server.
525
-	 * @return boolean|null   void
526
-	 *                 $_strMsg      If this is run in 'Test' mode, the actual message structure will be returned
527
-	 */
528
-	function sendMsg($_bolTestMsg = false, $_bolDebug = false)
529
-	{
530
-		global $conf;
531
-
532
-		/**
533
-		 * Default return value
534
-		 */
535
-		$_retVal = false;
536
-
537
-		// Connect to Server
538
-		if ( $this->socket = $this->_server_connect() )
539
-		{
540
-			// If a User ID *and* a password is given, assume Authentication is desired
541
-			if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) )
542
-			{
543
-				// Send the RFC2554 specified EHLO.
544
-				$_retVal = $this->_server_authenticate();
545
-			}
546
-
547
-			// This is a "normal" SMTP Server "handshack"
548
-			else
549
-			{
550
-				// Send the RFC821 specified HELO.
551
-				$host=$this->getHost();
552
-				$usetls = preg_match('@tls://@i',$host);
553
-
554
-				$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
555
-				$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
556
-				$host=preg_replace('@tls://@i','',$host);	// Remove prefix
557
-
558
-				$hosth = $host;
559
-
560
-				if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
561
-				{
562
-					// If the from to is 'aaa <[email protected]>', we will keep 'ccc.com'
563
-					$hosth = $this->getFrom('addr');
564
-					$hosth = preg_replace('/^.*</', '', $hosth);
565
-					$hosth = preg_replace('/>.*$/', '', $hosth);
566
-					$hosth = preg_replace('/.*@/', '', $hosth);
567
-				}
568
-
569
-				$_retVal = $this->socket_send_str('HELO ' . $hosth, '250');
570
-			}
571
-
572
-			// Well, did we get to the server?
573
-			if ( $_retVal )
574
-			{
575
-				// From this point onward most server response codes should be 250
576
-				// Specify who the mail is from....
577
-				// This has to be the raw email address, strip the "name" off
578
-				$this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250');
579
-
580
-				// 'RCPT TO:' must be given a single address, so this has to loop
581
-				// through the list of addresses, regardless of TO, CC or BCC
582
-				// and send it out "single file"
583
-				foreach ( $this->get_RCPT_list() as $_address )
584
-				{
585
-				    /* Note:
468
+                if (!$_retVal = $this->socket_send_str('STARTTLS', 220))
469
+                {
470
+                    $this->_setErr(131, 'STARTTLS connection is not supported.');
471
+                    return $_retVal;
472
+                }
473
+
474
+                // Before 5.6.7:
475
+                // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_SSLv2_CLIENT|STREAM_CRYPTO_METHOD_SSLv3_CLIENT
476
+                // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
477
+                // PHP >= 5.6.7:
478
+                // STREAM_CRYPTO_METHOD_SSLv23_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT|STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
479
+                // STREAM_CRYPTO_METHOD_TLS_CLIENT = STREAM_CRYPTO_METHOD_TLSv1_0_CLIENT
480
+
481
+                $crypto_method = STREAM_CRYPTO_METHOD_TLS_CLIENT;
482
+                if (defined('STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT')) {
483
+                    $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT;
484
+                    $crypto_method |= STREAM_CRYPTO_METHOD_TLSv1_1_CLIENT;
485
+                }
486
+
487
+                if (!stream_socket_enable_crypto($this->socket, true, $crypto_method))
488
+                {
489
+                    $this->_setErr(132, 'STARTTLS connection failed.');
490
+                    return $_retVal;
491
+                }
492
+                // Most server servers expect a 2nd pass of EHLO after TLS is established to get another time
493
+                // the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
494
+                if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250'))
495
+                {
496
+                    $this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
497
+                    return $_retVal;
498
+                }
499
+            }
500
+            // Send Authentication to Server
501
+            // Check for errors along the way
502
+            $this->socket_send_str('AUTH LOGIN', '334');
503
+
504
+            // User name will not return any error, server will take anything we give it.
505
+            $this->socket_send_str(base64_encode($this->_smtpsID), '334');
506
+
507
+            // The error here just means the ID/password combo doesn't work.
508
+            // There is not a method to determine which is the problem, ID or password
509
+            if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
510
+            $this->_setErr(130, 'Invalid Authentication Credentials.');
511
+        }
512
+        else
513
+        {
514
+            $this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
515
+        }
516
+
517
+        return $_retVal;
518
+    }
519
+
520
+    /**
521
+     * Now send the message
522
+     *
523
+     * @param  boolean $_bolTestMsg  whether to run this method in 'Test' mode.
524
+     * @param  boolean $_bolDebug    whether to log all communication between this Class and the Mail Server.
525
+     * @return boolean|null   void
526
+     *                 $_strMsg      If this is run in 'Test' mode, the actual message structure will be returned
527
+     */
528
+    function sendMsg($_bolTestMsg = false, $_bolDebug = false)
529
+    {
530
+        global $conf;
531
+
532
+        /**
533
+         * Default return value
534
+         */
535
+        $_retVal = false;
536
+
537
+        // Connect to Server
538
+        if ( $this->socket = $this->_server_connect() )
539
+        {
540
+            // If a User ID *and* a password is given, assume Authentication is desired
541
+            if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) )
542
+            {
543
+                // Send the RFC2554 specified EHLO.
544
+                $_retVal = $this->_server_authenticate();
545
+            }
546
+
547
+            // This is a "normal" SMTP Server "handshack"
548
+            else
549
+            {
550
+                // Send the RFC821 specified HELO.
551
+                $host=$this->getHost();
552
+                $usetls = preg_match('@tls://@i',$host);
553
+
554
+                $host=preg_replace('@tcp://@i','',$host);	// Remove prefix
555
+                $host=preg_replace('@ssl://@i','',$host);	// Remove prefix
556
+                $host=preg_replace('@tls://@i','',$host);	// Remove prefix
557
+
558
+                $hosth = $host;
559
+
560
+                if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
561
+                {
562
+                    // If the from to is 'aaa <[email protected]>', we will keep 'ccc.com'
563
+                    $hosth = $this->getFrom('addr');
564
+                    $hosth = preg_replace('/^.*</', '', $hosth);
565
+                    $hosth = preg_replace('/>.*$/', '', $hosth);
566
+                    $hosth = preg_replace('/.*@/', '', $hosth);
567
+                }
568
+
569
+                $_retVal = $this->socket_send_str('HELO ' . $hosth, '250');
570
+            }
571
+
572
+            // Well, did we get to the server?
573
+            if ( $_retVal )
574
+            {
575
+                // From this point onward most server response codes should be 250
576
+                // Specify who the mail is from....
577
+                // This has to be the raw email address, strip the "name" off
578
+                $this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250');
579
+
580
+                // 'RCPT TO:' must be given a single address, so this has to loop
581
+                // through the list of addresses, regardless of TO, CC or BCC
582
+                // and send it out "single file"
583
+                foreach ( $this->get_RCPT_list() as $_address )
584
+                {
585
+                    /* Note:
586 586
 				     * BCC email addresses must be listed in the RCPT TO command list,
587 587
                      * but the BCC header should not be printed under the DATA command.
588 588
 				     * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
589 589
 				     */
590 590
 
591
-    				/*
591
+                    /*
592 592
 					 * TODO
593 593
 					 * After each 'RCPT TO:' is sent, we need to make sure it was kosher,
594 594
 					 * if not, the whole message will fail
@@ -596,1237 +596,1237 @@  discard block
 block discarded – undo
596 596
 					 * mark the last address as "bad" and start the address loop over again.
597 597
 					 * If any address fails, the entire message fails.
598 598
 					 */
599
-					$this->socket_send_str('RCPT TO: <' . $_address . '>', '250');
600
-				}
601
-
602
-				// Tell the server we are ready to start sending data
603
-				// with any custom headers...
604
-				// This is the last response code we look for until the end of the message.
605
-				$this->socket_send_str('DATA', '354');
606
-
607
-				// Now we are ready for the message...
608
-				// Ok, all the ingredients are mixed in let's cook this puppy...
609
-				$this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250');
610
-
611
-				// Now tell the server we are done and close the socket...
612
-				fputs($this->socket, 'QUIT');
613
-				fclose($this->socket);
614
-			}
615
-		}
616
-
617
-		return $_retVal;
618
-	}
619
-
620
-	// =============================================================
621
-	// ** Setter & Getter methods
622
-
623
-	// ** Basic System configuration
624
-
625
-	/**
626
-	 * setConfig() is used to populate select class properties from either
627
-	 * a user defined INI file or the systems 'php.ini' file
628
-	 *
629
-	 * If a user defined INI is to be used, the files complete path is passed
630
-	 * as the method single parameter. The INI can define any class and/or
631
-	 * user properties. Only properties defined within this file will be setter
632
-	 * and/or orverwritten
633
-	 *
634
-	 * If the systems 'php.ini' file is to be used, the method is called without
635
-	 * parameters. In this case, only HOST, PORT and FROM properties will be set
636
-	 * as they are the only properties that are defined within the 'php.ini'.
637
-	 *
638
-	 * If secure SMTP is to be used, the user ID and Password can be defined with
639
-	 * the user INI file, but the properties are not defined with the systems
640
-	 * 'php.ini'file, they must be defined via their setter methods
641
-	 *
642
-	 * This method can be called twice, if desired. Once without a parameter to
643
-	 * load the properties as defined within the systems 'php.ini' file, and a
644
-	 * second time, with a path to a user INI file for other properties to be
645
-	 * defined.
646
-	 *
647
-	 * @param mixed $_strConfigPath path to config file or VOID
648
-	 * @return boolean
649
-	 */
650
-	function setConfig($_strConfigPath = null)
651
-	{
652
-		/**
653
-		 * Returns constructed SELECT Object string or boolean upon failure
654
-		 * Default value is set at true
655
-		 */
656
-		$_retVal = true;
657
-
658
-		// if we have a path...
659
-		if ( ! empty ($_strConfigPath) )
660
-		{
661
-			// If the path is not valid, this will NOT generate an error,
662
-			// it will simply return false.
663
-			if ( ! @include $_strConfigPath)
664
-			{
665
-				$this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.');
666
-				$_retVal = false;
667
-			}
668
-		}
669
-
670
-		// Read the Systems php.ini file
671
-		else
672
-		{
673
-			// Set these properties ONLY if they are set in the php.ini file.
674
-			// Otherwise the default values will be used.
675
-			if ( $_host = ini_get('SMTPs') )
676
-			$this->setHost($_host);
677
-
678
-			if ( $_port = ini_get('smtp_port') )
679
-			$this->setPort($_port);
680
-
681
-			if ( $_from = ini_get('sendmail_from') )
682
-			$this->setFrom($_from);
683
-		}
684
-
685
-		// Send back what we have
686
-		return $_retVal;
687
-	}
688
-
689
-	/**
690
-	 * Determines the method inwhich the messages are to be sent.
691
-	 * - 'sockets' [0] - conect via network to SMTP server
692
-	 * - 'pipe     [1] - use UNIX path to EXE
693
-	 * - 'phpmail  [2] - use the PHP built-in mail function
694
-	 *
695
-	 * @param int $_type  Interger value representing Mail Transport Type
696
-	 * @return void
697
-	 */
698
-	function setTransportType($_type = 0)
699
-	{
700
-		if ( ( is_numeric($_type) ) &&
701
-		( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
702
-		$this->_transportType = $_type;
703
-	}
704
-
705
-	/**
706
-	 * Return the method inwhich the message is to be sent.
707
-	 * - 'sockets' [0] - conect via network to SMTP server
708
-	 * - 'pipe     [1] - use UNIX path to EXE
709
-	 * - 'phpmail  [2] - use the PHP built-in mail function
710
-	 *
711
-	 * @return int $_strHost Host Name or IP of the Mail Server to use
712
-	 */
713
-	function getTransportType()
714
-	{
715
-		return $this->_transportType;
716
-	}
717
-
718
-	/**
719
-	 * Path to the sendmail execuable
720
-	 *
721
-	 * @param string $_path Path to the sendmail execuable
722
-	 * @return boolean
723
-	 *
724
-	 */
725
-	function setMailPath($_path)
726
-	{
727
-		// This feature is not yet implemented
728
-		return true;
729
-
730
-		//if ( $_path ) $this->_mailPath = $_path;
731
-	}
732
-
733
-	/**
734
-	 * Defines the Host Name or IP of the Mail Server to use.
735
-	 * This is defaulted to 'localhost'
736
-	 * This is  used only with 'socket' based mail transmission
737
-	 *
738
-	 * @param 	string 	$_strHost 		Host Name or IP of the Mail Server to use
739
-	 * @return 	void
740
-	 */
741
-	function setHost($_strHost)
742
-	{
743
-		if ( $_strHost )
744
-		$this->_smtpsHost = $_strHost;
745
-	}
746
-
747
-	/**
748
-	 * Retrieves the Host Name or IP of the Mail Server to use
749
-	 * This is  used only with 'socket' based mail transmission
750
-	 *
751
-	 * @return 	string 	$_strHost 		Host Name or IP of the Mail Server to use
752
-	 */
753
-	function getHost()
754
-	{
755
-		return $this->_smtpsHost;
756
-	}
757
-
758
-	/**
759
-	 * Defines the Port Number of the Mail Server to use
760
-	 * This is defaulted to '25'
761
-	 * This is  used only with 'socket' based mail transmission
762
-	 *
763
-	 * @param 	int 	$_intPort 		Port Number of the Mail Server to use
764
-	 * @return 	void
765
-	 */
766
-	function setPort($_intPort)
767
-	{
768
-		if ( ( is_numeric($_intPort) ) &&
769
-		( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
770
-		$this->_smtpsPort = $_intPort;
771
-	}
772
-
773
-	/**
774
-	 * Retrieves the Port Number of the Mail Server to use
775
-	 * This is  used only with 'socket' based mail transmission
776
-	 *
777
-	 * @return 	string 		Port Number of the Mail Server to use
778
-	 */
779
-	function getPort()
780
-	{
781
-		return $this->_smtpsPort;
782
-	}
783
-
784
-	/**
785
-	 * User Name for authentication on Mail Server
786
-	 *
787
-	 * @param 	string 	$_strID 	User Name for authentication on Mail Server
788
-	 * @return 	void
789
-	 */
790
-	function setID($_strID)
791
-	{
792
-		$this->_smtpsID = $_strID;
793
-	}
794
-
795
-	/**
796
-	 * Retrieves the User Name for authentication on Mail Server
797
-	 *
798
-	 * @return string 	User Name for authentication on Mail Server
799
-	 */
800
-	function getID()
801
-	{
802
-		return $this->_smtpsID;
803
-	}
804
-
805
-	/**
806
-	 * User Password for authentication on Mail Server
807
-	 *
808
-	 * @param 	string 	$_strPW 	User Password for authentication on Mail Server
809
-	 * @return 	void
810
-	 */
811
-	function setPW($_strPW)
812
-	{
813
-		$this->_smtpsPW = $_strPW;
814
-	}
815
-
816
-	/**
817
-	 * Retrieves the User Password for authentication on Mail Server
818
-	 *
819
-	 * @return 	string 		User Password for authentication on Mail Server
820
-	 */
821
-	function getPW()
822
-	{
823
-		return $this->_smtpsPW;
824
-	}
825
-
826
-	/**
827
-	 * Character set used for current message
828
-	 * Character set is defaulted to 'iso-8859-1';
829
-	 *
830
-	 * @param string $_strCharSet Character set used for current message
831
-	 * @return void
832
-	 */
833
-	function setCharSet($_strCharSet)
834
-	{
835
-		if ( $_strCharSet )
836
-		$this->_smtpsCharSet = $_strCharSet;
837
-	}
838
-
839
-	/**
840
-	 * Retrieves the Character set used for current message
841
-	 *
842
-	 * @return string $_smtpsCharSet Character set used for current message
843
-	 */
844
-	function getCharSet()
845
-	{
846
-		return $this->_smtpsCharSet;
847
-	}
848
-
849
-	/**
850
-	 * Content-Transfer-Encoding, Defaulted to '7bit'
851
-	 * This can be changed for 2byte characers sets
852
-	 * Known Encode Types
853
-	 *  - 7bit               Simple 7-bit ASCII
854
-	 *  - 8bit               8-bit coding with line termination characters
855
-	 *  - base64             3 octets encoded into 4 sextets with offset
856
-	 *  - binary             Arbitrary binary stream
857
-	 *  - mac-binhex40       Macintosh binary to hex encoding
858
-	 *  - quoted-printable   Mostly 7-bit, with 8-bit characters encoded as "=HH"
859
-	 *  - uuencode           UUENCODE encoding
860
-	 *
861
-	 * @param string $_strTransEncode Content-Transfer-Encoding
862
-	 * @return void
863
-	 */
864
-	function setTransEncode($_strTransEncode)
865
-	{
866
-		if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes))
867
-		$this->_smtpsTransEncode = $_strTransEncode;
868
-	}
869
-
870
-	/**
871
-	 * Retrieves the Content-Transfer-Encoding
872
-	 *
873
-	 * @return string $_smtpsTransEncode Content-Transfer-Encoding
874
-	 */
875
-	function getTransEncode()
876
-	{
877
-		return $this->_smtpsTransEncode;
878
-	}
879
-
880
-	/**
881
-	 * Content-Transfer-Encoding, Defaulted to '0' [ZERO]
882
-	 * This can be changed for 2byte characers sets
883
-	 * Known Encode Types
884
-	 *  - [0] 7bit               Simple 7-bit ASCII
885
-	 *  - [1] 8bit               8-bit coding with line termination characters
886
-	 *  - [2] base64             3 octets encoded into 4 sextets with offset
887
-	 *  - [3] binary             Arbitrary binary stream
888
-	 *  - [4] mac-binhex40       Macintosh binary to hex encoding
889
-	 *  - [5] quoted-printable   Mostly 7-bit, with 8-bit characters encoded as "=HH"
890
-	 *  - [6] uuencode           UUENCODE encoding
891
-	 *
892
-	 * @param string $_strTransEncodeType Content-Transfer-Encoding
893
-	 * @return void
894
-	 *
895
-	 */
896
-	function setTransEncodeType($_strTransEncodeType)
897
-	{
898
-		if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
899
-		$this->_smtpsTransEncodeType = $_strTransEncodeType;
900
-	}
901
-
902
-	/**
903
-	 * Retrieves the Content-Transfer-Encoding
904
-	 *
905
-	 * @return 	string 		Content-Transfer-Encoding
906
-	 */
907
-	function getTransEncodeType()
908
-	{
909
-		return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
910
-	}
911
-
912
-
913
-	// ** Message Construction
914
-
915
-	/**
916
-	 * FROM Address from which mail will be sent
917
-	 *
918
-	 * @param 	string 	$_strFrom 	Address from which mail will be sent
919
-	 * @return 	void
920
-	 */
921
-	function setFrom($_strFrom)
922
-	{
923
-		if ( $_strFrom )
924
-		$this->_msgFrom = $this->_strip_email($_strFrom);
925
-	}
926
-
927
-	/**
928
-	 * Retrieves the Address from which mail will be sent
929
-	 *
930
-	 * @param  	boolean $_part		To "strip" 'Real name' from address
931
-	 * @return 	string 				Address from which mail will be sent
932
-	 */
933
-	function getFrom($_part = true)
934
-	{
935
-		$_retValue = '';
936
-
937
-		if ( $_part === true )
938
-		$_retValue = $this->_msgFrom;
939
-		else
940
-		$_retValue = $this->_msgFrom[$_part];
941
-
942
-		return $_retValue;
943
-	}
944
-
945
-	/**
946
-	 * Reply-To Address from which mail will be the reply-to
947
-	 *
948
-	 * @param 	string 	$_strReplyTo 	Address from which mail will be the reply-to
949
-	 * @return 	void
950
-	 */
951
-	function setReplyTo($_strReplyTo)
952
-	{
953
-	    if ( $_strReplyTo )
954
-	        $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
955
-	}
956
-
957
-	/**
958
-	 * Retrieves the Address from which mail will be the reply-to
959
-	 *
960
-	 * @param  	boolean $_part		To "strip" 'Real name' from address
961
-	 * @return 	string 				Address from which mail will be the reply-to
962
-	 */
963
-	function getReplyTo($_part = true)
964
-	{
965
-	    $_retValue = '';
966
-
967
-	    if ( $_part === true )
968
-	        $_retValue = $this->_msgReplyTo;
969
-	    else
970
-	        $_retValue = $this->_msgReplyTo[$_part];
971
-
972
-	    return $_retValue;
973
-	}
974
-
975
-	/**
976
-	 * Inserts given addresses into structured format.
977
-	 * This method takes a list of given addresses, via an array
978
-	 * or a COMMA delimted string, and inserts them into a highly
979
-	 * structured array. This array is designed to remove duplicate
980
-	 * addresses and to sort them by Domain.
981
-	 *
982
-	 * @param 	string 	$_type 			TO, CC, or BCC lists to add addrresses into
983
-	 * @param 	mixed 	$_addrList 		Array or COMMA delimited string of addresses
984
-	 * @return void
985
-	 *
986
-	 */
987
-	function _buildAddrList($_type, $_addrList)
988
-	{
989
-		// Pull existing list
990
-		$aryHost = $this->_msgRecipients;
991
-
992
-		// Only run this if we have something
993
-		if ( !empty ($_addrList ))
994
-		{
995
-			// $_addrList can be a STRING or an array
996
-			if ( is_string($_addrList) )
997
-			{
998
-				// This could be a COMMA delimited string
999
-				if ( strstr($_addrList, ',') )
1000
-				// "explode "list" into an array
1001
-				$_addrList = explode(',', $_addrList);
1002
-
1003
-				// Stick it in an array
1004
-				else
1005
-				$_addrList = array($_addrList);
1006
-			}
1007
-
1008
-			// take the array of addresses and split them further
1009
-			foreach ( $_addrList as $_strAddr )
1010
-			{
1011
-				// Strip off the end '>'
1012
-				$_strAddr = str_replace('>', '', $_strAddr);
1013
-
1014
-				// Seperate "Real Name" from eMail address
1015
-				$_tmpaddr = null;
1016
-				$_tmpaddr = explode('<', $_strAddr);
1017
-
1018
-				// We have a "Real Name" and eMail address
1019
-				if ( count($_tmpaddr) == 2 )
1020
-				{
1021
-					$_tmpHost = explode('@', $_tmpaddr[1]);
1022
-					$_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
1023
-					$aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
1024
-				}
1025
-				// We only have an eMail address
1026
-				else
1027
-				{
1028
-					// Strip off the beggining '<'
1029
-					$_strAddr = str_replace('<', '', $_strAddr);
1030
-
1031
-					$_tmpHost = explode('@', $_strAddr);
1032
-					$_tmpHost[0] = trim($_tmpHost[0]);
1033
-					$_tmpHost[1] = trim($_tmpHost[1]);
1034
-
1035
-					$aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
1036
-				}
1037
-			}
1038
-		}
1039
-		// replace list
1040
-		$this->_msgRecipients = $aryHost;
1041
-	}
599
+                    $this->socket_send_str('RCPT TO: <' . $_address . '>', '250');
600
+                }
601
+
602
+                // Tell the server we are ready to start sending data
603
+                // with any custom headers...
604
+                // This is the last response code we look for until the end of the message.
605
+                $this->socket_send_str('DATA', '354');
606
+
607
+                // Now we are ready for the message...
608
+                // Ok, all the ingredients are mixed in let's cook this puppy...
609
+                $this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250');
610
+
611
+                // Now tell the server we are done and close the socket...
612
+                fputs($this->socket, 'QUIT');
613
+                fclose($this->socket);
614
+            }
615
+        }
616
+
617
+        return $_retVal;
618
+    }
619
+
620
+    // =============================================================
621
+    // ** Setter & Getter methods
622
+
623
+    // ** Basic System configuration
624
+
625
+    /**
626
+     * setConfig() is used to populate select class properties from either
627
+     * a user defined INI file or the systems 'php.ini' file
628
+     *
629
+     * If a user defined INI is to be used, the files complete path is passed
630
+     * as the method single parameter. The INI can define any class and/or
631
+     * user properties. Only properties defined within this file will be setter
632
+     * and/or orverwritten
633
+     *
634
+     * If the systems 'php.ini' file is to be used, the method is called without
635
+     * parameters. In this case, only HOST, PORT and FROM properties will be set
636
+     * as they are the only properties that are defined within the 'php.ini'.
637
+     *
638
+     * If secure SMTP is to be used, the user ID and Password can be defined with
639
+     * the user INI file, but the properties are not defined with the systems
640
+     * 'php.ini'file, they must be defined via their setter methods
641
+     *
642
+     * This method can be called twice, if desired. Once without a parameter to
643
+     * load the properties as defined within the systems 'php.ini' file, and a
644
+     * second time, with a path to a user INI file for other properties to be
645
+     * defined.
646
+     *
647
+     * @param mixed $_strConfigPath path to config file or VOID
648
+     * @return boolean
649
+     */
650
+    function setConfig($_strConfigPath = null)
651
+    {
652
+        /**
653
+         * Returns constructed SELECT Object string or boolean upon failure
654
+         * Default value is set at true
655
+         */
656
+        $_retVal = true;
657
+
658
+        // if we have a path...
659
+        if ( ! empty ($_strConfigPath) )
660
+        {
661
+            // If the path is not valid, this will NOT generate an error,
662
+            // it will simply return false.
663
+            if ( ! @include $_strConfigPath)
664
+            {
665
+                $this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.');
666
+                $_retVal = false;
667
+            }
668
+        }
669
+
670
+        // Read the Systems php.ini file
671
+        else
672
+        {
673
+            // Set these properties ONLY if they are set in the php.ini file.
674
+            // Otherwise the default values will be used.
675
+            if ( $_host = ini_get('SMTPs') )
676
+            $this->setHost($_host);
677
+
678
+            if ( $_port = ini_get('smtp_port') )
679
+            $this->setPort($_port);
680
+
681
+            if ( $_from = ini_get('sendmail_from') )
682
+            $this->setFrom($_from);
683
+        }
684
+
685
+        // Send back what we have
686
+        return $_retVal;
687
+    }
688
+
689
+    /**
690
+     * Determines the method inwhich the messages are to be sent.
691
+     * - 'sockets' [0] - conect via network to SMTP server
692
+     * - 'pipe     [1] - use UNIX path to EXE
693
+     * - 'phpmail  [2] - use the PHP built-in mail function
694
+     *
695
+     * @param int $_type  Interger value representing Mail Transport Type
696
+     * @return void
697
+     */
698
+    function setTransportType($_type = 0)
699
+    {
700
+        if ( ( is_numeric($_type) ) &&
701
+        ( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
702
+        $this->_transportType = $_type;
703
+    }
704
+
705
+    /**
706
+     * Return the method inwhich the message is to be sent.
707
+     * - 'sockets' [0] - conect via network to SMTP server
708
+     * - 'pipe     [1] - use UNIX path to EXE
709
+     * - 'phpmail  [2] - use the PHP built-in mail function
710
+     *
711
+     * @return int $_strHost Host Name or IP of the Mail Server to use
712
+     */
713
+    function getTransportType()
714
+    {
715
+        return $this->_transportType;
716
+    }
717
+
718
+    /**
719
+     * Path to the sendmail execuable
720
+     *
721
+     * @param string $_path Path to the sendmail execuable
722
+     * @return boolean
723
+     *
724
+     */
725
+    function setMailPath($_path)
726
+    {
727
+        // This feature is not yet implemented
728
+        return true;
729
+
730
+        //if ( $_path ) $this->_mailPath = $_path;
731
+    }
732
+
733
+    /**
734
+     * Defines the Host Name or IP of the Mail Server to use.
735
+     * This is defaulted to 'localhost'
736
+     * This is  used only with 'socket' based mail transmission
737
+     *
738
+     * @param 	string 	$_strHost 		Host Name or IP of the Mail Server to use
739
+     * @return 	void
740
+     */
741
+    function setHost($_strHost)
742
+    {
743
+        if ( $_strHost )
744
+        $this->_smtpsHost = $_strHost;
745
+    }
746
+
747
+    /**
748
+     * Retrieves the Host Name or IP of the Mail Server to use
749
+     * This is  used only with 'socket' based mail transmission
750
+     *
751
+     * @return 	string 	$_strHost 		Host Name or IP of the Mail Server to use
752
+     */
753
+    function getHost()
754
+    {
755
+        return $this->_smtpsHost;
756
+    }
757
+
758
+    /**
759
+     * Defines the Port Number of the Mail Server to use
760
+     * This is defaulted to '25'
761
+     * This is  used only with 'socket' based mail transmission
762
+     *
763
+     * @param 	int 	$_intPort 		Port Number of the Mail Server to use
764
+     * @return 	void
765
+     */
766
+    function setPort($_intPort)
767
+    {
768
+        if ( ( is_numeric($_intPort) ) &&
769
+        ( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
770
+        $this->_smtpsPort = $_intPort;
771
+    }
772
+
773
+    /**
774
+     * Retrieves the Port Number of the Mail Server to use
775
+     * This is  used only with 'socket' based mail transmission
776
+     *
777
+     * @return 	string 		Port Number of the Mail Server to use
778
+     */
779
+    function getPort()
780
+    {
781
+        return $this->_smtpsPort;
782
+    }
783
+
784
+    /**
785
+     * User Name for authentication on Mail Server
786
+     *
787
+     * @param 	string 	$_strID 	User Name for authentication on Mail Server
788
+     * @return 	void
789
+     */
790
+    function setID($_strID)
791
+    {
792
+        $this->_smtpsID = $_strID;
793
+    }
794
+
795
+    /**
796
+     * Retrieves the User Name for authentication on Mail Server
797
+     *
798
+     * @return string 	User Name for authentication on Mail Server
799
+     */
800
+    function getID()
801
+    {
802
+        return $this->_smtpsID;
803
+    }
804
+
805
+    /**
806
+     * User Password for authentication on Mail Server
807
+     *
808
+     * @param 	string 	$_strPW 	User Password for authentication on Mail Server
809
+     * @return 	void
810
+     */
811
+    function setPW($_strPW)
812
+    {
813
+        $this->_smtpsPW = $_strPW;
814
+    }
815
+
816
+    /**
817
+     * Retrieves the User Password for authentication on Mail Server
818
+     *
819
+     * @return 	string 		User Password for authentication on Mail Server
820
+     */
821
+    function getPW()
822
+    {
823
+        return $this->_smtpsPW;
824
+    }
825
+
826
+    /**
827
+     * Character set used for current message
828
+     * Character set is defaulted to 'iso-8859-1';
829
+     *
830
+     * @param string $_strCharSet Character set used for current message
831
+     * @return void
832
+     */
833
+    function setCharSet($_strCharSet)
834
+    {
835
+        if ( $_strCharSet )
836
+        $this->_smtpsCharSet = $_strCharSet;
837
+    }
838
+
839
+    /**
840
+     * Retrieves the Character set used for current message
841
+     *
842
+     * @return string $_smtpsCharSet Character set used for current message
843
+     */
844
+    function getCharSet()
845
+    {
846
+        return $this->_smtpsCharSet;
847
+    }
848
+
849
+    /**
850
+     * Content-Transfer-Encoding, Defaulted to '7bit'
851
+     * This can be changed for 2byte characers sets
852
+     * Known Encode Types
853
+     *  - 7bit               Simple 7-bit ASCII
854
+     *  - 8bit               8-bit coding with line termination characters
855
+     *  - base64             3 octets encoded into 4 sextets with offset
856
+     *  - binary             Arbitrary binary stream
857
+     *  - mac-binhex40       Macintosh binary to hex encoding
858
+     *  - quoted-printable   Mostly 7-bit, with 8-bit characters encoded as "=HH"
859
+     *  - uuencode           UUENCODE encoding
860
+     *
861
+     * @param string $_strTransEncode Content-Transfer-Encoding
862
+     * @return void
863
+     */
864
+    function setTransEncode($_strTransEncode)
865
+    {
866
+        if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes))
867
+        $this->_smtpsTransEncode = $_strTransEncode;
868
+    }
869
+
870
+    /**
871
+     * Retrieves the Content-Transfer-Encoding
872
+     *
873
+     * @return string $_smtpsTransEncode Content-Transfer-Encoding
874
+     */
875
+    function getTransEncode()
876
+    {
877
+        return $this->_smtpsTransEncode;
878
+    }
879
+
880
+    /**
881
+     * Content-Transfer-Encoding, Defaulted to '0' [ZERO]
882
+     * This can be changed for 2byte characers sets
883
+     * Known Encode Types
884
+     *  - [0] 7bit               Simple 7-bit ASCII
885
+     *  - [1] 8bit               8-bit coding with line termination characters
886
+     *  - [2] base64             3 octets encoded into 4 sextets with offset
887
+     *  - [3] binary             Arbitrary binary stream
888
+     *  - [4] mac-binhex40       Macintosh binary to hex encoding
889
+     *  - [5] quoted-printable   Mostly 7-bit, with 8-bit characters encoded as "=HH"
890
+     *  - [6] uuencode           UUENCODE encoding
891
+     *
892
+     * @param string $_strTransEncodeType Content-Transfer-Encoding
893
+     * @return void
894
+     *
895
+     */
896
+    function setTransEncodeType($_strTransEncodeType)
897
+    {
898
+        if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
899
+        $this->_smtpsTransEncodeType = $_strTransEncodeType;
900
+    }
901
+
902
+    /**
903
+     * Retrieves the Content-Transfer-Encoding
904
+     *
905
+     * @return 	string 		Content-Transfer-Encoding
906
+     */
907
+    function getTransEncodeType()
908
+    {
909
+        return $this->_smtpsTransEncodeTypes[$this->_smtpsTransEncodeType];
910
+    }
911
+
912
+
913
+    // ** Message Construction
914
+
915
+    /**
916
+     * FROM Address from which mail will be sent
917
+     *
918
+     * @param 	string 	$_strFrom 	Address from which mail will be sent
919
+     * @return 	void
920
+     */
921
+    function setFrom($_strFrom)
922
+    {
923
+        if ( $_strFrom )
924
+        $this->_msgFrom = $this->_strip_email($_strFrom);
925
+    }
926
+
927
+    /**
928
+     * Retrieves the Address from which mail will be sent
929
+     *
930
+     * @param  	boolean $_part		To "strip" 'Real name' from address
931
+     * @return 	string 				Address from which mail will be sent
932
+     */
933
+    function getFrom($_part = true)
934
+    {
935
+        $_retValue = '';
936
+
937
+        if ( $_part === true )
938
+        $_retValue = $this->_msgFrom;
939
+        else
940
+        $_retValue = $this->_msgFrom[$_part];
941
+
942
+        return $_retValue;
943
+    }
944
+
945
+    /**
946
+     * Reply-To Address from which mail will be the reply-to
947
+     *
948
+     * @param 	string 	$_strReplyTo 	Address from which mail will be the reply-to
949
+     * @return 	void
950
+     */
951
+    function setReplyTo($_strReplyTo)
952
+    {
953
+        if ( $_strReplyTo )
954
+            $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
955
+    }
956
+
957
+    /**
958
+     * Retrieves the Address from which mail will be the reply-to
959
+     *
960
+     * @param  	boolean $_part		To "strip" 'Real name' from address
961
+     * @return 	string 				Address from which mail will be the reply-to
962
+     */
963
+    function getReplyTo($_part = true)
964
+    {
965
+        $_retValue = '';
966
+
967
+        if ( $_part === true )
968
+            $_retValue = $this->_msgReplyTo;
969
+        else
970
+            $_retValue = $this->_msgReplyTo[$_part];
971
+
972
+        return $_retValue;
973
+    }
974
+
975
+    /**
976
+     * Inserts given addresses into structured format.
977
+     * This method takes a list of given addresses, via an array
978
+     * or a COMMA delimted string, and inserts them into a highly
979
+     * structured array. This array is designed to remove duplicate
980
+     * addresses and to sort them by Domain.
981
+     *
982
+     * @param 	string 	$_type 			TO, CC, or BCC lists to add addrresses into
983
+     * @param 	mixed 	$_addrList 		Array or COMMA delimited string of addresses
984
+     * @return void
985
+     *
986
+     */
987
+    function _buildAddrList($_type, $_addrList)
988
+    {
989
+        // Pull existing list
990
+        $aryHost = $this->_msgRecipients;
991
+
992
+        // Only run this if we have something
993
+        if ( !empty ($_addrList ))
994
+        {
995
+            // $_addrList can be a STRING or an array
996
+            if ( is_string($_addrList) )
997
+            {
998
+                // This could be a COMMA delimited string
999
+                if ( strstr($_addrList, ',') )
1000
+                // "explode "list" into an array
1001
+                $_addrList = explode(',', $_addrList);
1002
+
1003
+                // Stick it in an array
1004
+                else
1005
+                $_addrList = array($_addrList);
1006
+            }
1007
+
1008
+            // take the array of addresses and split them further
1009
+            foreach ( $_addrList as $_strAddr )
1010
+            {
1011
+                // Strip off the end '>'
1012
+                $_strAddr = str_replace('>', '', $_strAddr);
1013
+
1014
+                // Seperate "Real Name" from eMail address
1015
+                $_tmpaddr = null;
1016
+                $_tmpaddr = explode('<', $_strAddr);
1017
+
1018
+                // We have a "Real Name" and eMail address
1019
+                if ( count($_tmpaddr) == 2 )
1020
+                {
1021
+                    $_tmpHost = explode('@', $_tmpaddr[1]);
1022
+                    $_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
1023
+                    $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = $_tmpaddr[0];
1024
+                }
1025
+                // We only have an eMail address
1026
+                else
1027
+                {
1028
+                    // Strip off the beggining '<'
1029
+                    $_strAddr = str_replace('<', '', $_strAddr);
1030
+
1031
+                    $_tmpHost = explode('@', $_strAddr);
1032
+                    $_tmpHost[0] = trim($_tmpHost[0]);
1033
+                    $_tmpHost[1] = trim($_tmpHost[1]);
1034
+
1035
+                    $aryHost[$_tmpHost[1]][$_type][$_tmpHost[0]] = '';
1036
+                }
1037
+            }
1038
+        }
1039
+        // replace list
1040
+        $this->_msgRecipients = $aryHost;
1041
+    }
1042 1042
 
1043 1043
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1044
-	/**
1045
-	 * Returns an array of the various parts of an email address
1046
-	 * This assumes a well formed address:
1047
-	 * - "Real name" <[email protected]>
1048
-	 * - "Real Name" is optional
1049
-	 * - if "Real Name" does not exist, the angle brackets are optional
1050
-	 * This will split an email address into 4 or 5 parts.
1051
-	 * - $_aryEmail[org]  = orignal string
1052
-	 * - $_aryEmail[real] = "real name" - if there is one
1053
-	 * - $_aryEmail[addr] = address part "[email protected]"
1054
-	 * - $_aryEmail[host] = "domain.tld"
1055
-	 * - $_aryEmail[user] = "userName"
1056
-	 *
1057
-	 *	@param		string		$_strAddr		Email address
1058
-	 * 	@return 	array	 					An array of the various parts of an email address
1059
-	 */
1060
-	function _strip_email($_strAddr)
1061
-	{
1044
+    /**
1045
+     * Returns an array of the various parts of an email address
1046
+     * This assumes a well formed address:
1047
+     * - "Real name" <[email protected]>
1048
+     * - "Real Name" is optional
1049
+     * - if "Real Name" does not exist, the angle brackets are optional
1050
+     * This will split an email address into 4 or 5 parts.
1051
+     * - $_aryEmail[org]  = orignal string
1052
+     * - $_aryEmail[real] = "real name" - if there is one
1053
+     * - $_aryEmail[addr] = address part "[email protected]"
1054
+     * - $_aryEmail[host] = "domain.tld"
1055
+     * - $_aryEmail[user] = "userName"
1056
+     *
1057
+     *	@param		string		$_strAddr		Email address
1058
+     * 	@return 	array	 					An array of the various parts of an email address
1059
+     */
1060
+    function _strip_email($_strAddr)
1061
+    {
1062 1062
         // phpcs:enable
1063
-		// Keep the orginal
1064
-		$_aryEmail['org'] = $_strAddr;
1063
+        // Keep the orginal
1064
+        $_aryEmail['org'] = $_strAddr;
1065 1065
 
1066
-		// Set entire string to Lower Case
1067
-		$_strAddr = strtolower($_strAddr);
1066
+        // Set entire string to Lower Case
1067
+        $_strAddr = strtolower($_strAddr);
1068 1068
 
1069
-		// Drop "stuff' off the end
1070
-		$_strAddr = trim($_strAddr, ' ">');
1069
+        // Drop "stuff' off the end
1070
+        $_strAddr = trim($_strAddr, ' ">');
1071 1071
 
1072
-		// Seperate "Real Name" from eMail address, if we have one
1073
-		$_tmpAry = explode('<', $_strAddr);
1072
+        // Seperate "Real Name" from eMail address, if we have one
1073
+        $_tmpAry = explode('<', $_strAddr);
1074 1074
 
1075
-		// Do we have a "Real name"
1076
-		if ( count($_tmpAry) == 2 )
1077
-		{
1078
-			// We may not really have a "Real Name"
1079
-			if ( $_tmpAry[0])
1080
-			$_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1075
+        // Do we have a "Real name"
1076
+        if ( count($_tmpAry) == 2 )
1077
+        {
1078
+            // We may not really have a "Real Name"
1079
+            if ( $_tmpAry[0])
1080
+            $_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1081 1081
 
1082
-			$_aryEmail['addr'] = $_tmpAry[1];
1083
-		}
1084
-		else
1085
-		$_aryEmail['addr'] = $_tmpAry[0];
1082
+            $_aryEmail['addr'] = $_tmpAry[1];
1083
+        }
1084
+        else
1085
+        $_aryEmail['addr'] = $_tmpAry[0];
1086 1086
 
1087
-		// Pull User Name and Host.tld apart
1088
-		list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']);
1087
+        // Pull User Name and Host.tld apart
1088
+        list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']);
1089 1089
 
1090
-		// Put the brackets back around the address
1091
-		$_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>';
1090
+        // Put the brackets back around the address
1091
+        $_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>';
1092 1092
 
1093
-		return $_aryEmail;
1094
-	}
1093
+        return $_aryEmail;
1094
+    }
1095 1095
 
1096 1096
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1097
-	/**
1098
-	 * Returns an array of bares addresses for use with 'RCPT TO:'
1099
-	 * This is a "build as you go" method. Each time this method is called
1100
-	 * the underlaying array is destroyed and reconstructed.
1101
-	 *
1102
-	 * @return 		array		Returns an array of bares addresses
1103
-	 */
1104
-	function get_RCPT_list()
1105
-	{
1097
+    /**
1098
+     * Returns an array of bares addresses for use with 'RCPT TO:'
1099
+     * This is a "build as you go" method. Each time this method is called
1100
+     * the underlaying array is destroyed and reconstructed.
1101
+     *
1102
+     * @return 		array		Returns an array of bares addresses
1103
+     */
1104
+    function get_RCPT_list()
1105
+    {
1106 1106
         // phpcs:enable
1107
-		/**
1108
-		 * An array of bares addresses for use with 'RCPT TO:'
1109
-		 */
1110
-		$_RCPT_list=array();
1111
-
1112
-		// walk down Recipients array and pull just email addresses
1113
-		foreach ( $this->_msgRecipients as $_host => $_list )
1114
-		{
1115
-			foreach ( $_list as $_subList )
1116
-			{
1117
-				foreach ( $_subList as $_name => $_addr )
1118
-				{
1119
-					// build RCPT list
1120
-					$_RCPT_list[] = $_name . '@' . $_host;
1121
-				}
1122
-			}
1123
-		}
1124
-
1125
-		return $_RCPT_list;
1126
-	}
1107
+        /**
1108
+         * An array of bares addresses for use with 'RCPT TO:'
1109
+         */
1110
+        $_RCPT_list=array();
1111
+
1112
+        // walk down Recipients array and pull just email addresses
1113
+        foreach ( $this->_msgRecipients as $_host => $_list )
1114
+        {
1115
+            foreach ( $_list as $_subList )
1116
+            {
1117
+                foreach ( $_subList as $_name => $_addr )
1118
+                {
1119
+                    // build RCPT list
1120
+                    $_RCPT_list[] = $_name . '@' . $_host;
1121
+                }
1122
+            }
1123
+        }
1124
+
1125
+        return $_RCPT_list;
1126
+    }
1127 1127
 
1128 1128
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1129
-	/**
1130
-	 * Returns an array of addresses for a specific type; TO, CC or BCC
1131
-	 *
1132
-	 * @param 		string 	       $_which 	    Which collection of addresses to return ('to', 'cc', 'bcc')
1133
-	 * @return 		string|false 				Array of emaill address
1134
-	 */
1135
-	function get_email_list($_which = null)
1136
-	{
1129
+    /**
1130
+     * Returns an array of addresses for a specific type; TO, CC or BCC
1131
+     *
1132
+     * @param 		string 	       $_which 	    Which collection of addresses to return ('to', 'cc', 'bcc')
1133
+     * @return 		string|false 				Array of emaill address
1134
+     */
1135
+    function get_email_list($_which = null)
1136
+    {
1137 1137
         // phpcs:enable
1138
-		// We need to know which address segment to pull
1139
-		if ( $_which )
1140
-		{
1141
-			// Make sure we have addresses to process
1142
-			if ( $this->_msgRecipients )
1143
-			{
1144
-				$_RCPT_list=array();
1145
-				// walk down Recipients array and pull just email addresses
1146
-				foreach ( $this->_msgRecipients as $_host => $_list )
1147
-				{
1148
-					if ( $this->_msgRecipients[$_host][$_which] )
1149
-					{
1150
-						foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName )
1151
-						{
1152
-							if ( $_realName )	// @CHANGE LDR
1153
-							{
1154
-								$_realName = '"' . $_realName . '"';
1155
-								$_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
1156
-							}
1157
-							else
1158
-							{
1159
-								$_RCPT_list[] = $_addr . '@' . $_host;
1160
-							}
1161
-						}
1162
-					}
1163
-				}
1164
-
1165
-				return implode(', ', $_RCPT_list);
1166
-			}
1167
-			else
1168
-			{
1169
-				$this->_setErr(101, 'No eMail Address for message to be sent to.');
1170
-				return false;
1171
-			}
1172
-		}
1173
-		else
1174
-		{
1175
-			$this->_setErr(102, 'eMail type not defined.');
1176
-			return false;
1177
-		}
1178
-	}
1179
-
1180
-	/**
1181
-	 * TO Address[es] inwhich to send mail to
1182
-	 *
1183
-	 * @param 	string 	$_addrTo 	TO Address[es] inwhich to send mail to
1184
-	 * @return 	void
1185
-	 */
1186
-	function setTO($_addrTo)
1187
-	{
1188
-		if ( $_addrTo )
1189
-		$this->_buildAddrList('to', $_addrTo);
1190
-	}
1191
-
1192
-	/**
1193
-	 * Retrieves the TO Address[es] inwhich to send mail to
1194
-	 *
1195
-	 * @return 	string 	TO Address[es] inwhich to send mail to
1196
-	 */
1197
-	function getTo()
1198
-	{
1199
-		return $this->get_email_list('to');
1200
-	}
1201
-
1202
-	/**
1203
-	 * CC Address[es] inwhich to send mail to
1204
-	 *
1205
-	 * @param 	string	$_strCC		CC Address[es] inwhich to send mail to
1206
-	 * @return 	void
1207
-	 */
1208
-	function setCC($_strCC)
1209
-	{
1210
-		if ( $_strCC )
1211
-		$this->_buildAddrList('cc', $_strCC);
1212
-	}
1213
-
1214
-	/**
1215
-	 * Retrieves the CC Address[es] inwhich to send mail to
1216
-	 *
1217
-	 * @return 	string 		CC Address[es] inwhich to send mail to
1218
-	 */
1219
-	function getCC()
1220
-	{
1221
-		return $this->get_email_list('cc');
1222
-	}
1223
-
1224
-	/**
1225
-	 * BCC Address[es] inwhich to send mail to
1226
-	 *
1227
-	 * @param 	string		$_strBCC	Recipients BCC Address[es] inwhich to send mail to
1228
-	 * @return 	void
1229
-	 */
1230
-	function setBCC($_strBCC)
1231
-	{
1232
-		if ( $_strBCC )
1233
-		$this->_buildAddrList('bcc', $_strBCC);
1234
-	}
1235
-
1236
-	/**
1237
-	 * Retrieves the BCC Address[es] inwhich to send mail to
1238
-	 *
1239
-	 * @return 	string		BCC Address[es] inwhich to send mail to
1240
-	 */
1241
-	function getBCC()
1242
-	{
1243
-		return $this->get_email_list('bcc');
1244
-	}
1245
-
1246
-	/**
1247
-	 * Message Subject
1248
-	 *
1249
-	 * @param 	string 	$_strSubject	Message Subject
1250
-	 * @return 	void
1251
-	 */
1252
-	function setSubject($_strSubject = '')
1253
-	{
1254
-		if ( $_strSubject )
1255
-		$this->_msgSubject = $_strSubject;
1256
-	}
1257
-
1258
-	/**
1259
-	 * Retrieves the Message Subject
1260
-	 *
1261
-	 * @return 	string 		Message Subject
1262
-	 */
1263
-	function getSubject()
1264
-	{
1265
-		return $this->_msgSubject;
1266
-	}
1267
-
1268
-	/**
1269
-	 * Constructes and returns message header
1270
-	 *
1271
-	 * @return string Complete message header
1272
-	 */
1273
-	function getHeader()
1274
-	{
1275
-		global $conf;
1276
-
1277
-		$_header = 'From: '       . $this->getFrom('org') . "\r\n"
1278
-		. 'To: '         . $this->getTO()          . "\r\n";
1279
-
1280
-		if ( $this->getCC() )
1281
-		$_header .= 'Cc: ' . $this->getCC()  . "\r\n";
1282
-
1283
-		/* Note:
1138
+        // We need to know which address segment to pull
1139
+        if ( $_which )
1140
+        {
1141
+            // Make sure we have addresses to process
1142
+            if ( $this->_msgRecipients )
1143
+            {
1144
+                $_RCPT_list=array();
1145
+                // walk down Recipients array and pull just email addresses
1146
+                foreach ( $this->_msgRecipients as $_host => $_list )
1147
+                {
1148
+                    if ( $this->_msgRecipients[$_host][$_which] )
1149
+                    {
1150
+                        foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName )
1151
+                        {
1152
+                            if ( $_realName )	// @CHANGE LDR
1153
+                            {
1154
+                                $_realName = '"' . $_realName . '"';
1155
+                                $_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
1156
+                            }
1157
+                            else
1158
+                            {
1159
+                                $_RCPT_list[] = $_addr . '@' . $_host;
1160
+                            }
1161
+                        }
1162
+                    }
1163
+                }
1164
+
1165
+                return implode(', ', $_RCPT_list);
1166
+            }
1167
+            else
1168
+            {
1169
+                $this->_setErr(101, 'No eMail Address for message to be sent to.');
1170
+                return false;
1171
+            }
1172
+        }
1173
+        else
1174
+        {
1175
+            $this->_setErr(102, 'eMail type not defined.');
1176
+            return false;
1177
+        }
1178
+    }
1179
+
1180
+    /**
1181
+     * TO Address[es] inwhich to send mail to
1182
+     *
1183
+     * @param 	string 	$_addrTo 	TO Address[es] inwhich to send mail to
1184
+     * @return 	void
1185
+     */
1186
+    function setTO($_addrTo)
1187
+    {
1188
+        if ( $_addrTo )
1189
+        $this->_buildAddrList('to', $_addrTo);
1190
+    }
1191
+
1192
+    /**
1193
+     * Retrieves the TO Address[es] inwhich to send mail to
1194
+     *
1195
+     * @return 	string 	TO Address[es] inwhich to send mail to
1196
+     */
1197
+    function getTo()
1198
+    {
1199
+        return $this->get_email_list('to');
1200
+    }
1201
+
1202
+    /**
1203
+     * CC Address[es] inwhich to send mail to
1204
+     *
1205
+     * @param 	string	$_strCC		CC Address[es] inwhich to send mail to
1206
+     * @return 	void
1207
+     */
1208
+    function setCC($_strCC)
1209
+    {
1210
+        if ( $_strCC )
1211
+        $this->_buildAddrList('cc', $_strCC);
1212
+    }
1213
+
1214
+    /**
1215
+     * Retrieves the CC Address[es] inwhich to send mail to
1216
+     *
1217
+     * @return 	string 		CC Address[es] inwhich to send mail to
1218
+     */
1219
+    function getCC()
1220
+    {
1221
+        return $this->get_email_list('cc');
1222
+    }
1223
+
1224
+    /**
1225
+     * BCC Address[es] inwhich to send mail to
1226
+     *
1227
+     * @param 	string		$_strBCC	Recipients BCC Address[es] inwhich to send mail to
1228
+     * @return 	void
1229
+     */
1230
+    function setBCC($_strBCC)
1231
+    {
1232
+        if ( $_strBCC )
1233
+        $this->_buildAddrList('bcc', $_strBCC);
1234
+    }
1235
+
1236
+    /**
1237
+     * Retrieves the BCC Address[es] inwhich to send mail to
1238
+     *
1239
+     * @return 	string		BCC Address[es] inwhich to send mail to
1240
+     */
1241
+    function getBCC()
1242
+    {
1243
+        return $this->get_email_list('bcc');
1244
+    }
1245
+
1246
+    /**
1247
+     * Message Subject
1248
+     *
1249
+     * @param 	string 	$_strSubject	Message Subject
1250
+     * @return 	void
1251
+     */
1252
+    function setSubject($_strSubject = '')
1253
+    {
1254
+        if ( $_strSubject )
1255
+        $this->_msgSubject = $_strSubject;
1256
+    }
1257
+
1258
+    /**
1259
+     * Retrieves the Message Subject
1260
+     *
1261
+     * @return 	string 		Message Subject
1262
+     */
1263
+    function getSubject()
1264
+    {
1265
+        return $this->_msgSubject;
1266
+    }
1267
+
1268
+    /**
1269
+     * Constructes and returns message header
1270
+     *
1271
+     * @return string Complete message header
1272
+     */
1273
+    function getHeader()
1274
+    {
1275
+        global $conf;
1276
+
1277
+        $_header = 'From: '       . $this->getFrom('org') . "\r\n"
1278
+        . 'To: '         . $this->getTO()          . "\r\n";
1279
+
1280
+        if ( $this->getCC() )
1281
+        $_header .= 'Cc: ' . $this->getCC()  . "\r\n";
1282
+
1283
+        /* Note:
1284 1284
 		 * BCC email addresses must be listed in the RCPT TO command list,
1285 1285
 		 * but the BCC header should not be printed under the DATA command.
1286 1286
 		 * So it is included into the function sendMsg() but not here.
1287 1287
 		 * http://stackoverflow.com/questions/2750211/sending-bcc-emails-using-a-smtp-server
1288 1288
 		 */
1289
-		/*
1289
+        /*
1290 1290
 		if ( $this->getBCC() )
1291 1291
 		$_header .= 'Bcc: ' . $this->getBCC()  . "\r\n";
1292 1292
         */
1293 1293
 
1294
-		$host=$this->getHost();
1295
-		$usetls = preg_match('@tls://@i',$host);
1296
-
1297
-		$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
1298
-		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
1299
-		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
1300
-
1301
-		$host=dol_getprefix('email');
1302
-
1303
-		//NOTE: Message-ID should probably contain the username of the user who sent the msg
1304
-		$_header .= 'Subject: '    . $this->getSubject()     . "\r\n";
1305
-		$_header .= 'Date: '       . date("r")               . "\r\n";
1306
-
1307
-		$trackid = $this->getTrackId();
1308
-		if ($trackid)
1309
-		{
1310
-			// References is kept in response and Message-ID is returned into In-Reply-To:
1311
-			$_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1312
-			$_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1313
-			$_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n";
1314
-		}
1315
-		else
1316
-		{
1317
-			$_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
1318
-		}
1319
-		if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n";
1320
-		if ( $this->getMoreInHeader() )
1321
-		    $_header .= $this->getMoreInHeader();     // Value must include the "\r\n";
1322
-
1323
-		//$_header .=
1324
-		//                 'Read-Receipt-To: '   . $this->getFrom( 'org' ) . "\r\n"
1325
-		//                 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
1326
-
1327
-		if ( $this->getSensitivity() )
1328
-		$_header .= 'Sensitivity: ' . $this->getSensitivity()  . "\r\n";
1329
-
1330
-		if ( $this->_msgPriority != 3 )
1331
-		$_header .= $this->getPriority();
1332
-
1333
-
1334
-		// @CHANGE LDR
1335
-		if ( $this->getDeliveryReceipt() )
1336
-		    $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
1337
-		if ( $this->getErrorsTo() )
1338
-		    $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
1339
-		if ( $this->getReplyTo() )
1340
-		    $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
1341
-
1342
-		$_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n";
1343
-		$_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n";
1344
-		$_header .= 'Mime-Version: 1.0' . "\r\n";
1345
-
1346
-
1347
-		return $_header;
1348
-	}
1349
-
1350
-	/**
1351
-	 * Message Content
1352
-	 *
1353
-	 * @param 	string 	$strContent		Message Content
1354
-	 * @param	string	$strType		Type
1355
-	 * @return 	void
1356
-	 */
1357
-	function setBodyContent($strContent, $strType = 'plain')
1358
-	{
1359
-		//if ( $strContent )
1360
-		//{
1361
-		if ( $strType == 'html' )
1362
-		$strMimeType = 'text/html';
1363
-		else
1364
-		$strMimeType = 'text/plain';
1365
-
1366
-		// Make RFC821 Compliant, replace bare linefeeds
1367
-		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent);
1368
-
1369
-		$strContentAltText = '';
1370
-		if ($strType == 'html')
1371
-		{
1372
-			// Similar code to forge a text from html is also in CMailFile.class.php
1373
-			$strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1374
-			$strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1375
-			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n"));
1376
-		}
1377
-
1378
-		// Make RFC2045 Compliant
1379
-		//$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1380
-		$strContent = rtrim(wordwrap($strContent, 75, "\r\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1381
-
1382
-		$this->_msgContent[$strType] = array();
1383
-
1384
-		$this->_msgContent[$strType]['mimeType'] = $strMimeType;
1385
-		$this->_msgContent[$strType]['data']     = $strContent;
1386
-		$this->_msgContent[$strType]['dataText'] = $strContentAltText;
1387
-
1388
-		if ( $this->getMD5flag() )
1389
-		$this->_msgContent[$strType]['md5']      = dol_hash($strContent, 3);
1390
-		//}
1391
-	}
1392
-
1393
-	/**
1394
-	 * Retrieves the Message Content
1395
-	 *
1396
-	 * @return 	string			Message Content
1397
-	 */
1398
-	function getBodyContent()
1399
-	{
1400
-	    global $conf;
1401
-
1402
-		// Generate a new Boundary string
1403
-		$this->_setBoundary();
1404
-
1405
-		// What type[s] of content do we have
1406
-		$_types = array_keys($this->_msgContent);
1407
-
1408
-		// How many content types do we have
1409
-		$keyCount = count($_types);
1410
-
1411
-		// If we have ZERO, we have a problem
1412
-		if( $keyCount === 0 )
1413
-		die ("Sorry, no content");
1414
-
1415
-		// If we have ONE, we can use the simple format
1416
-		else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1417
-		{
1418
-			$_msgData = $this->_msgContent;
1419
-			$_msgData = $_msgData[$_types[0]];
1420
-
1421
-			$content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n"
1422
-			. 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n"
1423
-			. 'Content-Disposition: inline'  . "\r\n"
1424
-			. 'Content-Description: Message' . "\r\n";
1425
-
1426
-			if ( $this->getMD5flag() )
1427
-			$content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
1428
-
1429
-			$content .= "\r\n"
1430
-			.  $_msgData['data'] . "\r\n";
1431
-		}
1432
-
1433
-		// If we have more than ONE, we use the multi-part format
1434
-		else if( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1435
-		{
1436
-			// Since this is an actual multi-part message
1437
-			// We need to define a content message Boundary
1438
-			// NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
1439
-
1440
-			//$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"'   . "\r\n";
1441
-			$content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"'   . "\r\n";
1442
-
1443
-			//                     . "\r\n"
1444
-			//                     . 'This is a multi-part message in MIME format.' . "\r\n";
1445
-			$content .= "Content-Transfer-Encoding: 8bit\r\n";
1446
-			$content .= "\r\n";
1447
-
1448
-			$content .= "--" . $this->_getBoundary('mixed') . "\r\n";
1449
-
1450
-			if (key_exists('image', $this->_msgContent))     // If inline image found
1451
-			{
1452
-				$content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1453
-				$content .= "\r\n";
1454
-				$content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1455
-			}
1456
-
1457
-
1458
-			// $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment'
1459
-
1460
-
1461
-			// Loop through message content array
1462
-			foreach ($this->_msgContent as $type => $_content )
1463
-			{
1464
-				if ( $type == 'attachment' )
1465
-				{
1466
-					// loop through all attachments
1467
-					foreach ( $_content as $_file => $_data )
1468
-					{
1469
-						$content .= "--" . $this->_getBoundary('mixed') . "\r\n"
1470
-						.  'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n"
1471
-						.  'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n"
1472
-						.  'Content-Transfer-Encoding: base64' . "\r\n"
1473
-						.  'Content-Description: ' . $_data['fileName'] ."\r\n";
1474
-
1475
-						if ( $this->getMD5flag() )
1476
-						$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1477
-
1478
-						$content .= "\r\n" .  $_data['data'] . "\r\n\r\n";
1479
-					}
1480
-				}
1481
-				// @CHANGE LDR
1482
-				else if ( $type == 'image' )
1483
-				{
1484
-					// loop through all images
1485
-					foreach ( $_content as $_image => $_data )
1486
-					{
1487
-						$content .= "--" . $this->_getBoundary('related') . "\r\n";  // always related for an inline image
1488
-
1489
-						$content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
1490
-						.  'Content-Transfer-Encoding: base64' . "\r\n"
1491
-						.  'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
1492
-						.  'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
1493
-
1494
-						if ( $this->getMD5flag() )
1495
-						$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1496
-
1497
-						$content .= "\r\n"
1498
-						. $_data['data'] . "\r\n";
1499
-					}
1500
-
1501
-					// always end related and end alternative after inline images
1502
-					$content.= "--" . $this->_getBoundary('related') . "--" . "\r\n";
1503
-					$content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n";
1504
-					$content.= "\r\n";
1505
-				}
1506
-				else
1507
-				{
1508
-					if (key_exists('image', $this->_msgContent))
1509
-					{
1510
-						$content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
1511
-						$content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message
1512
-						$content.= "--" . $this->_getBoundary('alternative') . "\r\n";
1513
-						$content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n";
1514
-						$content.= "\r\n";
1515
-						$content.= "--" . $this->_getBoundary('related') . "\r\n";
1516
-					}
1517
-
1518
-					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part before html part
1519
-					{
1520
-					    $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1521
-    					$content .= "\r\n";
1522
-	       				$content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1523
-
1524
-	       				$content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
1525
-	       				$content.= "\r\n". $_content['dataText'] . "\r\n";
1526
-	       				$content.= "--" . $this->_getBoundary('alternative') . "\r\n";
1527
-					}
1528
-
1529
-					$content .= 'Content-Type: ' . $_content['mimeType'] . '; '
1530
-					//                             . 'charset="' . $this->getCharSet() . '"';
1531
-					. 'charset=' . $this->getCharSet() . '';
1532
-
1533
-					//                    $content .= ( $type == 'html') ? '; name="HTML Part"' : '';
1534
-					$content .=  "\r\n";
1535
-					//                    $content .= 'Content-Transfer-Encoding: ';
1536
-					//                    $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
1537
-					//                    $content .=  "\r\n"
1538
-					//                             . 'Content-Disposition: inline'  . "\r\n"
1539
-					//                             . 'Content-Description: ' . $type . ' message' . "\r\n";
1540
-
1541
-					if ( $this->getMD5flag() )
1542
-					$content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
1543
-
1544
-					$content .= "\r\n"	. $_content['data'] . "\r\n";
1545
-
1546
-					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part after html part
1547
-					{
1548
-					    $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n";
1549
-					}
1550
-
1551
-					$content .= "\r\n";
1552
-				}
1553
-			}
1554
-
1555
-			// Close message boundries
1556
-			//            $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ;
1557
-			$content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ;
1558
-		}
1559
-
1560
-		return $content;
1561
-	}
1562
-
1563
-	/**
1564
-	 * File attachments are added to the content array as sub-arrays,
1565
-	 * allowing for multiple attachments for each outbound email
1566
-	 *
1567
-	 * @param string $strContent  File data to attach to message
1568
-	 * @param string $strFileName File Name to give to attachment
1569
-	 * @param string $strMimeType File Mime Type of attachment
1570
-	 * @return void
1571
-	 */
1572
-	function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
1573
-	{
1574
-		if ( $strContent )
1575
-		{
1576
-			$strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n"));    // 76 max is defined into http://tools.ietf.org/html/rfc2047
1577
-
1578
-			$this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
1579
-			$this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
1580
-			$this->_msgContent['attachment'][$strFileName]['data']     = $strContent;
1581
-
1582
-			if ( $this->getMD5flag() )
1583
-			$this->_msgContent['attachment'][$strFileName]['md5']      = dol_hash($strContent, 3);
1584
-		}
1585
-	}
1586
-
1587
-
1588
-	// @CHANGE LDR
1589
-
1590
-	/**
1591
-	 * Image attachments are added to the content array as sub-arrays,
1592
-	 * allowing for multiple images for each outbound email
1593
-	 *
1594
-	 * @param 	string $strContent  	Image data to attach to message
1595
-	 * @param 	string $strImageName 	Image Name to give to attachment
1596
-	 * @param 	string $strMimeType 	Image Mime Type of attachment
1597
-	 * @param 	string $strImageCid		CID
1598
-	 * @return 	void
1599
-	 */
1600
-	function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown')
1601
-	{
1602
-		if ($strContent)
1603
-		{
1604
-			$this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType;
1605
-			$this->_msgContent['image'][$strImageName]['imageName'] = $strImageName;
1606
-			$this->_msgContent['image'][$strImageName]['cid']      = $strImageCid;
1607
-			$this->_msgContent['image'][$strImageName]['data']     = $strContent;
1608
-
1609
-			if ( $this->getMD5flag() )
1610
-			$this->_msgContent['image'][$strImageName]['md5']      = dol_hash($strContent, 3);
1611
-		}
1612
-	}
1613
-	// END @CHANGE LDR
1614
-
1615
-
1616
-	/**
1617
-	 * Message Content Sensitivity
1618
-	 * Message Sensitivity values:
1619
-	 *   - [0] None - default
1620
-	 *   - [1] Personal
1621
-	 *   - [2] Private
1622
-	 *   - [3] Company Confidential
1623
-	 *
1624
-	 * @param 	integer	$_value		Message Sensitivity
1625
-	 * @return 	void
1626
-	 */
1627
-	function setSensitivity($_value = 0)
1628
-	{
1629
-		if ( ( is_numeric($_value) ) &&
1630
-		( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
1631
-		$this->_msgSensitivity = $_value;
1632
-	}
1633
-
1634
-	/**
1635
-	 * Returns Message Content Sensitivity string
1636
-	 * Message Sensitivity values:
1637
-	 *   - [0] None - default
1638
-	 *   - [1] Personal
1639
-	 *   - [2] Private
1640
-	 *   - [3] Company Confidential
1641
-	 *
1642
-	 * @return 	void
1643
-	 */
1644
-	function getSensitivity()
1645
-	{
1646
-		return $this->_arySensitivity[$this->_msgSensitivity];
1647
-	}
1648
-
1649
-	/**
1650
-	 * Message Content Priority
1651
-	 * Message Priority values:
1652
-	 *  - [0] 'Bulk'
1653
-	 *  - [1] 'Highest'
1654
-	 *  - [2] 'High'
1655
-	 *  - [3] 'Normal' - default
1656
-	 *  - [4] 'Low'
1657
-	 *  - [5] 'Lowest'
1658
-	 *
1659
-	 * @param 	integer 	$_value 	Message Priority
1660
-	 * @return 	void
1661
-	 */
1662
-	function setPriority( $_value = 3 )
1663
-	{
1664
-		if ( ( is_numeric($_value) ) &&
1665
-		( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
1666
-		$this->_msgPriority = $_value;
1667
-	}
1668
-
1669
-	/**
1670
-	 * Message Content Priority
1671
-	 * Message Priority values:
1672
-	 *  - [0] 'Bulk'
1673
-	 *  - [1] 'Highest'
1674
-	 *  - [2] 'High'
1675
-	 *  - [3] 'Normal' - default
1676
-	 *  - [4] 'Low'
1677
-	 *  - [5] 'Lowest'
1678
-	 *
1679
-	 * @return string
1680
-	 */
1681
-	function getPriority()
1682
-	{
1683
-		return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
1684
-		. 'Priority: '   . $this->_aryPriority[$this->_msgPriority] . "\r\n"
1685
-		. 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n";
1686
-	}
1687
-
1688
-	/**
1689
-	 * Set flag which determines whether to calculate message MD5 checksum.
1690
-	 *
1691
-	 * @param 	string 	$_flag		Message Priority
1692
-	 * @return 	void
1693
-	 */
1694
-	function setMD5flag($_flag = false)
1695
-	{
1696
-		$this->_smtpMD5 = $_flag;
1697
-	}
1698
-
1699
-	/**
1700
-	 * Gets flag which determines whether to calculate message MD5 checksum.
1701
-	 *
1702
-	 * @return 	boolean 				Message Priority
1703
-	 */
1704
-	function getMD5flag()
1705
-	{
1706
-		return $this->_smtpMD5;
1707
-	}
1708
-
1709
-	/**
1710
-	 * Message X-Header Content
1711
-	 * This is a simple "insert". Whatever is given will be placed
1712
-	 * "as is" into the Xheader array.
1713
-	 *
1714
-	 * @param string $strXdata Message X-Header Content
1715
-	 * @return void
1716
-	 */
1717
-	function setXheader($strXdata)
1718
-	{
1719
-		if ( $strXdata )
1720
-		$this->_msgXheader[] = $strXdata;
1721
-	}
1722
-
1723
-	/**
1724
-	 * Retrieves the Message X-Header Content
1725
-	 *
1726
-	 * @return string[] $_msgContent Message X-Header Content
1727
-	 */
1728
-	function getXheader()
1729
-	{
1730
-		return $this->_msgXheader;
1731
-	}
1732
-
1733
-	/**
1734
-	 * Generates Random string for MIME message Boundary
1735
-	 *
1736
-	 * @return void
1737
-	 */
1738
-	function _setBoundary()
1739
-	{
1740
-		$this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary";
1741
-		$this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);
1742
-		$this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);
1743
-	}
1744
-
1745
-	/**
1746
-	 * Retrieves the MIME message Boundary
1747
-	 *
1748
-	 * @param  string $type				Type of boundary
1749
-	 * @return string $_smtpsBoundary 	MIME message Boundary
1750
-	 */
1751
-	function _getBoundary($type='mixed')
1752
-	{
1753
-		if ($type == 'mixed') return $this->_smtpsBoundary;
1754
-		else if ($type == 'related') return $this->_smtpsRelatedBoundary;
1755
-		else if ($type == 'alternative') return $this->_smtpsAlternativeBoundary;
1756
-	}
1294
+        $host=$this->getHost();
1295
+        $usetls = preg_match('@tls://@i',$host);
1296
+
1297
+        $host=preg_replace('@tcp://@i','',$host);	// Remove prefix
1298
+        $host=preg_replace('@ssl://@i','',$host);	// Remove prefix
1299
+        $host=preg_replace('@tls://@i','',$host);	// Remove prefix
1300
+
1301
+        $host=dol_getprefix('email');
1302
+
1303
+        //NOTE: Message-ID should probably contain the username of the user who sent the msg
1304
+        $_header .= 'Subject: '    . $this->getSubject()     . "\r\n";
1305
+        $_header .= 'Date: '       . date("r")               . "\r\n";
1306
+
1307
+        $trackid = $this->getTrackId();
1308
+        if ($trackid)
1309
+        {
1310
+            // References is kept in response and Message-ID is returned into In-Reply-To:
1311
+            $_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1312
+            $_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1313
+            $_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n";
1314
+        }
1315
+        else
1316
+        {
1317
+            $_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
1318
+        }
1319
+        if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n";
1320
+        if ( $this->getMoreInHeader() )
1321
+            $_header .= $this->getMoreInHeader();     // Value must include the "\r\n";
1322
+
1323
+        //$_header .=
1324
+        //                 'Read-Receipt-To: '   . $this->getFrom( 'org' ) . "\r\n"
1325
+        //                 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
1326
+
1327
+        if ( $this->getSensitivity() )
1328
+        $_header .= 'Sensitivity: ' . $this->getSensitivity()  . "\r\n";
1329
+
1330
+        if ( $this->_msgPriority != 3 )
1331
+        $_header .= $this->getPriority();
1332
+
1333
+
1334
+        // @CHANGE LDR
1335
+        if ( $this->getDeliveryReceipt() )
1336
+            $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
1337
+        if ( $this->getErrorsTo() )
1338
+            $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
1339
+        if ( $this->getReplyTo() )
1340
+            $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
1341
+
1342
+        $_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n";
1343
+        $_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n";
1344
+        $_header .= 'Mime-Version: 1.0' . "\r\n";
1345
+
1346
+
1347
+        return $_header;
1348
+    }
1349
+
1350
+    /**
1351
+     * Message Content
1352
+     *
1353
+     * @param 	string 	$strContent		Message Content
1354
+     * @param	string	$strType		Type
1355
+     * @return 	void
1356
+     */
1357
+    function setBodyContent($strContent, $strType = 'plain')
1358
+    {
1359
+        //if ( $strContent )
1360
+        //{
1361
+        if ( $strType == 'html' )
1362
+        $strMimeType = 'text/html';
1363
+        else
1364
+        $strMimeType = 'text/plain';
1365
+
1366
+        // Make RFC821 Compliant, replace bare linefeeds
1367
+        $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent);
1368
+
1369
+        $strContentAltText = '';
1370
+        if ($strType == 'html')
1371
+        {
1372
+            // Similar code to forge a text from html is also in CMailFile.class.php
1373
+            $strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1374
+            $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1375
+            $strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n"));
1376
+        }
1377
+
1378
+        // Make RFC2045 Compliant
1379
+        //$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1380
+        $strContent = rtrim(wordwrap($strContent, 75, "\r\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1381
+
1382
+        $this->_msgContent[$strType] = array();
1383
+
1384
+        $this->_msgContent[$strType]['mimeType'] = $strMimeType;
1385
+        $this->_msgContent[$strType]['data']     = $strContent;
1386
+        $this->_msgContent[$strType]['dataText'] = $strContentAltText;
1387
+
1388
+        if ( $this->getMD5flag() )
1389
+        $this->_msgContent[$strType]['md5']      = dol_hash($strContent, 3);
1390
+        //}
1391
+    }
1392
+
1393
+    /**
1394
+     * Retrieves the Message Content
1395
+     *
1396
+     * @return 	string			Message Content
1397
+     */
1398
+    function getBodyContent()
1399
+    {
1400
+        global $conf;
1401
+
1402
+        // Generate a new Boundary string
1403
+        $this->_setBoundary();
1404
+
1405
+        // What type[s] of content do we have
1406
+        $_types = array_keys($this->_msgContent);
1407
+
1408
+        // How many content types do we have
1409
+        $keyCount = count($_types);
1410
+
1411
+        // If we have ZERO, we have a problem
1412
+        if( $keyCount === 0 )
1413
+        die ("Sorry, no content");
1414
+
1415
+        // If we have ONE, we can use the simple format
1416
+        else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1417
+        {
1418
+            $_msgData = $this->_msgContent;
1419
+            $_msgData = $_msgData[$_types[0]];
1420
+
1421
+            $content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n"
1422
+            . 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n"
1423
+            . 'Content-Disposition: inline'  . "\r\n"
1424
+            . 'Content-Description: Message' . "\r\n";
1425
+
1426
+            if ( $this->getMD5flag() )
1427
+            $content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
1428
+
1429
+            $content .= "\r\n"
1430
+            .  $_msgData['data'] . "\r\n";
1431
+        }
1432
+
1433
+        // If we have more than ONE, we use the multi-part format
1434
+        else if( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1435
+        {
1436
+            // Since this is an actual multi-part message
1437
+            // We need to define a content message Boundary
1438
+            // NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
1439
+
1440
+            //$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"'   . "\r\n";
1441
+            $content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"'   . "\r\n";
1442
+
1443
+            //                     . "\r\n"
1444
+            //                     . 'This is a multi-part message in MIME format.' . "\r\n";
1445
+            $content .= "Content-Transfer-Encoding: 8bit\r\n";
1446
+            $content .= "\r\n";
1447
+
1448
+            $content .= "--" . $this->_getBoundary('mixed') . "\r\n";
1449
+
1450
+            if (key_exists('image', $this->_msgContent))     // If inline image found
1451
+            {
1452
+                $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1453
+                $content .= "\r\n";
1454
+                $content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1455
+            }
1456
+
1457
+
1458
+            // $this->_msgContent must be sorted with key 'text' or 'html' first then 'image' then 'attachment'
1459
+
1460
+
1461
+            // Loop through message content array
1462
+            foreach ($this->_msgContent as $type => $_content )
1463
+            {
1464
+                if ( $type == 'attachment' )
1465
+                {
1466
+                    // loop through all attachments
1467
+                    foreach ( $_content as $_file => $_data )
1468
+                    {
1469
+                        $content .= "--" . $this->_getBoundary('mixed') . "\r\n"
1470
+                        .  'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n"
1471
+                        .  'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n"
1472
+                        .  'Content-Transfer-Encoding: base64' . "\r\n"
1473
+                        .  'Content-Description: ' . $_data['fileName'] ."\r\n";
1474
+
1475
+                        if ( $this->getMD5flag() )
1476
+                        $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1477
+
1478
+                        $content .= "\r\n" .  $_data['data'] . "\r\n\r\n";
1479
+                    }
1480
+                }
1481
+                // @CHANGE LDR
1482
+                else if ( $type == 'image' )
1483
+                {
1484
+                    // loop through all images
1485
+                    foreach ( $_content as $_image => $_data )
1486
+                    {
1487
+                        $content .= "--" . $this->_getBoundary('related') . "\r\n";  // always related for an inline image
1488
+
1489
+                        $content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
1490
+                        .  'Content-Transfer-Encoding: base64' . "\r\n"
1491
+                        .  'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
1492
+                        .  'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
1493
+
1494
+                        if ( $this->getMD5flag() )
1495
+                        $content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1496
+
1497
+                        $content .= "\r\n"
1498
+                        . $_data['data'] . "\r\n";
1499
+                    }
1500
+
1501
+                    // always end related and end alternative after inline images
1502
+                    $content.= "--" . $this->_getBoundary('related') . "--" . "\r\n";
1503
+                    $content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n";
1504
+                    $content.= "\r\n";
1505
+                }
1506
+                else
1507
+                {
1508
+                    if (key_exists('image', $this->_msgContent))
1509
+                    {
1510
+                        $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
1511
+                        $content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message
1512
+                        $content.= "--" . $this->_getBoundary('alternative') . "\r\n";
1513
+                        $content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n";
1514
+                        $content.= "\r\n";
1515
+                        $content.= "--" . $this->_getBoundary('related') . "\r\n";
1516
+                    }
1517
+
1518
+                    if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part before html part
1519
+                    {
1520
+                        $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1521
+                        $content .= "\r\n";
1522
+                            $content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1523
+
1524
+                            $content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
1525
+                            $content.= "\r\n". $_content['dataText'] . "\r\n";
1526
+                            $content.= "--" . $this->_getBoundary('alternative') . "\r\n";
1527
+                    }
1528
+
1529
+                    $content .= 'Content-Type: ' . $_content['mimeType'] . '; '
1530
+                    //                             . 'charset="' . $this->getCharSet() . '"';
1531
+                    . 'charset=' . $this->getCharSet() . '';
1532
+
1533
+                    //                    $content .= ( $type == 'html') ? '; name="HTML Part"' : '';
1534
+                    $content .=  "\r\n";
1535
+                    //                    $content .= 'Content-Transfer-Encoding: ';
1536
+                    //                    $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
1537
+                    //                    $content .=  "\r\n"
1538
+                    //                             . 'Content-Disposition: inline'  . "\r\n"
1539
+                    //                             . 'Content-Description: ' . $type . ' message' . "\r\n";
1540
+
1541
+                    if ( $this->getMD5flag() )
1542
+                    $content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
1543
+
1544
+                    $content .= "\r\n"	. $_content['data'] . "\r\n";
1545
+
1546
+                    if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part after html part
1547
+                    {
1548
+                        $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n";
1549
+                    }
1550
+
1551
+                    $content .= "\r\n";
1552
+                }
1553
+            }
1554
+
1555
+            // Close message boundries
1556
+            //            $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ;
1557
+            $content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ;
1558
+        }
1559
+
1560
+        return $content;
1561
+    }
1562
+
1563
+    /**
1564
+     * File attachments are added to the content array as sub-arrays,
1565
+     * allowing for multiple attachments for each outbound email
1566
+     *
1567
+     * @param string $strContent  File data to attach to message
1568
+     * @param string $strFileName File Name to give to attachment
1569
+     * @param string $strMimeType File Mime Type of attachment
1570
+     * @return void
1571
+     */
1572
+    function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
1573
+    {
1574
+        if ( $strContent )
1575
+        {
1576
+            $strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n"));    // 76 max is defined into http://tools.ietf.org/html/rfc2047
1577
+
1578
+            $this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
1579
+            $this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
1580
+            $this->_msgContent['attachment'][$strFileName]['data']     = $strContent;
1581
+
1582
+            if ( $this->getMD5flag() )
1583
+            $this->_msgContent['attachment'][$strFileName]['md5']      = dol_hash($strContent, 3);
1584
+        }
1585
+    }
1586
+
1587
+
1588
+    // @CHANGE LDR
1589
+
1590
+    /**
1591
+     * Image attachments are added to the content array as sub-arrays,
1592
+     * allowing for multiple images for each outbound email
1593
+     *
1594
+     * @param 	string $strContent  	Image data to attach to message
1595
+     * @param 	string $strImageName 	Image Name to give to attachment
1596
+     * @param 	string $strMimeType 	Image Mime Type of attachment
1597
+     * @param 	string $strImageCid		CID
1598
+     * @return 	void
1599
+     */
1600
+    function setImageInline($strContent, $strImageName = 'unknown', $strMimeType = 'unknown', $strImageCid = 'unknown')
1601
+    {
1602
+        if ($strContent)
1603
+        {
1604
+            $this->_msgContent['image'][$strImageName]['mimeType'] = $strMimeType;
1605
+            $this->_msgContent['image'][$strImageName]['imageName'] = $strImageName;
1606
+            $this->_msgContent['image'][$strImageName]['cid']      = $strImageCid;
1607
+            $this->_msgContent['image'][$strImageName]['data']     = $strContent;
1608
+
1609
+            if ( $this->getMD5flag() )
1610
+            $this->_msgContent['image'][$strImageName]['md5']      = dol_hash($strContent, 3);
1611
+        }
1612
+    }
1613
+    // END @CHANGE LDR
1614
+
1615
+
1616
+    /**
1617
+     * Message Content Sensitivity
1618
+     * Message Sensitivity values:
1619
+     *   - [0] None - default
1620
+     *   - [1] Personal
1621
+     *   - [2] Private
1622
+     *   - [3] Company Confidential
1623
+     *
1624
+     * @param 	integer	$_value		Message Sensitivity
1625
+     * @return 	void
1626
+     */
1627
+    function setSensitivity($_value = 0)
1628
+    {
1629
+        if ( ( is_numeric($_value) ) &&
1630
+        ( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
1631
+        $this->_msgSensitivity = $_value;
1632
+    }
1633
+
1634
+    /**
1635
+     * Returns Message Content Sensitivity string
1636
+     * Message Sensitivity values:
1637
+     *   - [0] None - default
1638
+     *   - [1] Personal
1639
+     *   - [2] Private
1640
+     *   - [3] Company Confidential
1641
+     *
1642
+     * @return 	void
1643
+     */
1644
+    function getSensitivity()
1645
+    {
1646
+        return $this->_arySensitivity[$this->_msgSensitivity];
1647
+    }
1648
+
1649
+    /**
1650
+     * Message Content Priority
1651
+     * Message Priority values:
1652
+     *  - [0] 'Bulk'
1653
+     *  - [1] 'Highest'
1654
+     *  - [2] 'High'
1655
+     *  - [3] 'Normal' - default
1656
+     *  - [4] 'Low'
1657
+     *  - [5] 'Lowest'
1658
+     *
1659
+     * @param 	integer 	$_value 	Message Priority
1660
+     * @return 	void
1661
+     */
1662
+    function setPriority( $_value = 3 )
1663
+    {
1664
+        if ( ( is_numeric($_value) ) &&
1665
+        ( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
1666
+        $this->_msgPriority = $_value;
1667
+    }
1668
+
1669
+    /**
1670
+     * Message Content Priority
1671
+     * Message Priority values:
1672
+     *  - [0] 'Bulk'
1673
+     *  - [1] 'Highest'
1674
+     *  - [2] 'High'
1675
+     *  - [3] 'Normal' - default
1676
+     *  - [4] 'Low'
1677
+     *  - [5] 'Lowest'
1678
+     *
1679
+     * @return string
1680
+     */
1681
+    function getPriority()
1682
+    {
1683
+        return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
1684
+        . 'Priority: '   . $this->_aryPriority[$this->_msgPriority] . "\r\n"
1685
+        . 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n";
1686
+    }
1687
+
1688
+    /**
1689
+     * Set flag which determines whether to calculate message MD5 checksum.
1690
+     *
1691
+     * @param 	string 	$_flag		Message Priority
1692
+     * @return 	void
1693
+     */
1694
+    function setMD5flag($_flag = false)
1695
+    {
1696
+        $this->_smtpMD5 = $_flag;
1697
+    }
1698
+
1699
+    /**
1700
+     * Gets flag which determines whether to calculate message MD5 checksum.
1701
+     *
1702
+     * @return 	boolean 				Message Priority
1703
+     */
1704
+    function getMD5flag()
1705
+    {
1706
+        return $this->_smtpMD5;
1707
+    }
1708
+
1709
+    /**
1710
+     * Message X-Header Content
1711
+     * This is a simple "insert". Whatever is given will be placed
1712
+     * "as is" into the Xheader array.
1713
+     *
1714
+     * @param string $strXdata Message X-Header Content
1715
+     * @return void
1716
+     */
1717
+    function setXheader($strXdata)
1718
+    {
1719
+        if ( $strXdata )
1720
+        $this->_msgXheader[] = $strXdata;
1721
+    }
1722
+
1723
+    /**
1724
+     * Retrieves the Message X-Header Content
1725
+     *
1726
+     * @return string[] $_msgContent Message X-Header Content
1727
+     */
1728
+    function getXheader()
1729
+    {
1730
+        return $this->_msgXheader;
1731
+    }
1732
+
1733
+    /**
1734
+     * Generates Random string for MIME message Boundary
1735
+     *
1736
+     * @return void
1737
+     */
1738
+    function _setBoundary()
1739
+    {
1740
+        $this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary";
1741
+        $this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);
1742
+        $this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);
1743
+    }
1744
+
1745
+    /**
1746
+     * Retrieves the MIME message Boundary
1747
+     *
1748
+     * @param  string $type				Type of boundary
1749
+     * @return string $_smtpsBoundary 	MIME message Boundary
1750
+     */
1751
+    function _getBoundary($type='mixed')
1752
+    {
1753
+        if ($type == 'mixed') return $this->_smtpsBoundary;
1754
+        else if ($type == 'related') return $this->_smtpsRelatedBoundary;
1755
+        else if ($type == 'alternative') return $this->_smtpsAlternativeBoundary;
1756
+    }
1757 1757
 
1758 1758
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1759
-	/**
1760
-	 * This function has been modified as provided by SirSir to allow multiline responses when
1761
-	 * using SMTP Extensions
1762
-	 *
1763
-	 * @param	Handler		$socket			Socket handler
1764
-	 * @param	string		$response		Response. Example: "550 5.7.1  https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3"
1765
-	 * @return	boolean						True or false
1766
-	 */
1767
-	function server_parse($socket, $response)
1768
-	{
1759
+    /**
1760
+     * This function has been modified as provided by SirSir to allow multiline responses when
1761
+     * using SMTP Extensions
1762
+     *
1763
+     * @param	Handler		$socket			Socket handler
1764
+     * @param	string		$response		Response. Example: "550 5.7.1  https://support.google.com/a/answer/6140680#invalidcred j21sm814390wre.3"
1765
+     * @return	boolean						True or false
1766
+     */
1767
+    function server_parse($socket, $response)
1768
+    {
1769 1769
         // phpcs:enable
1770
-		/**
1771
-		 * Returns constructed SELECT Object string or boolean upon failure
1772
-		 * Default value is set at true
1773
-		 */
1774
-		$_retVal = true;
1770
+        /**
1771
+         * Returns constructed SELECT Object string or boolean upon failure
1772
+         * Default value is set at true
1773
+         */
1774
+        $_retVal = true;
1775 1775
 
1776
-		$server_response = '';
1776
+        $server_response = '';
1777 1777
 
1778 1778
         // avoid infinite loop
1779 1779
         $limit=0;
1780 1780
 
1781
-		while (substr($server_response,3,1) != ' ' && $limit<100)
1782
-		{
1783
-			if (! ($server_response = fgets($socket, 256)))
1784
-			{
1785
-				$this->_setErr(121, "Couldn't get mail server response codes");
1786
-				$_retVal = false;
1787
-				break;
1788
-			}
1781
+        while (substr($server_response,3,1) != ' ' && $limit<100)
1782
+        {
1783
+            if (! ($server_response = fgets($socket, 256)))
1784
+            {
1785
+                $this->_setErr(121, "Couldn't get mail server response codes");
1786
+                $_retVal = false;
1787
+                break;
1788
+            }
1789 1789
             $limit++;
1790
-		}
1790
+        }
1791 1791
 
1792
-		if (! (substr($server_response, 0, 3) == $response))
1793
-		{
1794
-			$this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
1795
-			$_retVal = false;
1796
-		}
1792
+        if (! (substr($server_response, 0, 3) == $response))
1793
+        {
1794
+            $this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
1795
+            $_retVal = false;
1796
+        }
1797 1797
 
1798
-		return $_retVal;
1799
-	}
1798
+        return $_retVal;
1799
+    }
1800 1800
 
1801 1801
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1802
-	/**
1803
-	 * Send str
1804
-	 *
1805
-	 * @param	string		$_strSend		String to send
1806
-	 * @param 	string		$_returnCode	Return code
1807
-	 * @param 	string		$CRLF			CRLF
1808
-	 * @return 	boolean|null						True or false
1809
-	 */
1810
-	function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
1811
-	{
1802
+    /**
1803
+     * Send str
1804
+     *
1805
+     * @param	string		$_strSend		String to send
1806
+     * @param 	string		$_returnCode	Return code
1807
+     * @param 	string		$CRLF			CRLF
1808
+     * @return 	boolean|null						True or false
1809
+     */
1810
+    function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
1811
+    {
1812 1812
         // phpcs:enable
1813
-		if ($this->_debug) $this->log.=$_strSend;	// @CHANGE LDR for log
1814
-		fputs($this->socket, $_strSend . $CRLF);
1815
-		if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF;
1813
+        if ($this->_debug) $this->log.=$_strSend;	// @CHANGE LDR for log
1814
+        fputs($this->socket, $_strSend . $CRLF);
1815
+        if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF;
1816 1816
 
1817
-		if ( $_returnCode )
1818
-		return $this->server_parse($this->socket, $_returnCode);
1819
-	}
1817
+        if ( $_returnCode )
1818
+        return $this->server_parse($this->socket, $_returnCode);
1819
+    }
1820 1820
 
1821
-	// =============================================================
1822
-	// ** Error handling methods
1821
+    // =============================================================
1822
+    // ** Error handling methods
1823 1823
 
1824
-	/**
1825
-	 * Defines errors codes and messages for Class
1826
-	 *
1827
-	 * @param  int    $_errNum  Error Code Number
1828
-	 * @param  string $_errMsg  Error Message
1829
-	 * @return void
1824
+    /**
1825
+     * Defines errors codes and messages for Class
1826
+     *
1827
+     * @param  int    $_errNum  Error Code Number
1828
+     * @param  string $_errMsg  Error Message
1829
+     * @return void
1830 1830
      */
1831 1831
     function _setErr( $_errNum, $_errMsg )
1832 1832
     {
@@ -1836,25 +1836,25 @@  discard block
 block discarded – undo
1836 1836
         );
1837 1837
     }
1838 1838
 
1839
-	/**
1840
-	 * Returns errors codes and messages for Class
1841
-	 *
1842
-	 * @return string $_errMsg  Error Message
1843
-	 */
1844
-	function getErrors()
1845
-	{
1846
-		$_errMsg = array();
1847
-
1848
-		if (is_array($this->_smtpsErrors))
1849
-		{
1850
-			foreach ( $this->_smtpsErrors as $_err => $_info )
1851
-			{
1852
-				$_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg'];
1853
-			}
1854
-		}
1855
-
1856
-		return implode("\n", $_errMsg);
1857
-	}
1839
+    /**
1840
+     * Returns errors codes and messages for Class
1841
+     *
1842
+     * @return string $_errMsg  Error Message
1843
+     */
1844
+    function getErrors()
1845
+    {
1846
+        $_errMsg = array();
1847
+
1848
+        if (is_array($this->_smtpsErrors))
1849
+        {
1850
+            foreach ( $this->_smtpsErrors as $_err => $_info )
1851
+            {
1852
+                $_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg'];
1853
+            }
1854
+        }
1855
+
1856
+        return implode("\n", $_errMsg);
1857
+    }
1858 1858
 }
1859 1859
 
1860 1860
 
Please login to merge, or discard this patch.
Spacing   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 	/**
118 118
 	 * Message Sensitivity
119 119
 	 */
120
-	var $_arySensitivity = array ( false,
120
+	var $_arySensitivity = array(false,
121 121
                                   'Personal',
122 122
                                   'Private',
123
-                                  'Company Confidential' );
123
+                                  'Company Confidential');
124 124
 
125 125
 	/**
126 126
 	 * Message Sensitivity
@@ -131,12 +131,12 @@  discard block
 block discarded – undo
131 131
 	/**
132 132
 	 * Message Priority
133 133
 	 */
134
-	var $_aryPriority = array ( 'Bulk',
134
+	var $_aryPriority = array('Bulk',
135 135
                                 'Highest',
136 136
                                 'High',
137 137
                                 'Normal',
138 138
                                 'Low',
139
-                                'Lowest' );
139
+                                'Lowest');
140 140
 
141 141
 	/**
142 142
 	 * Content-Transfer-Encoding
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
 	/**
148 148
 	 * Content-Transfer-Encoding
149 149
 	 */
150
-	var $_smtpsTransEncodeTypes = array( '7bit',               // Simple 7-bit ASCII
151
-                                         '8bit',               // 8-bit coding with line termination characters
152
-                                         'base64',             // 3 octets encoded into 4 sextets with offset
153
-                                         'binary',             // Arbitrary binary stream
154
-                                         'mac-binhex40',       // Macintosh binary to hex encoding
155
-                                         'quoted-printable',   // Mostly 7-bit, with 8-bit characters encoded as "=HH"
156
-                                         'uuencode' );         // UUENCODE encoding
150
+	var $_smtpsTransEncodeTypes = array('7bit', // Simple 7-bit ASCII
151
+                                         '8bit', // 8-bit coding with line termination characters
152
+                                         'base64', // 3 octets encoded into 4 sextets with offset
153
+                                         'binary', // Arbitrary binary stream
154
+                                         'mac-binhex40', // Macintosh binary to hex encoding
155
+                                         'quoted-printable', // Mostly 7-bit, with 8-bit characters encoded as "=HH"
156
+                                         'uuencode'); // UUENCODE encoding
157 157
 
158 158
 	/**
159 159
 	 * Content-Transfer-Encoding
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
      */
301 301
 	function setErrorsTo($_strErrorsTo)
302 302
 	{
303
-		if ( $_strErrorsTo )
303
+		if ($_strErrorsTo)
304 304
 		$this->_errorsTo = $this->_strip_email($_strErrorsTo);
305 305
 	}
306 306
 
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
      * @param	boolean		$_part		Variant
311 311
      * @return	string					Errors to
312 312
      */
313
-	function getErrorsTo($_part = true )
313
+	function getErrorsTo($_part = true)
314 314
 	{
315 315
 		$_retValue = '';
316 316
 
317
-		if ( $_part === true )
317
+		if ($_part === true)
318 318
 		$_retValue = $this->_errorsTo;
319 319
 		else
320 320
 		$_retValue = $this->_errorsTo[$_part];
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 	 * @param	boolean		$_vDebug		Value for debug
329 329
 	 * @return 	void
330 330
 	 */
331
-	function setDebug($_vDebug = false )
331
+	function setDebug($_vDebug = false)
332 332
 	{
333 333
 		$this->_debug = $_vDebug;
334 334
 	}
@@ -359,29 +359,29 @@  discard block
 block discarded – undo
359 359
 		// We have to make sure the HOST given is valid
360 360
 		// This is done here because '@fsockopen' will not give me this
361 361
 		// information if it failes to connect because it can't find the HOST
362
-		$host=$this->getHost();
363
-		$usetls = preg_match('@tls://@i',$host);
362
+		$host = $this->getHost();
363
+		$usetls = preg_match('@tls://@i', $host);
364 364
 
365
-		$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
366
-		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
367
-		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
365
+		$host = preg_replace('@tcp://@i', '', $host); // Remove prefix
366
+		$host = preg_replace('@ssl://@i', '', $host); // Remove prefix
367
+		$host = preg_replace('@tls://@i', '', $host); // Remove prefix
368 368
 
369 369
 		// @CHANGE LDR
370 370
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
371 371
 
372
-		if ( (! is_ip($host)) && ((gethostbyname($host)) == $host))
372
+		if ((!is_ip($host)) && ((gethostbyname($host)) == $host))
373 373
 		{
374
-			$this->_setErr(99, $host . ' is either offline or is an invalid host name.');
374
+			$this->_setErr(99, $host.' is either offline or is an invalid host name.');
375 375
 			$_retVal = false;
376 376
 		}
377 377
 		else
378 378
 		{
379 379
 			//See if we can connect to the SMTP server
380 380
 			if ($this->socket = @fsockopen(
381
-    			preg_replace('@tls://@i','',$this->getHost()),       // Host to 'hit', IP or domain
382
-    			$this->getPort(),       // which Port number to use
383
-    			$this->errno,           // actual system level error
384
-    			$this->errstr,          // and any text that goes with the error
381
+    			preg_replace('@tls://@i', '', $this->getHost()), // Host to 'hit', IP or domain
382
+    			$this->getPort(), // which Port number to use
383
+    			$this->errno, // actual system level error
384
+    			$this->errstr, // and any text that goes with the error
385 385
     			$this->_smtpTimeout
386 386
 			))  // timeout for reading/writing data over the socket
387 387
 			{
@@ -392,14 +392,14 @@  discard block
 block discarded – undo
392 392
 				if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
393 393
 
394 394
 				// Check response from Server
395
-				if ( $_retVal = $this->server_parse($this->socket, "220") )
395
+				if ($_retVal = $this->server_parse($this->socket, "220"))
396 396
 				$_retVal = $this->socket;
397 397
 			}
398 398
 			// This connection attempt failed.
399 399
 			else
400 400
 			{
401 401
 				// @CHANGE LDR
402
-				if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
402
+				if (empty($this->errstr)) $this->errstr = 'Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
403 403
 				$this->_setErr($this->errno, $this->errstr);
404 404
 				$_retVal = false;
405 405
 			}
@@ -422,18 +422,18 @@  discard block
 block discarded – undo
422 422
 		// Send the RFC2554 specified EHLO.
423 423
 		// This improvment as provided by 'SirSir' to
424 424
 		// accomodate both SMTP AND ESMTP capable servers
425
-		$host=$this->getHost();
426
-		$usetls = preg_match('@tls://@i',$host);
425
+		$host = $this->getHost();
426
+		$usetls = preg_match('@tls://@i', $host);
427 427
 
428
-		$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
429
-		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
430
-		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
428
+		$host = preg_replace('@tcp://@i', '', $host); // Remove prefix
429
+		$host = preg_replace('@ssl://@i', '', $host); // Remove prefix
430
+		$host = preg_replace('@tls://@i', '', $host); // Remove prefix
431 431
 
432
-		if ($usetls) $host='tls://'.$host;
432
+		if ($usetls) $host = 'tls://'.$host;
433 433
 
434 434
 		$hosth = $host;
435 435
 
436
-		if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
436
+		if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
437 437
 		{
438 438
 			// If the from to is 'aaa <[email protected]>', we will keep 'ccc.com'
439 439
 			$hosth = $this->getFrom('addr');
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
 			$hosth = preg_replace('/.*@/', '', $hosth);
443 443
 		}
444 444
 
445
-		if ( $_retVal = $this->socket_send_str('EHLO ' . $hosth, '250') )
445
+		if ($_retVal = $this->socket_send_str('EHLO '.$hosth, '250'))
446 446
 		{
447 447
 			if ($usetls)
448 448
 			{
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 				// the answer with list of supported AUTH methods. They may differs between non STARTTLS and with STARTTLS.
494 494
 				if (!$_retVal = $this->socket_send_str('EHLO '.$host, '250'))
495 495
 				{
496
-					$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
496
+					$this->_setErr(126, '"'.$host.'" does not support authenticated connections.');
497 497
 					return $_retVal;
498 498
 				}
499 499
 			}
@@ -506,12 +506,12 @@  discard block
 block discarded – undo
506 506
 
507 507
 			// The error here just means the ID/password combo doesn't work.
508 508
 			// There is not a method to determine which is the problem, ID or password
509
-			if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
509
+			if (!$_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235'))
510 510
 			$this->_setErr(130, 'Invalid Authentication Credentials.');
511 511
 		}
512 512
 		else
513 513
 		{
514
-			$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
514
+			$this->_setErr(126, '"'.$host.'" does not support authenticated connections.');
515 515
 		}
516 516
 
517 517
 		return $_retVal;
@@ -535,10 +535,10 @@  discard block
 block discarded – undo
535 535
 		$_retVal = false;
536 536
 
537 537
 		// Connect to Server
538
-		if ( $this->socket = $this->_server_connect() )
538
+		if ($this->socket = $this->_server_connect())
539 539
 		{
540 540
 			// If a User ID *and* a password is given, assume Authentication is desired
541
-			if( !empty($this->_smtpsID) && !empty($this->_smtpsPW) )
541
+			if (!empty($this->_smtpsID) && !empty($this->_smtpsPW))
542 542
 			{
543 543
 				// Send the RFC2554 specified EHLO.
544 544
 				$_retVal = $this->_server_authenticate();
@@ -548,16 +548,16 @@  discard block
 block discarded – undo
548 548
 			else
549 549
 			{
550 550
 				// Send the RFC821 specified HELO.
551
-				$host=$this->getHost();
552
-				$usetls = preg_match('@tls://@i',$host);
551
+				$host = $this->getHost();
552
+				$usetls = preg_match('@tls://@i', $host);
553 553
 
554
-				$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
555
-				$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
556
-				$host=preg_replace('@tls://@i','',$host);	// Remove prefix
554
+				$host = preg_replace('@tcp://@i', '', $host); // Remove prefix
555
+				$host = preg_replace('@ssl://@i', '', $host); // Remove prefix
556
+				$host = preg_replace('@tls://@i', '', $host); // Remove prefix
557 557
 
558 558
 				$hosth = $host;
559 559
 
560
-				if (! empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
560
+				if (!empty($conf->global->MAIL_SMTP_USE_FROM_FOR_HELO))
561 561
 				{
562 562
 					// If the from to is 'aaa <[email protected]>', we will keep 'ccc.com'
563 563
 					$hosth = $this->getFrom('addr');
@@ -566,21 +566,21 @@  discard block
 block discarded – undo
566 566
 					$hosth = preg_replace('/.*@/', '', $hosth);
567 567
 				}
568 568
 
569
-				$_retVal = $this->socket_send_str('HELO ' . $hosth, '250');
569
+				$_retVal = $this->socket_send_str('HELO '.$hosth, '250');
570 570
 			}
571 571
 
572 572
 			// Well, did we get to the server?
573
-			if ( $_retVal )
573
+			if ($_retVal)
574 574
 			{
575 575
 				// From this point onward most server response codes should be 250
576 576
 				// Specify who the mail is from....
577 577
 				// This has to be the raw email address, strip the "name" off
578
-				$this->socket_send_str('MAIL FROM: ' . $this->getFrom('addr'), '250');
578
+				$this->socket_send_str('MAIL FROM: '.$this->getFrom('addr'), '250');
579 579
 
580 580
 				// 'RCPT TO:' must be given a single address, so this has to loop
581 581
 				// through the list of addresses, regardless of TO, CC or BCC
582 582
 				// and send it out "single file"
583
-				foreach ( $this->get_RCPT_list() as $_address )
583
+				foreach ($this->get_RCPT_list() as $_address)
584 584
 				{
585 585
 				    /* Note:
586 586
 				     * BCC email addresses must be listed in the RCPT TO command list,
@@ -596,7 +596,7 @@  discard block
 block discarded – undo
596 596
 					 * mark the last address as "bad" and start the address loop over again.
597 597
 					 * If any address fails, the entire message fails.
598 598
 					 */
599
-					$this->socket_send_str('RCPT TO: <' . $_address . '>', '250');
599
+					$this->socket_send_str('RCPT TO: <'.$_address.'>', '250');
600 600
 				}
601 601
 
602 602
 				// Tell the server we are ready to start sending data
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 
607 607
 				// Now we are ready for the message...
608 608
 				// Ok, all the ingredients are mixed in let's cook this puppy...
609
-				$this->socket_send_str($this->getHeader().$this->getBodyContent() . "\r\n" . '.', '250');
609
+				$this->socket_send_str($this->getHeader().$this->getBodyContent()."\r\n".'.', '250');
610 610
 
611 611
 				// Now tell the server we are done and close the socket...
612 612
 				fputs($this->socket, 'QUIT');
@@ -656,13 +656,13 @@  discard block
 block discarded – undo
656 656
 		$_retVal = true;
657 657
 
658 658
 		// if we have a path...
659
-		if ( ! empty ($_strConfigPath) )
659
+		if (!empty ($_strConfigPath))
660 660
 		{
661 661
 			// If the path is not valid, this will NOT generate an error,
662 662
 			// it will simply return false.
663
-			if ( ! @include $_strConfigPath)
663
+			if (!@include $_strConfigPath)
664 664
 			{
665
-				$this->_setErr(110, '"' . $_strConfigPath . '" is not a valid path.');
665
+				$this->_setErr(110, '"'.$_strConfigPath.'" is not a valid path.');
666 666
 				$_retVal = false;
667 667
 			}
668 668
 		}
@@ -672,13 +672,13 @@  discard block
 block discarded – undo
672 672
 		{
673 673
 			// Set these properties ONLY if they are set in the php.ini file.
674 674
 			// Otherwise the default values will be used.
675
-			if ( $_host = ini_get('SMTPs') )
675
+			if ($_host = ini_get('SMTPs'))
676 676
 			$this->setHost($_host);
677 677
 
678
-			if ( $_port = ini_get('smtp_port') )
678
+			if ($_port = ini_get('smtp_port'))
679 679
 			$this->setPort($_port);
680 680
 
681
-			if ( $_from = ini_get('sendmail_from') )
681
+			if ($_from = ini_get('sendmail_from'))
682 682
 			$this->setFrom($_from);
683 683
 		}
684 684
 
@@ -697,8 +697,8 @@  discard block
 block discarded – undo
697 697
 	 */
698 698
 	function setTransportType($_type = 0)
699 699
 	{
700
-		if ( ( is_numeric($_type) ) &&
701
-		( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
700
+		if ((is_numeric($_type)) &&
701
+		(($_type >= 0) && ($_type <= 3)))
702 702
 		$this->_transportType = $_type;
703 703
 	}
704 704
 
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 	 */
741 741
 	function setHost($_strHost)
742 742
 	{
743
-		if ( $_strHost )
743
+		if ($_strHost)
744 744
 		$this->_smtpsHost = $_strHost;
745 745
 	}
746 746
 
@@ -765,8 +765,8 @@  discard block
 block discarded – undo
765 765
 	 */
766 766
 	function setPort($_intPort)
767 767
 	{
768
-		if ( ( is_numeric($_intPort) ) &&
769
-		( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
768
+		if ((is_numeric($_intPort)) &&
769
+		(($_intPort >= 1) && ($_intPort <= 65536)))
770 770
 		$this->_smtpsPort = $_intPort;
771 771
 	}
772 772
 
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 	 */
833 833
 	function setCharSet($_strCharSet)
834 834
 	{
835
-		if ( $_strCharSet )
835
+		if ($_strCharSet)
836 836
 		$this->_smtpsCharSet = $_strCharSet;
837 837
 	}
838 838
 
@@ -920,7 +920,7 @@  discard block
 block discarded – undo
920 920
 	 */
921 921
 	function setFrom($_strFrom)
922 922
 	{
923
-		if ( $_strFrom )
923
+		if ($_strFrom)
924 924
 		$this->_msgFrom = $this->_strip_email($_strFrom);
925 925
 	}
926 926
 
@@ -934,7 +934,7 @@  discard block
 block discarded – undo
934 934
 	{
935 935
 		$_retValue = '';
936 936
 
937
-		if ( $_part === true )
937
+		if ($_part === true)
938 938
 		$_retValue = $this->_msgFrom;
939 939
 		else
940 940
 		$_retValue = $this->_msgFrom[$_part];
@@ -950,7 +950,7 @@  discard block
 block discarded – undo
950 950
 	 */
951 951
 	function setReplyTo($_strReplyTo)
952 952
 	{
953
-	    if ( $_strReplyTo )
953
+	    if ($_strReplyTo)
954 954
 	        $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
955 955
 	}
956 956
 
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 	{
965 965
 	    $_retValue = '';
966 966
 
967
-	    if ( $_part === true )
967
+	    if ($_part === true)
968 968
 	        $_retValue = $this->_msgReplyTo;
969 969
 	    else
970 970
 	        $_retValue = $this->_msgReplyTo[$_part];
@@ -990,13 +990,13 @@  discard block
 block discarded – undo
990 990
 		$aryHost = $this->_msgRecipients;
991 991
 
992 992
 		// Only run this if we have something
993
-		if ( !empty ($_addrList ))
993
+		if (!empty ($_addrList))
994 994
 		{
995 995
 			// $_addrList can be a STRING or an array
996
-			if ( is_string($_addrList) )
996
+			if (is_string($_addrList))
997 997
 			{
998 998
 				// This could be a COMMA delimited string
999
-				if ( strstr($_addrList, ',') )
999
+				if (strstr($_addrList, ','))
1000 1000
 				// "explode "list" into an array
1001 1001
 				$_addrList = explode(',', $_addrList);
1002 1002
 
@@ -1006,7 +1006,7 @@  discard block
 block discarded – undo
1006 1006
 			}
1007 1007
 
1008 1008
 			// take the array of addresses and split them further
1009
-			foreach ( $_addrList as $_strAddr )
1009
+			foreach ($_addrList as $_strAddr)
1010 1010
 			{
1011 1011
 				// Strip off the end '>'
1012 1012
 				$_strAddr = str_replace('>', '', $_strAddr);
@@ -1016,7 +1016,7 @@  discard block
 block discarded – undo
1016 1016
 				$_tmpaddr = explode('<', $_strAddr);
1017 1017
 
1018 1018
 				// We have a "Real Name" and eMail address
1019
-				if ( count($_tmpaddr) == 2 )
1019
+				if (count($_tmpaddr) == 2)
1020 1020
 				{
1021 1021
 					$_tmpHost = explode('@', $_tmpaddr[1]);
1022 1022
 					$_tmpaddr[0] = trim($_tmpaddr[0], ' ">');
@@ -1073,10 +1073,10 @@  discard block
 block discarded – undo
1073 1073
 		$_tmpAry = explode('<', $_strAddr);
1074 1074
 
1075 1075
 		// Do we have a "Real name"
1076
-		if ( count($_tmpAry) == 2 )
1076
+		if (count($_tmpAry) == 2)
1077 1077
 		{
1078 1078
 			// We may not really have a "Real Name"
1079
-			if ( $_tmpAry[0])
1079
+			if ($_tmpAry[0])
1080 1080
 			$_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1081 1081
 
1082 1082
 			$_aryEmail['addr'] = $_tmpAry[1];
@@ -1085,10 +1085,10 @@  discard block
 block discarded – undo
1085 1085
 		$_aryEmail['addr'] = $_tmpAry[0];
1086 1086
 
1087 1087
 		// Pull User Name and Host.tld apart
1088
-		list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']);
1088
+		list($_aryEmail['user'], $_aryEmail['host']) = explode('@', $_aryEmail['addr']);
1089 1089
 
1090 1090
 		// Put the brackets back around the address
1091
-		$_aryEmail['addr'] = '<' . $_aryEmail['addr'] . '>';
1091
+		$_aryEmail['addr'] = '<'.$_aryEmail['addr'].'>';
1092 1092
 
1093 1093
 		return $_aryEmail;
1094 1094
 	}
@@ -1107,17 +1107,17 @@  discard block
 block discarded – undo
1107 1107
 		/**
1108 1108
 		 * An array of bares addresses for use with 'RCPT TO:'
1109 1109
 		 */
1110
-		$_RCPT_list=array();
1110
+		$_RCPT_list = array();
1111 1111
 
1112 1112
 		// walk down Recipients array and pull just email addresses
1113
-		foreach ( $this->_msgRecipients as $_host => $_list )
1113
+		foreach ($this->_msgRecipients as $_host => $_list)
1114 1114
 		{
1115
-			foreach ( $_list as $_subList )
1115
+			foreach ($_list as $_subList)
1116 1116
 			{
1117
-				foreach ( $_subList as $_name => $_addr )
1117
+				foreach ($_subList as $_name => $_addr)
1118 1118
 				{
1119 1119
 					// build RCPT list
1120
-					$_RCPT_list[] = $_name . '@' . $_host;
1120
+					$_RCPT_list[] = $_name.'@'.$_host;
1121 1121
 				}
1122 1122
 			}
1123 1123
 		}
@@ -1136,27 +1136,27 @@  discard block
 block discarded – undo
1136 1136
 	{
1137 1137
         // phpcs:enable
1138 1138
 		// We need to know which address segment to pull
1139
-		if ( $_which )
1139
+		if ($_which)
1140 1140
 		{
1141 1141
 			// Make sure we have addresses to process
1142
-			if ( $this->_msgRecipients )
1142
+			if ($this->_msgRecipients)
1143 1143
 			{
1144
-				$_RCPT_list=array();
1144
+				$_RCPT_list = array();
1145 1145
 				// walk down Recipients array and pull just email addresses
1146
-				foreach ( $this->_msgRecipients as $_host => $_list )
1146
+				foreach ($this->_msgRecipients as $_host => $_list)
1147 1147
 				{
1148
-					if ( $this->_msgRecipients[$_host][$_which] )
1148
+					if ($this->_msgRecipients[$_host][$_which])
1149 1149
 					{
1150
-						foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName )
1150
+						foreach ($this->_msgRecipients[$_host][$_which] as $_addr => $_realName)
1151 1151
 						{
1152
-							if ( $_realName )	// @CHANGE LDR
1152
+							if ($_realName)	// @CHANGE LDR
1153 1153
 							{
1154
-								$_realName = '"' . $_realName . '"';
1155
-								$_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
1154
+								$_realName = '"'.$_realName.'"';
1155
+								$_RCPT_list[] = $_realName.' <'.$_addr.'@'.$_host.'>';
1156 1156
 							}
1157 1157
 							else
1158 1158
 							{
1159
-								$_RCPT_list[] = $_addr . '@' . $_host;
1159
+								$_RCPT_list[] = $_addr.'@'.$_host;
1160 1160
 							}
1161 1161
 						}
1162 1162
 					}
@@ -1185,7 +1185,7 @@  discard block
 block discarded – undo
1185 1185
 	 */
1186 1186
 	function setTO($_addrTo)
1187 1187
 	{
1188
-		if ( $_addrTo )
1188
+		if ($_addrTo)
1189 1189
 		$this->_buildAddrList('to', $_addrTo);
1190 1190
 	}
1191 1191
 
@@ -1207,7 +1207,7 @@  discard block
 block discarded – undo
1207 1207
 	 */
1208 1208
 	function setCC($_strCC)
1209 1209
 	{
1210
-		if ( $_strCC )
1210
+		if ($_strCC)
1211 1211
 		$this->_buildAddrList('cc', $_strCC);
1212 1212
 	}
1213 1213
 
@@ -1229,7 +1229,7 @@  discard block
 block discarded – undo
1229 1229
 	 */
1230 1230
 	function setBCC($_strBCC)
1231 1231
 	{
1232
-		if ( $_strBCC )
1232
+		if ($_strBCC)
1233 1233
 		$this->_buildAddrList('bcc', $_strBCC);
1234 1234
 	}
1235 1235
 
@@ -1251,7 +1251,7 @@  discard block
 block discarded – undo
1251 1251
 	 */
1252 1252
 	function setSubject($_strSubject = '')
1253 1253
 	{
1254
-		if ( $_strSubject )
1254
+		if ($_strSubject)
1255 1255
 		$this->_msgSubject = $_strSubject;
1256 1256
 	}
1257 1257
 
@@ -1274,11 +1274,11 @@  discard block
 block discarded – undo
1274 1274
 	{
1275 1275
 		global $conf;
1276 1276
 
1277
-		$_header = 'From: '       . $this->getFrom('org') . "\r\n"
1278
-		. 'To: '         . $this->getTO()          . "\r\n";
1277
+		$_header = 'From: '.$this->getFrom('org')."\r\n"
1278
+		. 'To: '.$this->getTO()."\r\n";
1279 1279
 
1280
-		if ( $this->getCC() )
1281
-		$_header .= 'Cc: ' . $this->getCC()  . "\r\n";
1280
+		if ($this->getCC())
1281
+		$_header .= 'Cc: '.$this->getCC()."\r\n";
1282 1282
 
1283 1283
 		/* Note:
1284 1284
 		 * BCC email addresses must be listed in the RCPT TO command list,
@@ -1291,57 +1291,57 @@  discard block
 block discarded – undo
1291 1291
 		$_header .= 'Bcc: ' . $this->getBCC()  . "\r\n";
1292 1292
         */
1293 1293
 
1294
-		$host=$this->getHost();
1295
-		$usetls = preg_match('@tls://@i',$host);
1294
+		$host = $this->getHost();
1295
+		$usetls = preg_match('@tls://@i', $host);
1296 1296
 
1297
-		$host=preg_replace('@tcp://@i','',$host);	// Remove prefix
1298
-		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
1299
-		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
1297
+		$host = preg_replace('@tcp://@i', '', $host); // Remove prefix
1298
+		$host = preg_replace('@ssl://@i', '', $host); // Remove prefix
1299
+		$host = preg_replace('@tls://@i', '', $host); // Remove prefix
1300 1300
 
1301
-		$host=dol_getprefix('email');
1301
+		$host = dol_getprefix('email');
1302 1302
 
1303 1303
 		//NOTE: Message-ID should probably contain the username of the user who sent the msg
1304
-		$_header .= 'Subject: '    . $this->getSubject()     . "\r\n";
1305
-		$_header .= 'Date: '       . date("r")               . "\r\n";
1304
+		$_header .= 'Subject: '.$this->getSubject()."\r\n";
1305
+		$_header .= 'Date: '.date("r")."\r\n";
1306 1306
 
1307 1307
 		$trackid = $this->getTrackId();
1308 1308
 		if ($trackid)
1309 1309
 		{
1310 1310
 			// References is kept in response and Message-ID is returned into In-Reply-To:
1311
-			$_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1312
-			$_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1313
-			$_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n";
1311
+			$_header .= 'Message-ID: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n";
1312
+			$_header .= 'References: <'.time().'.SMTPs-dolibarr-'.$trackid.'@'.$host.">\r\n";
1313
+			$_header .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host."\r\n";
1314 1314
 		}
1315 1315
 		else
1316 1316
 		{
1317
-			$_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
1317
+			$_header .= 'Message-ID: <'.time().'.SMTPs@'.$host.">\r\n";
1318 1318
 		}
1319
-		if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n";
1320
-		if ( $this->getMoreInHeader() )
1321
-		    $_header .= $this->getMoreInHeader();     // Value must include the "\r\n";
1319
+		if (!empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR']."\r\n";
1320
+		if ($this->getMoreInHeader())
1321
+		    $_header .= $this->getMoreInHeader(); // Value must include the "\r\n";
1322 1322
 
1323 1323
 		//$_header .=
1324 1324
 		//                 'Read-Receipt-To: '   . $this->getFrom( 'org' ) . "\r\n"
1325 1325
 		//                 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
1326 1326
 
1327
-		if ( $this->getSensitivity() )
1328
-		$_header .= 'Sensitivity: ' . $this->getSensitivity()  . "\r\n";
1327
+		if ($this->getSensitivity())
1328
+		$_header .= 'Sensitivity: '.$this->getSensitivity()."\r\n";
1329 1329
 
1330
-		if ( $this->_msgPriority != 3 )
1330
+		if ($this->_msgPriority != 3)
1331 1331
 		$_header .= $this->getPriority();
1332 1332
 
1333 1333
 
1334 1334
 		// @CHANGE LDR
1335
-		if ( $this->getDeliveryReceipt() )
1336
-		    $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
1337
-		if ( $this->getErrorsTo() )
1338
-		    $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
1339
-		if ( $this->getReplyTo() )
1340
-		    $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
1335
+		if ($this->getDeliveryReceipt())
1336
+		    $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr')."\r\n";
1337
+		if ($this->getErrorsTo())
1338
+		    $_header .= 'Errors-To: '.$this->getErrorsTo('addr')."\r\n";
1339
+		if ($this->getReplyTo())
1340
+		    $_header .= "Reply-To: ".$this->getReplyTo('addr')."\r\n";
1341 1341
 
1342
-		$_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n";
1343
-		$_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n";
1344
-		$_header .= 'Mime-Version: 1.0' . "\r\n";
1342
+		$_header .= 'X-Mailer: Dolibarr version '.DOL_VERSION.' (using SMTPs Mailer)'."\r\n";
1343
+		$_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART ? 'MAIN_MAIL_USE_MULTI_PART' : 'No MAIN_MAIL_USE_MULTI_PART')."\r\n";
1344
+		$_header .= 'Mime-Version: 1.0'."\r\n";
1345 1345
 
1346 1346
 
1347 1347
 		return $_header;
@@ -1358,7 +1358,7 @@  discard block
 block discarded – undo
1358 1358
 	{
1359 1359
 		//if ( $strContent )
1360 1360
 		//{
1361
-		if ( $strType == 'html' )
1361
+		if ($strType == 'html')
1362 1362
 		$strMimeType = 'text/html';
1363 1363
 		else
1364 1364
 		$strMimeType = 'text/plain';
@@ -1370,14 +1370,14 @@  discard block
 block discarded – undo
1370 1370
 		if ($strType == 'html')
1371 1371
 		{
1372 1372
 			// Similar code to forge a text from html is also in CMailFile.class.php
1373
-			$strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1373
+			$strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContent);
1374 1374
 			$strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1375 1375
 			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, "\r\n"));
1376 1376
 		}
1377 1377
 
1378 1378
 		// Make RFC2045 Compliant
1379 1379
 		//$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1380
-		$strContent = rtrim(wordwrap($strContent, 75, "\r\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1380
+		$strContent = rtrim(wordwrap($strContent, 75, "\r\n")); // TODO Using this method creates unexpected line break on text/plain content.
1381 1381
 
1382 1382
 		$this->_msgContent[$strType] = array();
1383 1383
 
@@ -1385,7 +1385,7 @@  discard block
 block discarded – undo
1385 1385
 		$this->_msgContent[$strType]['data']     = $strContent;
1386 1386
 		$this->_msgContent[$strType]['dataText'] = $strContentAltText;
1387 1387
 
1388
-		if ( $this->getMD5flag() )
1388
+		if ($this->getMD5flag())
1389 1389
 		$this->_msgContent[$strType]['md5']      = dol_hash($strContent, 3);
1390 1390
 		//}
1391 1391
 	}
@@ -1409,49 +1409,49 @@  discard block
 block discarded – undo
1409 1409
 		$keyCount = count($_types);
1410 1410
 
1411 1411
 		// If we have ZERO, we have a problem
1412
-		if( $keyCount === 0 )
1412
+		if ($keyCount === 0)
1413 1413
 		die ("Sorry, no content");
1414 1414
 
1415 1415
 		// If we have ONE, we can use the simple format
1416
-		else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1416
+		else if ($keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1417 1417
 		{
1418 1418
 			$_msgData = $this->_msgContent;
1419 1419
 			$_msgData = $_msgData[$_types[0]];
1420 1420
 
1421
-			$content = 'Content-Type: ' . $_msgData['mimeType'] . '; charset="' . $this->getCharSet() . '"' . "\r\n"
1422
-			. 'Content-Transfer-Encoding: ' . $this->getTransEncodeType() . "\r\n"
1423
-			. 'Content-Disposition: inline'  . "\r\n"
1424
-			. 'Content-Description: Message' . "\r\n";
1421
+			$content = 'Content-Type: '.$_msgData['mimeType'].'; charset="'.$this->getCharSet().'"'."\r\n"
1422
+			. 'Content-Transfer-Encoding: '.$this->getTransEncodeType()."\r\n"
1423
+			. 'Content-Disposition: inline'."\r\n"
1424
+			. 'Content-Description: Message'."\r\n";
1425 1425
 
1426
-			if ( $this->getMD5flag() )
1427
-			$content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
1426
+			if ($this->getMD5flag())
1427
+			$content .= 'Content-MD5: '.$_msgData['md5']."\r\n";
1428 1428
 
1429 1429
 			$content .= "\r\n"
1430
-			.  $_msgData['data'] . "\r\n";
1430
+			.  $_msgData['data']."\r\n";
1431 1431
 		}
1432 1432
 
1433 1433
 		// If we have more than ONE, we use the multi-part format
1434
-		else if( $keyCount >= 1 || ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1434
+		else if ($keyCount >= 1 || !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
1435 1435
 		{
1436 1436
 			// Since this is an actual multi-part message
1437 1437
 			// We need to define a content message Boundary
1438 1438
 			// NOTE: This was 'multipart/alternative', but Windows based mail servers have issues with this.
1439 1439
 
1440 1440
 			//$content = 'Content-Type: multipart/related; boundary="' . $this->_getBoundary() . '"'   . "\r\n";
1441
-			$content = 'Content-Type: multipart/mixed; boundary="' . $this->_getBoundary('mixed') . '"'   . "\r\n";
1441
+			$content = 'Content-Type: multipart/mixed; boundary="'.$this->_getBoundary('mixed').'"'."\r\n";
1442 1442
 
1443 1443
 			//                     . "\r\n"
1444 1444
 			//                     . 'This is a multi-part message in MIME format.' . "\r\n";
1445 1445
 			$content .= "Content-Transfer-Encoding: 8bit\r\n";
1446 1446
 			$content .= "\r\n";
1447 1447
 
1448
-			$content .= "--" . $this->_getBoundary('mixed') . "\r\n";
1448
+			$content .= "--".$this->_getBoundary('mixed')."\r\n";
1449 1449
 
1450 1450
 			if (key_exists('image', $this->_msgContent))     // If inline image found
1451 1451
 			{
1452
-				$content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1452
+				$content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n";
1453 1453
 				$content .= "\r\n";
1454
-				$content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1454
+				$content .= "--".$this->_getBoundary('alternative')."\r\n";
1455 1455
 			}
1456 1456
 
1457 1457
 
@@ -1459,93 +1459,93 @@  discard block
 block discarded – undo
1459 1459
 
1460 1460
 
1461 1461
 			// Loop through message content array
1462
-			foreach ($this->_msgContent as $type => $_content )
1462
+			foreach ($this->_msgContent as $type => $_content)
1463 1463
 			{
1464
-				if ( $type == 'attachment' )
1464
+				if ($type == 'attachment')
1465 1465
 				{
1466 1466
 					// loop through all attachments
1467
-					foreach ( $_content as $_file => $_data )
1467
+					foreach ($_content as $_file => $_data)
1468 1468
 					{
1469
-						$content .= "--" . $this->_getBoundary('mixed') . "\r\n"
1470
-						.  'Content-Disposition: attachment; filename="' . $_data['fileName'] . '"' . "\r\n"
1471
-						.  'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['fileName'] . '"' . "\r\n"
1472
-						.  'Content-Transfer-Encoding: base64' . "\r\n"
1473
-						.  'Content-Description: ' . $_data['fileName'] ."\r\n";
1469
+						$content .= "--".$this->_getBoundary('mixed')."\r\n"
1470
+						.  'Content-Disposition: attachment; filename="'.$_data['fileName'].'"'."\r\n"
1471
+						.  'Content-Type: '.$_data['mimeType'].'; name="'.$_data['fileName'].'"'."\r\n"
1472
+						.  'Content-Transfer-Encoding: base64'."\r\n"
1473
+						.  'Content-Description: '.$_data['fileName']."\r\n";
1474 1474
 
1475
-						if ( $this->getMD5flag() )
1476
-						$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1475
+						if ($this->getMD5flag())
1476
+						$content .= 'Content-MD5: '.$_data['md5']."\r\n";
1477 1477
 
1478
-						$content .= "\r\n" .  $_data['data'] . "\r\n\r\n";
1478
+						$content .= "\r\n".$_data['data']."\r\n\r\n";
1479 1479
 					}
1480 1480
 				}
1481 1481
 				// @CHANGE LDR
1482
-				else if ( $type == 'image' )
1482
+				else if ($type == 'image')
1483 1483
 				{
1484 1484
 					// loop through all images
1485
-					foreach ( $_content as $_image => $_data )
1485
+					foreach ($_content as $_image => $_data)
1486 1486
 					{
1487
-						$content .= "--" . $this->_getBoundary('related') . "\r\n";  // always related for an inline image
1487
+						$content .= "--".$this->_getBoundary('related')."\r\n"; // always related for an inline image
1488 1488
 
1489
-						$content .= 'Content-Type: ' . $_data['mimeType'] . '; name="' . $_data['imageName'] . '"' . "\r\n"
1490
-						.  'Content-Transfer-Encoding: base64' . "\r\n"
1491
-						.  'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
1492
-						.  'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
1489
+						$content .= 'Content-Type: '.$_data['mimeType'].'; name="'.$_data['imageName'].'"'."\r\n"
1490
+						.  'Content-Transfer-Encoding: base64'."\r\n"
1491
+						.  'Content-Disposition: inline; filename="'.$_data['imageName'].'"'."\r\n"
1492
+						.  'Content-ID: <'.$_data['cid'].'> '."\r\n";
1493 1493
 
1494
-						if ( $this->getMD5flag() )
1495
-						$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1494
+						if ($this->getMD5flag())
1495
+						$content .= 'Content-MD5: '.$_data['md5']."\r\n";
1496 1496
 
1497 1497
 						$content .= "\r\n"
1498
-						. $_data['data'] . "\r\n";
1498
+						. $_data['data']."\r\n";
1499 1499
 					}
1500 1500
 
1501 1501
 					// always end related and end alternative after inline images
1502
-					$content.= "--" . $this->_getBoundary('related') . "--" . "\r\n";
1503
-					$content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n";
1504
-					$content.= "\r\n";
1502
+					$content .= "--".$this->_getBoundary('related')."--"."\r\n";
1503
+					$content .= "\r\n"."--".$this->_getBoundary('alternative')."--"."\r\n";
1504
+					$content .= "\r\n";
1505 1505
 				}
1506 1506
 				else
1507 1507
 				{
1508 1508
 					if (key_exists('image', $this->_msgContent))
1509 1509
 					{
1510
-						$content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
1511
-						$content.= "\r\n" . ($_content['dataText']?$_content['dataText']:strip_tags($_content['data'])) . "\r\n"; // Add plain text message
1512
-						$content.= "--" . $this->_getBoundary('alternative') . "\r\n";
1513
-						$content.= 'Content-Type: multipart/related; boundary="' . $this->_getBoundary('related') . '"' . "\r\n";
1514
-						$content.= "\r\n";
1515
-						$content.= "--" . $this->_getBoundary('related') . "\r\n";
1510
+						$content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n";
1511
+						$content .= "\r\n".($_content['dataText'] ? $_content['dataText'] : strip_tags($_content['data']))."\r\n"; // Add plain text message
1512
+						$content .= "--".$this->_getBoundary('alternative')."\r\n";
1513
+						$content .= 'Content-Type: multipart/related; boundary="'.$this->_getBoundary('related').'"'."\r\n";
1514
+						$content .= "\r\n";
1515
+						$content .= "--".$this->_getBoundary('related')."\r\n";
1516 1516
 					}
1517 1517
 
1518
-					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part before html part
1518
+					if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part before html part
1519 1519
 					{
1520
-					    $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1520
+					    $content .= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"'."\r\n";
1521 1521
     					$content .= "\r\n";
1522
-	       				$content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1522
+	       				$content .= "--".$this->_getBoundary('alternative')."\r\n";
1523 1523
 
1524
-	       				$content.= "Content-Type: text/plain; charset=" . $this->getCharSet() . "\r\n";
1525
-	       				$content.= "\r\n". $_content['dataText'] . "\r\n";
1526
-	       				$content.= "--" . $this->_getBoundary('alternative') . "\r\n";
1524
+	       				$content .= "Content-Type: text/plain; charset=".$this->getCharSet()."\r\n";
1525
+	       				$content .= "\r\n".$_content['dataText']."\r\n";
1526
+	       				$content .= "--".$this->_getBoundary('alternative')."\r\n";
1527 1527
 					}
1528 1528
 
1529
-					$content .= 'Content-Type: ' . $_content['mimeType'] . '; '
1529
+					$content .= 'Content-Type: '.$_content['mimeType'].'; '
1530 1530
 					//                             . 'charset="' . $this->getCharSet() . '"';
1531
-					. 'charset=' . $this->getCharSet() . '';
1531
+					. 'charset='.$this->getCharSet().'';
1532 1532
 
1533 1533
 					//                    $content .= ( $type == 'html') ? '; name="HTML Part"' : '';
1534
-					$content .=  "\r\n";
1534
+					$content .= "\r\n";
1535 1535
 					//                    $content .= 'Content-Transfer-Encoding: ';
1536 1536
 					//                    $content .= ($type == 'html') ? 'quoted-printable' : $this->getTransEncodeType();
1537 1537
 					//                    $content .=  "\r\n"
1538 1538
 					//                             . 'Content-Disposition: inline'  . "\r\n"
1539 1539
 					//                             . 'Content-Description: ' . $type . ' message' . "\r\n";
1540 1540
 
1541
-					if ( $this->getMD5flag() )
1542
-					$content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
1541
+					if ($this->getMD5flag())
1542
+					$content .= 'Content-MD5: '.$_content['md5']."\r\n";
1543 1543
 
1544
-					$content .= "\r\n"	. $_content['data'] . "\r\n";
1544
+					$content .= "\r\n".$_content['data']."\r\n";
1545 1545
 
1546
-					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part after html part
1546
+					if (!key_exists('image', $this->_msgContent) && $_content['dataText'] && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part after html part
1547 1547
 					{
1548
-					    $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n";
1548
+					    $content .= "--".$this->_getBoundary('alternative')."--"."\r\n";
1549 1549
 					}
1550 1550
 
1551 1551
 					$content .= "\r\n";
@@ -1554,7 +1554,7 @@  discard block
 block discarded – undo
1554 1554
 
1555 1555
 			// Close message boundries
1556 1556
 			//            $content .= "\r\n--" . $this->_getBoundary() . '--' . "\r\n" ;
1557
-			$content .= "--" . $this->_getBoundary('mixed') . '--' . "\r\n" ;
1557
+			$content .= "--".$this->_getBoundary('mixed').'--'."\r\n";
1558 1558
 		}
1559 1559
 
1560 1560
 		return $content;
@@ -1571,15 +1571,15 @@  discard block
 block discarded – undo
1571 1571
 	 */
1572 1572
 	function setAttachment($strContent, $strFileName = 'unknown', $strMimeType = 'unknown')
1573 1573
 	{
1574
-		if ( $strContent )
1574
+		if ($strContent)
1575 1575
 		{
1576
-			$strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n"));    // 76 max is defined into http://tools.ietf.org/html/rfc2047
1576
+			$strContent = rtrim(chunk_split(base64_encode($strContent), 76, "\r\n")); // 76 max is defined into http://tools.ietf.org/html/rfc2047
1577 1577
 
1578 1578
 			$this->_msgContent['attachment'][$strFileName]['mimeType'] = $strMimeType;
1579 1579
 			$this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
1580 1580
 			$this->_msgContent['attachment'][$strFileName]['data']     = $strContent;
1581 1581
 
1582
-			if ( $this->getMD5flag() )
1582
+			if ($this->getMD5flag())
1583 1583
 			$this->_msgContent['attachment'][$strFileName]['md5']      = dol_hash($strContent, 3);
1584 1584
 		}
1585 1585
 	}
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
 			$this->_msgContent['image'][$strImageName]['cid']      = $strImageCid;
1607 1607
 			$this->_msgContent['image'][$strImageName]['data']     = $strContent;
1608 1608
 
1609
-			if ( $this->getMD5flag() )
1609
+			if ($this->getMD5flag())
1610 1610
 			$this->_msgContent['image'][$strImageName]['md5']      = dol_hash($strContent, 3);
1611 1611
 		}
1612 1612
 	}
@@ -1626,8 +1626,8 @@  discard block
 block discarded – undo
1626 1626
 	 */
1627 1627
 	function setSensitivity($_value = 0)
1628 1628
 	{
1629
-		if ( ( is_numeric($_value) ) &&
1630
-		( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
1629
+		if ((is_numeric($_value)) &&
1630
+		(($_value >= 0) && ($_value <= 3)))
1631 1631
 		$this->_msgSensitivity = $_value;
1632 1632
 	}
1633 1633
 
@@ -1659,10 +1659,10 @@  discard block
 block discarded – undo
1659 1659
 	 * @param 	integer 	$_value 	Message Priority
1660 1660
 	 * @return 	void
1661 1661
 	 */
1662
-	function setPriority( $_value = 3 )
1662
+	function setPriority($_value = 3)
1663 1663
 	{
1664
-		if ( ( is_numeric($_value) ) &&
1665
-		( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
1664
+		if ((is_numeric($_value)) &&
1665
+		(($_value >= 0) && ($_value <= 5)))
1666 1666
 		$this->_msgPriority = $_value;
1667 1667
 	}
1668 1668
 
@@ -1680,9 +1680,9 @@  discard block
 block discarded – undo
1680 1680
 	 */
1681 1681
 	function getPriority()
1682 1682
 	{
1683
-		return 'Importance: ' . $this->_aryPriority[$this->_msgPriority] . "\r\n"
1684
-		. 'Priority: '   . $this->_aryPriority[$this->_msgPriority] . "\r\n"
1685
-		. 'X-Priority: ' . $this->_msgPriority . ' (' . $this->_aryPriority[$this->_msgPriority] . ')' . "\r\n";
1683
+		return 'Importance: '.$this->_aryPriority[$this->_msgPriority]."\r\n"
1684
+		. 'Priority: '.$this->_aryPriority[$this->_msgPriority]."\r\n"
1685
+		. 'X-Priority: '.$this->_msgPriority.' ('.$this->_aryPriority[$this->_msgPriority].')'."\r\n";
1686 1686
 	}
1687 1687
 
1688 1688
 	/**
@@ -1716,7 +1716,7 @@  discard block
 block discarded – undo
1716 1716
 	 */
1717 1717
 	function setXheader($strXdata)
1718 1718
 	{
1719
-		if ( $strXdata )
1719
+		if ($strXdata)
1720 1720
 		$this->_msgXheader[] = $strXdata;
1721 1721
 	}
1722 1722
 
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
 	 */
1738 1738
 	function _setBoundary()
1739 1739
 	{
1740
-		$this->_smtpsBoundary = "multipart_x." . time() . ".x_boundary";
1740
+		$this->_smtpsBoundary = "multipart_x.".time().".x_boundary";
1741 1741
 		$this->_smtpsRelatedBoundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);
1742 1742
 		$this->_smtpsAlternativeBoundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);
1743 1743
 	}
@@ -1748,7 +1748,7 @@  discard block
 block discarded – undo
1748 1748
 	 * @param  string $type				Type of boundary
1749 1749
 	 * @return string $_smtpsBoundary 	MIME message Boundary
1750 1750
 	 */
1751
-	function _getBoundary($type='mixed')
1751
+	function _getBoundary($type = 'mixed')
1752 1752
 	{
1753 1753
 		if ($type == 'mixed') return $this->_smtpsBoundary;
1754 1754
 		else if ($type == 'related') return $this->_smtpsRelatedBoundary;
@@ -1776,11 +1776,11 @@  discard block
 block discarded – undo
1776 1776
 		$server_response = '';
1777 1777
 
1778 1778
         // avoid infinite loop
1779
-        $limit=0;
1779
+        $limit = 0;
1780 1780
 
1781
-		while (substr($server_response,3,1) != ' ' && $limit<100)
1781
+		while (substr($server_response, 3, 1) != ' ' && $limit < 100)
1782 1782
 		{
1783
-			if (! ($server_response = fgets($socket, 256)))
1783
+			if (!($server_response = fgets($socket, 256)))
1784 1784
 			{
1785 1785
 				$this->_setErr(121, "Couldn't get mail server response codes");
1786 1786
 				$_retVal = false;
@@ -1789,7 +1789,7 @@  discard block
 block discarded – undo
1789 1789
             $limit++;
1790 1790
 		}
1791 1791
 
1792
-		if (! (substr($server_response, 0, 3) == $response))
1792
+		if (!(substr($server_response, 0, 3) == $response))
1793 1793
 		{
1794 1794
 			$this->_setErr(120, "Ran into problems sending Mail.\r\nResponse: $server_response");
1795 1795
 			$_retVal = false;
@@ -1807,14 +1807,14 @@  discard block
 block discarded – undo
1807 1807
 	 * @param 	string		$CRLF			CRLF
1808 1808
 	 * @return 	boolean|null						True or false
1809 1809
 	 */
1810
-	function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
1810
+	function socket_send_str($_strSend, $_returnCode = null, $CRLF = "\r\n")
1811 1811
 	{
1812 1812
         // phpcs:enable
1813
-		if ($this->_debug) $this->log.=$_strSend;	// @CHANGE LDR for log
1814
-		fputs($this->socket, $_strSend . $CRLF);
1815
-		if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF;
1813
+		if ($this->_debug) $this->log .= $_strSend; // @CHANGE LDR for log
1814
+		fputs($this->socket, $_strSend.$CRLF);
1815
+		if ($this->_debug) $this->log .= ' ('.$_returnCode.')'.$CRLF;
1816 1816
 
1817
-		if ( $_returnCode )
1817
+		if ($_returnCode)
1818 1818
 		return $this->server_parse($this->socket, $_returnCode);
1819 1819
 	}
1820 1820
 
@@ -1828,7 +1828,7 @@  discard block
 block discarded – undo
1828 1828
 	 * @param  string $_errMsg  Error Message
1829 1829
 	 * @return void
1830 1830
      */
1831
-    function _setErr( $_errNum, $_errMsg )
1831
+    function _setErr($_errNum, $_errMsg)
1832 1832
     {
1833 1833
         $this->_smtpsErrors[] = array(
1834 1834
             'num' => $_errNum,
@@ -1847,9 +1847,9 @@  discard block
 block discarded – undo
1847 1847
 
1848 1848
 		if (is_array($this->_smtpsErrors))
1849 1849
 		{
1850
-			foreach ( $this->_smtpsErrors as $_err => $_info )
1850
+			foreach ($this->_smtpsErrors as $_err => $_info)
1851 1851
 			{
1852
-				$_errMsg[] = 'Error [' . $_info['num'] .']: '. $_info['msg'];
1852
+				$_errMsg[] = 'Error ['.$_info['num'].']: '.$_info['msg'];
1853 1853
 			}
1854 1854
 		}
1855 1855
 
Please login to merge, or discard this patch.
Braces   +188 added lines, -125 removed lines patch added patch discarded remove patch
@@ -300,8 +300,9 @@  discard block
 block discarded – undo
300 300
      */
301 301
 	function setErrorsTo($_strErrorsTo)
302 302
 	{
303
-		if ( $_strErrorsTo )
304
-		$this->_errorsTo = $this->_strip_email($_strErrorsTo);
303
+		if ( $_strErrorsTo ) {
304
+				$this->_errorsTo = $this->_strip_email($_strErrorsTo);
305
+		}
305 306
 	}
306 307
 
307 308
     /**
@@ -314,10 +315,11 @@  discard block
 block discarded – undo
314 315
 	{
315 316
 		$_retValue = '';
316 317
 
317
-		if ( $_part === true )
318
-		$_retValue = $this->_errorsTo;
319
-		else
320
-		$_retValue = $this->_errorsTo[$_part];
318
+		if ( $_part === true ) {
319
+				$_retValue = $this->_errorsTo;
320
+		} else {
321
+				$_retValue = $this->_errorsTo[$_part];
322
+		}
321 323
 
322 324
 		return $_retValue;
323 325
 	}
@@ -373,8 +375,7 @@  discard block
 block discarded – undo
373 375
 		{
374 376
 			$this->_setErr(99, $host . ' is either offline or is an invalid host name.');
375 377
 			$_retVal = false;
376
-		}
377
-		else
378
+		} else
378 379
 		{
379 380
 			//See if we can connect to the SMTP server
380 381
 			if ($this->socket = @fsockopen(
@@ -383,23 +384,28 @@  discard block
 block discarded – undo
383 384
     			$this->errno,           // actual system level error
384 385
     			$this->errstr,          // and any text that goes with the error
385 386
     			$this->_smtpTimeout
386
-			))  // timeout for reading/writing data over the socket
387
+			)) {
388
+			    // timeout for reading/writing data over the socket
387 389
 			{
388 390
 				// Fix from PHP SMTP class by 'Chris Ryan'
389 391
 				// Sometimes the SMTP server takes a little longer to respond
390 392
 				// so we will give it a longer timeout for the first read
391 393
 				// Windows still does not have support for this timeout function
392 394
 				if (function_exists('stream_set_timeout')) stream_set_timeout($this->socket, $this->_smtpTimeout, 0);
395
+			}
393 396
 
394 397
 				// Check response from Server
395
-				if ( $_retVal = $this->server_parse($this->socket, "220") )
396
-				$_retVal = $this->socket;
398
+				if ( $_retVal = $this->server_parse($this->socket, "220") ) {
399
+								$_retVal = $this->socket;
400
+				}
397 401
 			}
398 402
 			// This connection attempt failed.
399 403
 			else
400 404
 			{
401 405
 				// @CHANGE LDR
402
-				if (empty($this->errstr)) $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
406
+				if (empty($this->errstr)) {
407
+				    $this->errstr='Failed to connect with fsockopen host='.$this->getHost().' port='.$this->getPort();
408
+				}
403 409
 				$this->_setErr($this->errno, $this->errstr);
404 410
 				$_retVal = false;
405 411
 			}
@@ -429,7 +435,9 @@  discard block
 block discarded – undo
429 435
 		$host=preg_replace('@ssl://@i','',$host);	// Remove prefix
430 436
 		$host=preg_replace('@tls://@i','',$host);	// Remove prefix
431 437
 
432
-		if ($usetls) $host='tls://'.$host;
438
+		if ($usetls) {
439
+		    $host='tls://'.$host;
440
+		}
433 441
 
434 442
 		$hosth = $host;
435 443
 
@@ -506,10 +514,10 @@  discard block
 block discarded – undo
506 514
 
507 515
 			// The error here just means the ID/password combo doesn't work.
508 516
 			// There is not a method to determine which is the problem, ID or password
509
-			if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') )
510
-			$this->_setErr(130, 'Invalid Authentication Credentials.');
511
-		}
512
-		else
517
+			if ( ! $_retVal = $this->socket_send_str(base64_encode($this->_smtpsPW), '235') ) {
518
+						$this->_setErr(130, 'Invalid Authentication Credentials.');
519
+			}
520
+		} else
513 521
 		{
514 522
 			$this->_setErr(126, '"' . $host . '" does not support authenticated connections.');
515 523
 		}
@@ -672,14 +680,17 @@  discard block
 block discarded – undo
672 680
 		{
673 681
 			// Set these properties ONLY if they are set in the php.ini file.
674 682
 			// Otherwise the default values will be used.
675
-			if ( $_host = ini_get('SMTPs') )
676
-			$this->setHost($_host);
683
+			if ( $_host = ini_get('SMTPs') ) {
684
+						$this->setHost($_host);
685
+			}
677 686
 
678
-			if ( $_port = ini_get('smtp_port') )
679
-			$this->setPort($_port);
687
+			if ( $_port = ini_get('smtp_port') ) {
688
+						$this->setPort($_port);
689
+			}
680 690
 
681
-			if ( $_from = ini_get('sendmail_from') )
682
-			$this->setFrom($_from);
691
+			if ( $_from = ini_get('sendmail_from') ) {
692
+						$this->setFrom($_from);
693
+			}
683 694
 		}
684 695
 
685 696
 		// Send back what we have
@@ -698,8 +709,9 @@  discard block
 block discarded – undo
698 709
 	function setTransportType($_type = 0)
699 710
 	{
700 711
 		if ( ( is_numeric($_type) ) &&
701
-		( ( $_type >= 0 ) && ( $_type <= 3 ) ) )
702
-		$this->_transportType = $_type;
712
+		( ( $_type >= 0 ) && ( $_type <= 3 ) ) ) {
713
+				$this->_transportType = $_type;
714
+		}
703 715
 	}
704 716
 
705 717
 	/**
@@ -740,8 +752,9 @@  discard block
 block discarded – undo
740 752
 	 */
741 753
 	function setHost($_strHost)
742 754
 	{
743
-		if ( $_strHost )
744
-		$this->_smtpsHost = $_strHost;
755
+		if ( $_strHost ) {
756
+				$this->_smtpsHost = $_strHost;
757
+		}
745 758
 	}
746 759
 
747 760
 	/**
@@ -766,8 +779,9 @@  discard block
 block discarded – undo
766 779
 	function setPort($_intPort)
767 780
 	{
768 781
 		if ( ( is_numeric($_intPort) ) &&
769
-		( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) )
770
-		$this->_smtpsPort = $_intPort;
782
+		( ( $_intPort >= 1 ) && ( $_intPort <= 65536 ) ) ) {
783
+				$this->_smtpsPort = $_intPort;
784
+		}
771 785
 	}
772 786
 
773 787
 	/**
@@ -832,8 +846,9 @@  discard block
 block discarded – undo
832 846
 	 */
833 847
 	function setCharSet($_strCharSet)
834 848
 	{
835
-		if ( $_strCharSet )
836
-		$this->_smtpsCharSet = $_strCharSet;
849
+		if ( $_strCharSet ) {
850
+				$this->_smtpsCharSet = $_strCharSet;
851
+		}
837 852
 	}
838 853
 
839 854
 	/**
@@ -863,8 +878,9 @@  discard block
 block discarded – undo
863 878
 	 */
864 879
 	function setTransEncode($_strTransEncode)
865 880
 	{
866
-		if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes))
867
-		$this->_smtpsTransEncode = $_strTransEncode;
881
+		if (array_search($_strTransEncode, $this->_smtpsTransEncodeTypes)) {
882
+				$this->_smtpsTransEncode = $_strTransEncode;
883
+		}
868 884
 	}
869 885
 
870 886
 	/**
@@ -895,8 +911,9 @@  discard block
 block discarded – undo
895 911
 	 */
896 912
 	function setTransEncodeType($_strTransEncodeType)
897 913
 	{
898
-		if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes))
899
-		$this->_smtpsTransEncodeType = $_strTransEncodeType;
914
+		if (array_search($_strTransEncodeType, $this->_smtpsTransEncodeTypes)) {
915
+				$this->_smtpsTransEncodeType = $_strTransEncodeType;
916
+		}
900 917
 	}
901 918
 
902 919
 	/**
@@ -920,8 +937,9 @@  discard block
 block discarded – undo
920 937
 	 */
921 938
 	function setFrom($_strFrom)
922 939
 	{
923
-		if ( $_strFrom )
924
-		$this->_msgFrom = $this->_strip_email($_strFrom);
940
+		if ( $_strFrom ) {
941
+				$this->_msgFrom = $this->_strip_email($_strFrom);
942
+		}
925 943
 	}
926 944
 
927 945
 	/**
@@ -934,10 +952,11 @@  discard block
 block discarded – undo
934 952
 	{
935 953
 		$_retValue = '';
936 954
 
937
-		if ( $_part === true )
938
-		$_retValue = $this->_msgFrom;
939
-		else
940
-		$_retValue = $this->_msgFrom[$_part];
955
+		if ( $_part === true ) {
956
+				$_retValue = $this->_msgFrom;
957
+		} else {
958
+				$_retValue = $this->_msgFrom[$_part];
959
+		}
941 960
 
942 961
 		return $_retValue;
943 962
 	}
@@ -950,8 +969,9 @@  discard block
 block discarded – undo
950 969
 	 */
951 970
 	function setReplyTo($_strReplyTo)
952 971
 	{
953
-	    if ( $_strReplyTo )
954
-	        $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
972
+	    if ( $_strReplyTo ) {
973
+	    	        $this->_msgReplyTo = $this->_strip_email($_strReplyTo);
974
+	    }
955 975
 	}
956 976
 
957 977
 	/**
@@ -964,10 +984,11 @@  discard block
 block discarded – undo
964 984
 	{
965 985
 	    $_retValue = '';
966 986
 
967
-	    if ( $_part === true )
968
-	        $_retValue = $this->_msgReplyTo;
969
-	    else
970
-	        $_retValue = $this->_msgReplyTo[$_part];
987
+	    if ( $_part === true ) {
988
+	    	        $_retValue = $this->_msgReplyTo;
989
+	    } else {
990
+	    	        $_retValue = $this->_msgReplyTo[$_part];
991
+	    }
971 992
 
972 993
 	    return $_retValue;
973 994
 	}
@@ -996,13 +1017,15 @@  discard block
 block discarded – undo
996 1017
 			if ( is_string($_addrList) )
997 1018
 			{
998 1019
 				// This could be a COMMA delimited string
999
-				if ( strstr($_addrList, ',') )
1000
-				// "explode "list" into an array
1020
+				if ( strstr($_addrList, ',') ) {
1021
+								// "explode "list" into an array
1001 1022
 				$_addrList = explode(',', $_addrList);
1023
+				}
1002 1024
 
1003 1025
 				// Stick it in an array
1004
-				else
1005
-				$_addrList = array($_addrList);
1026
+				else {
1027
+								$_addrList = array($_addrList);
1028
+				}
1006 1029
 			}
1007 1030
 
1008 1031
 			// take the array of addresses and split them further
@@ -1076,13 +1099,14 @@  discard block
 block discarded – undo
1076 1099
 		if ( count($_tmpAry) == 2 )
1077 1100
 		{
1078 1101
 			// We may not really have a "Real Name"
1079
-			if ( $_tmpAry[0])
1080
-			$_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1102
+			if ( $_tmpAry[0]) {
1103
+						$_aryEmail['real'] = trim($_tmpAry[0], ' ">');
1104
+			}
1081 1105
 
1082 1106
 			$_aryEmail['addr'] = $_tmpAry[1];
1107
+		} else {
1108
+				$_aryEmail['addr'] = $_tmpAry[0];
1083 1109
 		}
1084
-		else
1085
-		$_aryEmail['addr'] = $_tmpAry[0];
1086 1110
 
1087 1111
 		// Pull User Name and Host.tld apart
1088 1112
 		list($_aryEmail['user'], $_aryEmail['host'] ) = explode('@', $_aryEmail['addr']);
@@ -1149,12 +1173,13 @@  discard block
 block discarded – undo
1149 1173
 					{
1150 1174
 						foreach ( $this->_msgRecipients[$_host][$_which] as $_addr => $_realName )
1151 1175
 						{
1152
-							if ( $_realName )	// @CHANGE LDR
1176
+							if ( $_realName ) {
1177
+							    // @CHANGE LDR
1153 1178
 							{
1154 1179
 								$_realName = '"' . $_realName . '"';
1155
-								$_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
1156 1180
 							}
1157
-							else
1181
+								$_RCPT_list[] = $_realName . ' <' . $_addr . '@' . $_host . '>';
1182
+							} else
1158 1183
 							{
1159 1184
 								$_RCPT_list[] = $_addr . '@' . $_host;
1160 1185
 							}
@@ -1163,14 +1188,12 @@  discard block
 block discarded – undo
1163 1188
 				}
1164 1189
 
1165 1190
 				return implode(', ', $_RCPT_list);
1166
-			}
1167
-			else
1191
+			} else
1168 1192
 			{
1169 1193
 				$this->_setErr(101, 'No eMail Address for message to be sent to.');
1170 1194
 				return false;
1171 1195
 			}
1172
-		}
1173
-		else
1196
+		} else
1174 1197
 		{
1175 1198
 			$this->_setErr(102, 'eMail type not defined.');
1176 1199
 			return false;
@@ -1185,8 +1208,9 @@  discard block
 block discarded – undo
1185 1208
 	 */
1186 1209
 	function setTO($_addrTo)
1187 1210
 	{
1188
-		if ( $_addrTo )
1189
-		$this->_buildAddrList('to', $_addrTo);
1211
+		if ( $_addrTo ) {
1212
+				$this->_buildAddrList('to', $_addrTo);
1213
+		}
1190 1214
 	}
1191 1215
 
1192 1216
 	/**
@@ -1207,8 +1231,9 @@  discard block
 block discarded – undo
1207 1231
 	 */
1208 1232
 	function setCC($_strCC)
1209 1233
 	{
1210
-		if ( $_strCC )
1211
-		$this->_buildAddrList('cc', $_strCC);
1234
+		if ( $_strCC ) {
1235
+				$this->_buildAddrList('cc', $_strCC);
1236
+		}
1212 1237
 	}
1213 1238
 
1214 1239
 	/**
@@ -1229,8 +1254,9 @@  discard block
 block discarded – undo
1229 1254
 	 */
1230 1255
 	function setBCC($_strBCC)
1231 1256
 	{
1232
-		if ( $_strBCC )
1233
-		$this->_buildAddrList('bcc', $_strBCC);
1257
+		if ( $_strBCC ) {
1258
+				$this->_buildAddrList('bcc', $_strBCC);
1259
+		}
1234 1260
 	}
1235 1261
 
1236 1262
 	/**
@@ -1251,8 +1277,9 @@  discard block
 block discarded – undo
1251 1277
 	 */
1252 1278
 	function setSubject($_strSubject = '')
1253 1279
 	{
1254
-		if ( $_strSubject )
1255
-		$this->_msgSubject = $_strSubject;
1280
+		if ( $_strSubject ) {
1281
+				$this->_msgSubject = $_strSubject;
1282
+		}
1256 1283
 	}
1257 1284
 
1258 1285
 	/**
@@ -1277,8 +1304,9 @@  discard block
 block discarded – undo
1277 1304
 		$_header = 'From: '       . $this->getFrom('org') . "\r\n"
1278 1305
 		. 'To: '         . $this->getTO()          . "\r\n";
1279 1306
 
1280
-		if ( $this->getCC() )
1281
-		$_header .= 'Cc: ' . $this->getCC()  . "\r\n";
1307
+		if ( $this->getCC() ) {
1308
+				$_header .= 'Cc: ' . $this->getCC()  . "\r\n";
1309
+		}
1282 1310
 
1283 1311
 		/* Note:
1284 1312
 		 * BCC email addresses must be listed in the RCPT TO command list,
@@ -1311,33 +1339,41 @@  discard block
 block discarded – undo
1311 1339
 			$_header .= 'Message-ID: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1312 1340
 			$_header .= 'References: <' . time() . '.SMTPs-dolibarr-'.$trackid.'@' . $host . ">\r\n";
1313 1341
 			$_header .= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host . "\r\n";
1314
-		}
1315
-		else
1342
+		} else
1316 1343
 		{
1317 1344
 			$_header .= 'Message-ID: <' . time() . '.SMTPs@' . $host . ">\r\n";
1318 1345
 		}
1319
-		if (! empty($_SERVER['REMOTE_ADDR'])) $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n";
1320
-		if ( $this->getMoreInHeader() )
1321
-		    $_header .= $this->getMoreInHeader();     // Value must include the "\r\n";
1346
+		if (! empty($_SERVER['REMOTE_ADDR'])) {
1347
+		    $_header .= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. "\r\n";
1348
+		}
1349
+		if ( $this->getMoreInHeader() ) {
1350
+				    $_header .= $this->getMoreInHeader();
1351
+		}
1352
+		// Value must include the "\r\n";
1322 1353
 
1323 1354
 		//$_header .=
1324 1355
 		//                 'Read-Receipt-To: '   . $this->getFrom( 'org' ) . "\r\n"
1325 1356
 		//                 'Return-Receipt-To: ' . $this->getFrom( 'org' ) . "\r\n";
1326 1357
 
1327
-		if ( $this->getSensitivity() )
1328
-		$_header .= 'Sensitivity: ' . $this->getSensitivity()  . "\r\n";
1358
+		if ( $this->getSensitivity() ) {
1359
+				$_header .= 'Sensitivity: ' . $this->getSensitivity()  . "\r\n";
1360
+		}
1329 1361
 
1330
-		if ( $this->_msgPriority != 3 )
1331
-		$_header .= $this->getPriority();
1362
+		if ( $this->_msgPriority != 3 ) {
1363
+				$_header .= $this->getPriority();
1364
+		}
1332 1365
 
1333 1366
 
1334 1367
 		// @CHANGE LDR
1335
-		if ( $this->getDeliveryReceipt() )
1336
-		    $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
1337
-		if ( $this->getErrorsTo() )
1338
-		    $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
1339
-		if ( $this->getReplyTo() )
1340
-		    $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
1368
+		if ( $this->getDeliveryReceipt() ) {
1369
+				    $_header .= 'Disposition-Notification-To: '.$this->getFrom('addr') . "\r\n";
1370
+		}
1371
+		if ( $this->getErrorsTo() ) {
1372
+				    $_header .= 'Errors-To: '.$this->getErrorsTo('addr') . "\r\n";
1373
+		}
1374
+		if ( $this->getReplyTo() ) {
1375
+				    $_header .= "Reply-To: ".$this->getReplyTo('addr') ."\r\n";
1376
+		}
1341 1377
 
1342 1378
 		$_header .= 'X-Mailer: Dolibarr version ' . DOL_VERSION .' (using SMTPs Mailer)' . "\r\n";
1343 1379
 		$_header .= 'X-Dolibarr-Option: '.($conf->global->MAIN_MAIL_USE_MULTI_PART?'MAIN_MAIL_USE_MULTI_PART':'No MAIN_MAIL_USE_MULTI_PART') . "\r\n";
@@ -1358,10 +1394,11 @@  discard block
 block discarded – undo
1358 1394
 	{
1359 1395
 		//if ( $strContent )
1360 1396
 		//{
1361
-		if ( $strType == 'html' )
1362
-		$strMimeType = 'text/html';
1363
-		else
1364
-		$strMimeType = 'text/plain';
1397
+		if ( $strType == 'html' ) {
1398
+				$strMimeType = 'text/html';
1399
+		} else {
1400
+				$strMimeType = 'text/plain';
1401
+		}
1365 1402
 
1366 1403
 		// Make RFC821 Compliant, replace bare linefeeds
1367 1404
 		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $strContent);
@@ -1385,8 +1422,9 @@  discard block
 block discarded – undo
1385 1422
 		$this->_msgContent[$strType]['data']     = $strContent;
1386 1423
 		$this->_msgContent[$strType]['dataText'] = $strContentAltText;
1387 1424
 
1388
-		if ( $this->getMD5flag() )
1389
-		$this->_msgContent[$strType]['md5']      = dol_hash($strContent, 3);
1425
+		if ( $this->getMD5flag() ) {
1426
+				$this->_msgContent[$strType]['md5']      = dol_hash($strContent, 3);
1427
+		}
1390 1428
 		//}
1391 1429
 	}
1392 1430
 
@@ -1409,8 +1447,9 @@  discard block
 block discarded – undo
1409 1447
 		$keyCount = count($_types);
1410 1448
 
1411 1449
 		// If we have ZERO, we have a problem
1412
-		if( $keyCount === 0 )
1413
-		die ("Sorry, no content");
1450
+		if( $keyCount === 0 ) {
1451
+				die ("Sorry, no content");
1452
+		}
1414 1453
 
1415 1454
 		// If we have ONE, we can use the simple format
1416 1455
 		else if( $keyCount === 1 && empty($conf->global->MAIN_MAIL_USE_MULTI_PART))
@@ -1423,8 +1462,9 @@  discard block
 block discarded – undo
1423 1462
 			. 'Content-Disposition: inline'  . "\r\n"
1424 1463
 			. 'Content-Description: Message' . "\r\n";
1425 1464
 
1426
-			if ( $this->getMD5flag() )
1427
-			$content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
1465
+			if ( $this->getMD5flag() ) {
1466
+						$content .= 'Content-MD5: ' . $_msgData['md5'] . "\r\n";
1467
+			}
1428 1468
 
1429 1469
 			$content .= "\r\n"
1430 1470
 			.  $_msgData['data'] . "\r\n";
@@ -1447,9 +1487,11 @@  discard block
 block discarded – undo
1447 1487
 
1448 1488
 			$content .= "--" . $this->_getBoundary('mixed') . "\r\n";
1449 1489
 
1450
-			if (key_exists('image', $this->_msgContent))     // If inline image found
1490
+			if (key_exists('image', $this->_msgContent)) {
1491
+			    // If inline image found
1451 1492
 			{
1452 1493
 				$content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1494
+			}
1453 1495
 				$content .= "\r\n";
1454 1496
 				$content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1455 1497
 			}
@@ -1472,8 +1514,9 @@  discard block
 block discarded – undo
1472 1514
 						.  'Content-Transfer-Encoding: base64' . "\r\n"
1473 1515
 						.  'Content-Description: ' . $_data['fileName'] ."\r\n";
1474 1516
 
1475
-						if ( $this->getMD5flag() )
1476
-						$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1517
+						if ( $this->getMD5flag() ) {
1518
+												$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1519
+						}
1477 1520
 
1478 1521
 						$content .= "\r\n" .  $_data['data'] . "\r\n\r\n";
1479 1522
 					}
@@ -1491,8 +1534,9 @@  discard block
 block discarded – undo
1491 1534
 						.  'Content-Disposition: inline; filename="' . $_data['imageName'] . '"' . "\r\n"
1492 1535
 						.  'Content-ID: <' . $_data['cid'] . '> ' . "\r\n";
1493 1536
 
1494
-						if ( $this->getMD5flag() )
1495
-						$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1537
+						if ( $this->getMD5flag() ) {
1538
+												$content .= 'Content-MD5: ' . $_data['md5'] . "\r\n";
1539
+						}
1496 1540
 
1497 1541
 						$content .= "\r\n"
1498 1542
 						. $_data['data'] . "\r\n";
@@ -1502,8 +1546,7 @@  discard block
 block discarded – undo
1502 1546
 					$content.= "--" . $this->_getBoundary('related') . "--" . "\r\n";
1503 1547
 					$content.= "\r\n" . "--" . $this->_getBoundary('alternative') . "--" . "\r\n";
1504 1548
 					$content.= "\r\n";
1505
-				}
1506
-				else
1549
+				} else
1507 1550
 				{
1508 1551
 					if (key_exists('image', $this->_msgContent))
1509 1552
 					{
@@ -1515,9 +1558,11 @@  discard block
 block discarded – undo
1515 1558
 						$content.= "--" . $this->_getBoundary('related') . "\r\n";
1516 1559
 					}
1517 1560
 
1518
-					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part before html part
1561
+					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1562
+					    // Add plain text message part before html part
1519 1563
 					{
1520 1564
 					    $content.= 'Content-Type: multipart/alternative; boundary="'.$this->_getBoundary('alternative').'"' . "\r\n";
1565
+					}
1521 1566
     					$content .= "\r\n";
1522 1567
 	       				$content .= "--" . $this->_getBoundary('alternative') . "\r\n";
1523 1568
 
@@ -1538,15 +1583,18 @@  discard block
 block discarded – undo
1538 1583
 					//                             . 'Content-Disposition: inline'  . "\r\n"
1539 1584
 					//                             . 'Content-Description: ' . $type . ' message' . "\r\n";
1540 1585
 
1541
-					if ( $this->getMD5flag() )
1542
-					$content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
1586
+					if ( $this->getMD5flag() ) {
1587
+										$content .= 'Content-MD5: ' . $_content['md5'] . "\r\n";
1588
+					}
1543 1589
 
1544 1590
 					$content .= "\r\n"	. $_content['data'] . "\r\n";
1545 1591
 
1546
-					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))  // Add plain text message part after html part
1592
+					if (! key_exists('image', $this->_msgContent) && $_content['dataText'] && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1593
+					    // Add plain text message part after html part
1547 1594
 					{
1548 1595
 					    $content.= "--" . $this->_getBoundary('alternative') . "--". "\r\n";
1549 1596
 					}
1597
+					}
1550 1598
 
1551 1599
 					$content .= "\r\n";
1552 1600
 				}
@@ -1579,8 +1627,9 @@  discard block
 block discarded – undo
1579 1627
 			$this->_msgContent['attachment'][$strFileName]['fileName'] = $strFileName;
1580 1628
 			$this->_msgContent['attachment'][$strFileName]['data']     = $strContent;
1581 1629
 
1582
-			if ( $this->getMD5flag() )
1583
-			$this->_msgContent['attachment'][$strFileName]['md5']      = dol_hash($strContent, 3);
1630
+			if ( $this->getMD5flag() ) {
1631
+						$this->_msgContent['attachment'][$strFileName]['md5']      = dol_hash($strContent, 3);
1632
+			}
1584 1633
 		}
1585 1634
 	}
1586 1635
 
@@ -1606,8 +1655,9 @@  discard block
 block discarded – undo
1606 1655
 			$this->_msgContent['image'][$strImageName]['cid']      = $strImageCid;
1607 1656
 			$this->_msgContent['image'][$strImageName]['data']     = $strContent;
1608 1657
 
1609
-			if ( $this->getMD5flag() )
1610
-			$this->_msgContent['image'][$strImageName]['md5']      = dol_hash($strContent, 3);
1658
+			if ( $this->getMD5flag() ) {
1659
+						$this->_msgContent['image'][$strImageName]['md5']      = dol_hash($strContent, 3);
1660
+			}
1611 1661
 		}
1612 1662
 	}
1613 1663
 	// END @CHANGE LDR
@@ -1627,8 +1677,9 @@  discard block
 block discarded – undo
1627 1677
 	function setSensitivity($_value = 0)
1628 1678
 	{
1629 1679
 		if ( ( is_numeric($_value) ) &&
1630
-		( ( $_value >= 0 ) && ( $_value <= 3 ) ) )
1631
-		$this->_msgSensitivity = $_value;
1680
+		( ( $_value >= 0 ) && ( $_value <= 3 ) ) ) {
1681
+				$this->_msgSensitivity = $_value;
1682
+		}
1632 1683
 	}
1633 1684
 
1634 1685
 	/**
@@ -1662,8 +1713,9 @@  discard block
 block discarded – undo
1662 1713
 	function setPriority( $_value = 3 )
1663 1714
 	{
1664 1715
 		if ( ( is_numeric($_value) ) &&
1665
-		( ( $_value >= 0 ) && ( $_value <= 5 ) ) )
1666
-		$this->_msgPriority = $_value;
1716
+		( ( $_value >= 0 ) && ( $_value <= 5 ) ) ) {
1717
+				$this->_msgPriority = $_value;
1718
+		}
1667 1719
 	}
1668 1720
 
1669 1721
 	/**
@@ -1716,8 +1768,9 @@  discard block
 block discarded – undo
1716 1768
 	 */
1717 1769
 	function setXheader($strXdata)
1718 1770
 	{
1719
-		if ( $strXdata )
1720
-		$this->_msgXheader[] = $strXdata;
1771
+		if ( $strXdata ) {
1772
+				$this->_msgXheader[] = $strXdata;
1773
+		}
1721 1774
 	}
1722 1775
 
1723 1776
 	/**
@@ -1750,9 +1803,13 @@  discard block
 block discarded – undo
1750 1803
 	 */
1751 1804
 	function _getBoundary($type='mixed')
1752 1805
 	{
1753
-		if ($type == 'mixed') return $this->_smtpsBoundary;
1754
-		else if ($type == 'related') return $this->_smtpsRelatedBoundary;
1755
-		else if ($type == 'alternative') return $this->_smtpsAlternativeBoundary;
1806
+		if ($type == 'mixed') {
1807
+		    return $this->_smtpsBoundary;
1808
+		} else if ($type == 'related') {
1809
+		    return $this->_smtpsRelatedBoundary;
1810
+		} else if ($type == 'alternative') {
1811
+		    return $this->_smtpsAlternativeBoundary;
1812
+		}
1756 1813
 	}
1757 1814
 
1758 1815
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -1810,12 +1867,18 @@  discard block
 block discarded – undo
1810 1867
 	function socket_send_str( $_strSend, $_returnCode = null, $CRLF = "\r\n" )
1811 1868
 	{
1812 1869
         // phpcs:enable
1813
-		if ($this->_debug) $this->log.=$_strSend;	// @CHANGE LDR for log
1870
+		if ($this->_debug) {
1871
+		    $this->log.=$_strSend;
1872
+		}
1873
+		// @CHANGE LDR for log
1814 1874
 		fputs($this->socket, $_strSend . $CRLF);
1815
-		if ($this->_debug) $this->log.=' ('.$_returnCode.')' . $CRLF;
1875
+		if ($this->_debug) {
1876
+		    $this->log.=' ('.$_returnCode.')' . $CRLF;
1877
+		}
1816 1878
 
1817
-		if ( $_returnCode )
1818
-		return $this->server_parse($this->socket, $_returnCode);
1879
+		if ( $_returnCode ) {
1880
+				return $this->server_parse($this->socket, $_returnCode);
1881
+		}
1819 1882
 	}
1820 1883
 
1821 1884
 	// =============================================================
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/commonobjectline.class.php 3 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -29,25 +29,25 @@  discard block
 block discarded – undo
29 29
  */
30 30
 abstract class CommonObjectLine extends CommonObject
31 31
 {
32
-	/**
33
-	 * Id of the line
34
-	 * @var int
35
-	 */
36
-	public $id;
32
+    /**
33
+     * Id of the line
34
+     * @var int
35
+     */
36
+    public $id;
37 37
 
38
-	/**
39
-	 * Id of the line
40
-	 * @var int
41
-	 * @deprecated Try to use id property as possible (even if field into database is still rowid)
42
-	 * @see id
43
-	 */
44
-	public $rowid;
38
+    /**
39
+     * Id of the line
40
+     * @var int
41
+     * @deprecated Try to use id property as possible (even if field into database is still rowid)
42
+     * @see id
43
+     */
44
+    public $rowid;
45 45
 
46
-	/**
47
-	 * Product/service unit code ('km', 'm', 'p', ...)
48
-	 * @var string
49
-	 */
50
-	public $fk_unit;
46
+    /**
47
+     * Product/service unit code ('km', 'm', 'p', ...)
48
+     * @var string
49
+     */
50
+    public $fk_unit;
51 51
 
52 52
 
53 53
     /**
@@ -57,40 +57,40 @@  discard block
 block discarded – undo
57 57
      * 	@param	string $type Label type (long or short)
58 58
      *	@return	string|int <0 if ko, label if ok
59 59
      */
60
-	public function getLabelOfUnit($type='long')
61
-	{
62
-		global $langs;
60
+    public function getLabelOfUnit($type='long')
61
+    {
62
+        global $langs;
63 63
 
64
-		if (!$this->fk_unit) {
65
-			return '';
66
-		}
64
+        if (!$this->fk_unit) {
65
+            return '';
66
+        }
67 67
 
68
-		$langs->load('products');
68
+        $langs->load('products');
69 69
 
70
-		$label_type = 'label';
70
+        $label_type = 'label';
71 71
 
72
-		if ($type == 'short')
73
-		{
74
-			$label_type = 'short_label';
75
-		}
72
+        if ($type == 'short')
73
+        {
74
+            $label_type = 'short_label';
75
+        }
76 76
 
77
-		$sql = 'select '.$label_type.' from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit;
78
-		$resql = $this->db->query($sql);
79
-		if($resql && $this->db->num_rows($resql) > 0)
80
-		{
81
-			$res = $this->db->fetch_array($resql);
82
-			$label = $res[$label_type];
83
-			$this->db->free($resql);
84
-			return $label;
85
-		}
86
-		else
87
-		{
88
-			$this->error=$this->db->error().' sql='.$sql;
89
-			dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
90
-			return -1;
91
-		}
92
-	}
93
-	// Currently we need function at end of file CommonObject for all object lines. Should find a way to avoid duplicate code.
77
+        $sql = 'select '.$label_type.' from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit;
78
+        $resql = $this->db->query($sql);
79
+        if($resql && $this->db->num_rows($resql) > 0)
80
+        {
81
+            $res = $this->db->fetch_array($resql);
82
+            $label = $res[$label_type];
83
+            $this->db->free($resql);
84
+            return $label;
85
+        }
86
+        else
87
+        {
88
+            $this->error=$this->db->error().' sql='.$sql;
89
+            dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
90
+            return -1;
91
+        }
92
+    }
93
+    // Currently we need function at end of file CommonObject for all object lines. Should find a way to avoid duplicate code.
94 94
 
95
-	// For the moment we use the extends on CommonObject until PHP min is 5.4 so use Traits.
95
+    // For the moment we use the extends on CommonObject until PHP min is 5.4 so use Traits.
96 96
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      * 	@param	string $type Label type (long or short)
58 58
      *	@return	string|int <0 if ko, label if ok
59 59
      */
60
-	public function getLabelOfUnit($type='long')
60
+	public function getLabelOfUnit($type = 'long')
61 61
 	{
62 62
 		global $langs;
63 63
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 
77 77
 		$sql = 'select '.$label_type.' from '.MAIN_DB_PREFIX.'c_units where rowid='.$this->fk_unit;
78 78
 		$resql = $this->db->query($sql);
79
-		if($resql && $this->db->num_rows($resql) > 0)
79
+		if ($resql && $this->db->num_rows($resql) > 0)
80 80
 		{
81 81
 			$res = $this->db->fetch_array($resql);
82 82
 			$label = $res[$label_type];
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		}
86 86
 		else
87 87
 		{
88
-			$this->error=$this->db->error().' sql='.$sql;
88
+			$this->error = $this->db->error().' sql='.$sql;
89 89
 			dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
90 90
 			return -1;
91 91
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -82,8 +82,7 @@
 block discarded – undo
82 82
 			$label = $res[$label_type];
83 83
 			$this->db->free($resql);
84 84
 			return $label;
85
-		}
86
-		else
85
+		} else
87 86
 		{
88 87
 			$this->error=$this->db->error().' sql='.$sql;
89 88
 			dol_syslog(get_class($this)."::getLabelOfUnit Error ".$this->error, LOG_ERR);
Please login to merge, or discard this patch.