Test Failed
Push — master ( 0ba343...0c40ee )
by Alxarafe
39:21
created
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/hookmanager.class.php 3 patches
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -29,100 +29,100 @@  discard block
 block discarded – undo
29 29
  */
30 30
 class HookManager
31 31
 {
32
-	/**
32
+    /**
33 33
      * @var DoliDB Database handler.
34 34
      */
35 35
     public $db;
36 36
 	
37
-	/**
38
-	 * @var string Error code (or message)
39
-	 */
40
-	public $error='';
37
+    /**
38
+     * @var string Error code (or message)
39
+     */
40
+    public $error='';
41 41
 
42
-	/**
43
-	 * @var string[] Error codes (or messages)
44
-	 */
45
-	public $errors = array();
42
+    /**
43
+     * @var string[] Error codes (or messages)
44
+     */
45
+    public $errors = array();
46 46
 
47 47
     // Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
48 48
     var $contextarray=array();
49 49
 
50
-	// Array with instantiated classes
51
-	var $hooks=array();
52
-
53
-	// Array result
54
-	var $resArray=array();
55
-	// Printable result
56
-	var $resPrint='';
57
-	// Nb of qualified hook ran
58
-	var $resNbOfHooks=0;
59
-
60
-	/**
61
-	 * Constructor
62
-	 *
63
-	 * @param	DoliDB		$db		Database handler
64
-	 */
65
-	function __construct($db)
66
-	{
67
-		$this->db = $db;
68
-	}
69
-
70
-
71
-	/**
72
-	 *	Init array $this->hooks with instantiated action controlers.
73
-	 *  First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file.
74
-	 *  This makes $conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...))
75
-	 *  When initHooks function is called, with initHooks(list_of_contexts), an array $this->hooks is defined with instance of controler
76
-	 *  class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
77
-	 *  Then when a hook executeHooks('aMethod'...) is called, the method aMethod found into class will be executed.
78
-	 *
79
-	 *	@param	string[]	$arraycontext	    Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
80
-	 *	@return	int							    Always 1
81
-	 */
82
-	function initHooks($arraycontext)
83
-	{
84
-		global $conf;
85
-
86
-		// Test if there is hooks to manage
50
+    // Array with instantiated classes
51
+    var $hooks=array();
52
+
53
+    // Array result
54
+    var $resArray=array();
55
+    // Printable result
56
+    var $resPrint='';
57
+    // Nb of qualified hook ran
58
+    var $resNbOfHooks=0;
59
+
60
+    /**
61
+     * Constructor
62
+     *
63
+     * @param	DoliDB		$db		Database handler
64
+     */
65
+    function __construct($db)
66
+    {
67
+        $this->db = $db;
68
+    }
69
+
70
+
71
+    /**
72
+     *	Init array $this->hooks with instantiated action controlers.
73
+     *  First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file.
74
+     *  This makes $conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...))
75
+     *  When initHooks function is called, with initHooks(list_of_contexts), an array $this->hooks is defined with instance of controler
76
+     *  class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context).
77
+     *  Then when a hook executeHooks('aMethod'...) is called, the method aMethod found into class will be executed.
78
+     *
79
+     *	@param	string[]	$arraycontext	    Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ...
80
+     *	@return	int							    Always 1
81
+     */
82
+    function initHooks($arraycontext)
83
+    {
84
+        global $conf;
85
+
86
+        // Test if there is hooks to manage
87 87
         if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
88 88
 
89 89
         // For backward compatibility
90
-		if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
91
-
92
-		$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
93
-
94
-		foreach($conf->modules_parts['hooks'] as $module => $hooks)	// Loop on each module that brings hooks
95
-		{
96
-			if (empty($conf->$module->enabled)) continue;
97
-
98
-			//dol_syslog(get_class($this).'::initHooks module='.$module.' arraycontext='.join(',',$arraycontext));
99
-			foreach($arraycontext as $context)
100
-			{
101
-				if (is_array($hooks)) $arrayhooks=$hooks;    // New system
102
-				else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
103
-
104
-				if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks))    // We instantiate action class only if initialized hook is handled by module
105
-				{
106
-					// Include actions class overwriting hooks
107
-					if (! is_object($this->hooks[$context][$module]))	// If set, class was already loaded
108
-					{
109
-						$path 		= '/'.$module.'/class/';
110
-						$actionfile = 'actions_'.$module.'.class.php';
111
-
112
-						dol_syslog(get_class($this).'::initHooks Loading hook class for context '.$context.": ".$actionfile, LOG_INFO);
113
-						$resaction=dol_include_once($path.$actionfile);
114
-						if ($resaction)
115
-						{
116
-							$controlclassname = 'Actions'.ucfirst($module);
117
-							$actionInstance = new $controlclassname($this->db);
118
-							$this->hooks[$context][$module] = $actionInstance;
119
-						}
120
-					}
121
-				}
122
-			}
123
-		}
124
-		return 1;
125
-	}
90
+        if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
91
+
92
+        $this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
93
+
94
+        foreach($conf->modules_parts['hooks'] as $module => $hooks)	// Loop on each module that brings hooks
95
+        {
96
+            if (empty($conf->$module->enabled)) continue;
97
+
98
+            //dol_syslog(get_class($this).'::initHooks module='.$module.' arraycontext='.join(',',$arraycontext));
99
+            foreach($arraycontext as $context)
100
+            {
101
+                if (is_array($hooks)) $arrayhooks=$hooks;    // New system
102
+                else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
103
+
104
+                if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks))    // We instantiate action class only if initialized hook is handled by module
105
+                {
106
+                    // Include actions class overwriting hooks
107
+                    if (! is_object($this->hooks[$context][$module]))	// If set, class was already loaded
108
+                    {
109
+                        $path 		= '/'.$module.'/class/';
110
+                        $actionfile = 'actions_'.$module.'.class.php';
111
+
112
+                        dol_syslog(get_class($this).'::initHooks Loading hook class for context '.$context.": ".$actionfile, LOG_INFO);
113
+                        $resaction=dol_include_once($path.$actionfile);
114
+                        if ($resaction)
115
+                        {
116
+                            $controlclassname = 'Actions'.ucfirst($module);
117
+                            $actionInstance = new $controlclassname($this->db);
118
+                            $this->hooks[$context][$module] = $actionInstance;
119
+                        }
120
+                    }
121
+                }
122
+            }
123
+        }
124
+        return 1;
125
+    }
126 126
 
127 127
     /**
128 128
      * 		Execute hooks (if they were initialized) for the given method
@@ -136,8 +136,8 @@  discard block
 block discarded – undo
136 136
      *                                          All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
137 137
      * 											$this->error or this->errors are also defined by class called by this function if error.
138 138
      */
139
-	function executeHooks($method, $parameters=array(), &$object='', &$action='')
140
-	{
139
+    function executeHooks($method, $parameters=array(), &$object='', &$action='')
140
+    {
141 141
         if (! is_array($this->hooks) || empty($this->hooks)) return '';
142 142
 
143 143
         $parameters['context']=join(':',$this->contextarray);
@@ -145,67 +145,67 @@  discard block
 block discarded – undo
145 145
 
146 146
         // Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated because a 'addreplace' hook can also return resPrint and resArray).
147 147
         $hooktype='output';
148
-		if (in_array(
149
-			$method,
150
-			array(
151
-				'addCalendarChoice',
152
-				'addMoreActionsButtons',
153
-				'addMoreMassActions',
154
-				'addSearchEntry',
155
-				'addStatisticLine',
156
-				'createDictionaryFieldlist',
157
-				'editDictionaryFieldlist',
158
-				'getFormMail',
159
-				'deleteFile',
160
-				'doActions',
161
-				'doMassActions',
162
-				'formatEvent',
163
-				'formCreateThirdpartyOptions',
164
-				'formObjectOptions',
165
-				'formattachOptions',
166
-				'formBuilddocLineOptions',
167
-				'formatNotificationMessage',
168
-				'getFormMail',
169
-				'getIdProfUrl',
170
-				'getDirList',
171
-				'moveUploadedFile',
172
-				'moreHtmlStatus',
173
-				'pdf_build_address',
174
-				'pdf_writelinedesc',
175
-			    'pdf_getlinenum',
176
-			    'pdf_getlineref',
177
-			    'pdf_getlineref_supplier',
178
-			    'pdf_getlinevatrate',
179
-			    'pdf_getlineupexcltax',
180
-			    'pdf_getlineupwithtax',
181
-			    'pdf_getlineqty',
182
-			    'pdf_getlineqty_asked',
183
-			    'pdf_getlineqty_shipped',
184
-			    'pdf_getlineqty_keeptoship',
185
-			    'pdf_getlineunit',
186
-			    'pdf_getlineremisepercent',
187
-			    'pdf_getlineprogress',
188
-			    'pdf_getlinetotalexcltax',
189
-			    'pdf_getlinetotalwithtax',
190
-				'paymentsupplierinvoices',
191
-				'printAddress',
192
-				'printSearchForm',
193
-				'printTabsHead',
194
-				'printObjectLine',
195
-				'printObjectSubLine',
196
-				'restrictedArea',
197
-				'sendMail',
198
-				'sendMailAfter',
199
-				'showLinkToObjectBlock',
200
-				'setContentSecurityPolicy',
201
-				'setHtmlTitle'
202
-				)
203
-			)) $hooktype='addreplace';
148
+        if (in_array(
149
+            $method,
150
+            array(
151
+                'addCalendarChoice',
152
+                'addMoreActionsButtons',
153
+                'addMoreMassActions',
154
+                'addSearchEntry',
155
+                'addStatisticLine',
156
+                'createDictionaryFieldlist',
157
+                'editDictionaryFieldlist',
158
+                'getFormMail',
159
+                'deleteFile',
160
+                'doActions',
161
+                'doMassActions',
162
+                'formatEvent',
163
+                'formCreateThirdpartyOptions',
164
+                'formObjectOptions',
165
+                'formattachOptions',
166
+                'formBuilddocLineOptions',
167
+                'formatNotificationMessage',
168
+                'getFormMail',
169
+                'getIdProfUrl',
170
+                'getDirList',
171
+                'moveUploadedFile',
172
+                'moreHtmlStatus',
173
+                'pdf_build_address',
174
+                'pdf_writelinedesc',
175
+                'pdf_getlinenum',
176
+                'pdf_getlineref',
177
+                'pdf_getlineref_supplier',
178
+                'pdf_getlinevatrate',
179
+                'pdf_getlineupexcltax',
180
+                'pdf_getlineupwithtax',
181
+                'pdf_getlineqty',
182
+                'pdf_getlineqty_asked',
183
+                'pdf_getlineqty_shipped',
184
+                'pdf_getlineqty_keeptoship',
185
+                'pdf_getlineunit',
186
+                'pdf_getlineremisepercent',
187
+                'pdf_getlineprogress',
188
+                'pdf_getlinetotalexcltax',
189
+                'pdf_getlinetotalwithtax',
190
+                'paymentsupplierinvoices',
191
+                'printAddress',
192
+                'printSearchForm',
193
+                'printTabsHead',
194
+                'printObjectLine',
195
+                'printObjectSubLine',
196
+                'restrictedArea',
197
+                'sendMail',
198
+                'sendMailAfter',
199
+                'showLinkToObjectBlock',
200
+                'setContentSecurityPolicy',
201
+                'setHtmlTitle'
202
+                )
203
+            )) $hooktype='addreplace';
204 204
 
205 205
         if ($method == 'insertExtraFields')
206 206
         {
207
-        	$hooktype='returnvalue';	// @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
208
-        	dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
207
+            $hooktype='returnvalue';	// @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
208
+            dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
209 209
         }
210 210
 
211 211
         // Init return properties
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
             {
221 221
                 foreach($modules as $module => $actionclassinstance)
222 222
                 {
223
-                	//print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
223
+                    //print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
224 224
 
225 225
                     // test to avoid running twice a hook, when a module implements several active contexts
226 226
                     if (in_array($module,$modulealreadyexecuted)) continue;
227 227
 
228
-                	// jump to next module/class if method does not exist
228
+                    // jump to next module/class if method does not exist
229 229
                     if (! method_exists($actionclassinstance,$method)) continue;
230 230
 
231 231
                     $this->resNbOfHooks++;
@@ -243,34 +243,34 @@  discard block
 block discarded – undo
243 243
                     // Hooks that must return int (hooks with type 'addreplace')
244 244
                     if ($hooktype == 'addreplace')
245 245
                     {
246
-                    	$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
247
-                    	if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
248
-                    	{
249
-                    		$error++;
250
-                    		$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
251
-                    		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
252
-                    	}
253
-
254
-                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
255
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
246
+                        $resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
247
+                        if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
248
+                        {
249
+                            $error++;
250
+                            $this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
251
+                            dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
252
+                        }
253
+
254
+                        if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
255
+                        if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
256 256
                     }
257 257
                     // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
258 258
                     else
259
-					{
260
-                    	// TODO. this test should be done into the method of hook by returning nothing
261
-                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
262
-
263
-                    	//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
264
-                    	$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
265
-
266
-                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
267
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
268
-                    	// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
269
-                    	if (! is_array($resaction) && ! is_numeric($resaction))
270
-                    	{
271
-                    		dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);
272
-                    		if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; }
273
-                    	}
259
+                    {
260
+                        // TODO. this test should be done into the method of hook by returning nothing
261
+                        if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
262
+
263
+                        //dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
264
+                        $resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
265
+
266
+                        if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
267
+                        if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
268
+                        // TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
269
+                        if (! is_array($resaction) && ! is_numeric($resaction))
270
+                        {
271
+                            dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);
272
+                            if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; }
273
+                        }
274 274
                     }
275 275
 
276 276
                     //print "After hook  ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
@@ -282,5 +282,5 @@  discard block
 block discarded – undo
282 282
         }
283 283
 
284 284
         return ($error?-1:$resaction);
285
-	}
285
+    }
286 286
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 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
 	 * @var string[] Error codes (or messages)
@@ -45,17 +45,17 @@  discard block
 block discarded – undo
45 45
 	public $errors = array();
46 46
 
47 47
     // Context hookmanager was created for ('thirdpartycard', 'thirdpartydao', ...)
48
-    var $contextarray=array();
48
+    var $contextarray = array();
49 49
 
50 50
 	// Array with instantiated classes
51
-	var $hooks=array();
51
+	var $hooks = array();
52 52
 
53 53
 	// Array result
54
-	var $resArray=array();
54
+	var $resArray = array();
55 55
 	// Printable result
56
-	var $resPrint='';
56
+	var $resPrint = '';
57 57
 	// Nb of qualified hook ran
58
-	var $resNbOfHooks=0;
58
+	var $resNbOfHooks = 0;
59 59
 
60 60
 	/**
61 61
 	 * Constructor
@@ -84,33 +84,33 @@  discard block
 block discarded – undo
84 84
 		global $conf;
85 85
 
86 86
 		// Test if there is hooks to manage
87
-        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
87
+        if (!is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
88 88
 
89 89
         // For backward compatibility
90
-		if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
90
+		if (!is_array($arraycontext)) $arraycontext = array($arraycontext);
91 91
 
92
-		$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
92
+		$this->contextarray = array_unique(array_merge($arraycontext, $this->contextarray)); // All contexts are concatenated
93 93
 
94
-		foreach($conf->modules_parts['hooks'] as $module => $hooks)	// Loop on each module that brings hooks
94
+		foreach ($conf->modules_parts['hooks'] as $module => $hooks)	// Loop on each module that brings hooks
95 95
 		{
96 96
 			if (empty($conf->$module->enabled)) continue;
97 97
 
98 98
 			//dol_syslog(get_class($this).'::initHooks module='.$module.' arraycontext='.join(',',$arraycontext));
99
-			foreach($arraycontext as $context)
99
+			foreach ($arraycontext as $context)
100 100
 			{
101
-				if (is_array($hooks)) $arrayhooks=$hooks;    // New system
102
-				else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
101
+				if (is_array($hooks)) $arrayhooks = $hooks; // New system
102
+				else $arrayhooks = explode(':', $hooks); // Old system (for backward compatibility)
103 103
 
104 104
 				if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks))    // We instantiate action class only if initialized hook is handled by module
105 105
 				{
106 106
 					// Include actions class overwriting hooks
107
-					if (! is_object($this->hooks[$context][$module]))	// If set, class was already loaded
107
+					if (!is_object($this->hooks[$context][$module]))	// If set, class was already loaded
108 108
 					{
109
-						$path 		= '/'.$module.'/class/';
109
+						$path = '/'.$module.'/class/';
110 110
 						$actionfile = 'actions_'.$module.'.class.php';
111 111
 
112 112
 						dol_syslog(get_class($this).'::initHooks Loading hook class for context '.$context.": ".$actionfile, LOG_INFO);
113
-						$resaction=dol_include_once($path.$actionfile);
113
+						$resaction = dol_include_once($path.$actionfile);
114 114
 						if ($resaction)
115 115
 						{
116 116
 							$controlclassname = 'Actions'.ucfirst($module);
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
      *                                          All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller.
137 137
      * 											$this->error or this->errors are also defined by class called by this function if error.
138 138
      */
139
-	function executeHooks($method, $parameters=array(), &$object='', &$action='')
139
+	function executeHooks($method, $parameters = array(), &$object = '', &$action = '')
140 140
 	{
141
-        if (! is_array($this->hooks) || empty($this->hooks)) return '';
141
+        if (!is_array($this->hooks) || empty($this->hooks)) return '';
142 142
 
143
-        $parameters['context']=join(':',$this->contextarray);
143
+        $parameters['context'] = join(':', $this->contextarray);
144 144
         //dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
145 145
 
146 146
         // Define type of hook ('output' or 'addreplace'. 'returnvalue' is deprecated because a 'addreplace' hook can also return resPrint and resArray).
147
-        $hooktype='output';
147
+        $hooktype = 'output';
148 148
 		if (in_array(
149 149
 			$method,
150 150
 			array(
@@ -200,41 +200,41 @@  discard block
 block discarded – undo
200 200
 				'setContentSecurityPolicy',
201 201
 				'setHtmlTitle'
202 202
 				)
203
-			)) $hooktype='addreplace';
203
+			)) $hooktype = 'addreplace';
204 204
 
205 205
         if ($method == 'insertExtraFields')
206 206
         {
207
-        	$hooktype='returnvalue';	// @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
207
+        	$hooktype = 'returnvalue'; // @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available.
208 208
         	dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING);
209 209
         }
210 210
 
211 211
         // Init return properties
212
-        $this->resPrint=''; $this->resArray=array(); $this->resNbOfHooks=0;
212
+        $this->resPrint = ''; $this->resArray = array(); $this->resNbOfHooks = 0;
213 213
 
214 214
         // Loop on each hook to qualify modules that have declared context
215
-        $modulealreadyexecuted=array();
216
-        $resaction=0; $error=0; $result='';
217
-        foreach($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
215
+        $modulealreadyexecuted = array();
216
+        $resaction = 0; $error = 0; $result = '';
217
+        foreach ($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
218 218
         {
219
-            if (! empty($modules))
219
+            if (!empty($modules))
220 220
             {
221
-                foreach($modules as $module => $actionclassinstance)
221
+                foreach ($modules as $module => $actionclassinstance)
222 222
                 {
223 223
                 	//print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."<br>\n";
224 224
 
225 225
                     // test to avoid running twice a hook, when a module implements several active contexts
226
-                    if (in_array($module,$modulealreadyexecuted)) continue;
226
+                    if (in_array($module, $modulealreadyexecuted)) continue;
227 227
 
228 228
                 	// jump to next module/class if method does not exist
229
-                    if (! method_exists($actionclassinstance,$method)) continue;
229
+                    if (!method_exists($actionclassinstance, $method)) continue;
230 230
 
231 231
                     $this->resNbOfHooks++;
232 232
 
233
-                    $modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice
233
+                    $modulealreadyexecuted[$module] = $module; // Use the $currentcontext in method to avoid running twice
234 234
 
235 235
                     // Clean class (an error may have been set from a previous call of another method for same module/hook)
236
-                    $actionclassinstance->error=0;
237
-                    $actionclassinstance->errors=array();
236
+                    $actionclassinstance->error = 0;
237
+                    $actionclassinstance->errors = array();
238 238
 
239 239
                     dol_syslog(get_class($this)."::executeHooks Qualified hook found (hooktype=".$hooktype."). We call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", action=".$action." context=".$context, LOG_DEBUG);
240 240
 
@@ -244,32 +244,32 @@  discard block
 block discarded – undo
244 244
                     if ($hooktype == 'addreplace')
245 245
                     {
246 246
                     	$resaction += $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
247
-                    	if ($resaction < 0 || ! empty($actionclassinstance->error) || (! empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
247
+                    	if ($resaction < 0 || !empty($actionclassinstance->error) || (!empty($actionclassinstance->errors) && count($actionclassinstance->errors) > 0))
248 248
                     	{
249 249
                     		$error++;
250
-                    		$this->error=$actionclassinstance->error; $this->errors=array_merge($this->errors, (array) $actionclassinstance->errors);
251
-                    		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
250
+                    		$this->error = $actionclassinstance->error; $this->errors = array_merge($this->errors, (array) $actionclassinstance->errors);
251
+                    		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error) ? '' : " ".$this->error).(empty($this->errors) ? '' : " ".join(",", $this->errors)), LOG_ERR);
252 252
                     	}
253 253
 
254
-                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
255
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
254
+                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray = array_merge($this->resArray, $actionclassinstance->results);
255
+                    	if (!empty($actionclassinstance->resprints)) $this->resPrint .= $actionclassinstance->resprints;
256 256
                     }
257 257
                     // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
258 258
                     else
259 259
 					{
260 260
                     	// TODO. this test should be done into the method of hook by returning nothing
261
-                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
261
+                    	if (is_array($parameters) && !empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
262 262
 
263 263
                     	//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
264 264
                     	$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
265 265
 
266
-                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
267
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
266
+                    	if (!empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray = array_merge($this->resArray, $actionclassinstance->results);
267
+                    	if (!empty($actionclassinstance->resprints)) $this->resPrint .= $actionclassinstance->resprints;
268 268
                     	// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
269
-                    	if (! is_array($resaction) && ! is_numeric($resaction))
269
+                    	if (!is_array($resaction) && !is_numeric($resaction))
270 270
                     	{
271 271
                     		dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR);
272
-                    		if (empty($actionclassinstance->resprints)) { $this->resPrint.=$resaction; $resaction=0; }
272
+                    		if (empty($actionclassinstance->resprints)) { $this->resPrint .= $resaction; $resaction = 0; }
273 273
                     	}
274 274
                     }
275 275
 
@@ -281,6 +281,6 @@  discard block
 block discarded – undo
281 281
             }
282 282
         }
283 283
 
284
-        return ($error?-1:$resaction);
284
+        return ($error ?-1 : $resaction);
285 285
 	}
286 286
 }
Please login to merge, or discard this patch.
Braces   +47 added lines, -15 removed lines patch added patch discarded remove patch
@@ -84,29 +84,43 @@  discard block
 block discarded – undo
84 84
 		global $conf;
85 85
 
86 86
 		// Test if there is hooks to manage
87
-        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) return;
87
+        if (! is_array($conf->modules_parts['hooks']) || empty($conf->modules_parts['hooks'])) {
88
+            return;
89
+        }
88 90
 
89 91
         // For backward compatibility
90
-		if (! is_array($arraycontext)) $arraycontext=array($arraycontext);
92
+		if (! is_array($arraycontext)) {
93
+		    $arraycontext=array($arraycontext);
94
+		}
91 95
 
92 96
 		$this->contextarray=array_unique(array_merge($arraycontext,$this->contextarray));    // All contexts are concatenated
93 97
 
94
-		foreach($conf->modules_parts['hooks'] as $module => $hooks)	// Loop on each module that brings hooks
98
+		foreach($conf->modules_parts['hooks'] as $module => $hooks) {
99
+		    // Loop on each module that brings hooks
95 100
 		{
96 101
 			if (empty($conf->$module->enabled)) continue;
102
+		}
97 103
 
98 104
 			//dol_syslog(get_class($this).'::initHooks module='.$module.' arraycontext='.join(',',$arraycontext));
99 105
 			foreach($arraycontext as $context)
100 106
 			{
101
-				if (is_array($hooks)) $arrayhooks=$hooks;    // New system
102
-				else $arrayhooks=explode(':',$hooks);        // Old system (for backward compatibility)
107
+				if (is_array($hooks)) {
108
+				    $arrayhooks=$hooks;
109
+				}
110
+				// New system
111
+				else {
112
+				    $arrayhooks=explode(':',$hooks);
113
+				}
114
+				// Old system (for backward compatibility)
103 115
 
104
-				if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks))    // We instantiate action class only if initialized hook is handled by module
116
+				if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks)) {
117
+				    // We instantiate action class only if initialized hook is handled by module
105 118
 				{
106 119
 					// Include actions class overwriting hooks
107 120
 					if (! is_object($this->hooks[$context][$module]))	// If set, class was already loaded
108 121
 					{
109 122
 						$path 		= '/'.$module.'/class/';
123
+				}
110 124
 						$actionfile = 'actions_'.$module.'.class.php';
111 125
 
112 126
 						dol_syslog(get_class($this).'::initHooks Loading hook class for context '.$context.": ".$actionfile, LOG_INFO);
@@ -138,7 +152,9 @@  discard block
 block discarded – undo
138 152
      */
139 153
 	function executeHooks($method, $parameters=array(), &$object='', &$action='')
140 154
 	{
141
-        if (! is_array($this->hooks) || empty($this->hooks)) return '';
155
+        if (! is_array($this->hooks) || empty($this->hooks)) {
156
+            return '';
157
+        }
142 158
 
143 159
         $parameters['context']=join(':',$this->contextarray);
144 160
         //dol_syslog(get_class($this).'::executeHooks method='.$method." action=".$action." context=".$parameters['context']);
@@ -200,7 +216,9 @@  discard block
 block discarded – undo
200 216
 				'setContentSecurityPolicy',
201 217
 				'setHtmlTitle'
202 218
 				)
203
-			)) $hooktype='addreplace';
219
+			)) {
220
+		    $hooktype='addreplace';
221
+		}
204 222
 
205 223
         if ($method == 'insertExtraFields')
206 224
         {
@@ -214,7 +232,8 @@  discard block
 block discarded – undo
214 232
         // Loop on each hook to qualify modules that have declared context
215 233
         $modulealreadyexecuted=array();
216 234
         $resaction=0; $error=0; $result='';
217
-        foreach($this->hooks as $context => $modules)    // $this->hooks is an array with context as key and value is an array of modules that handle this context
235
+        foreach($this->hooks as $context => $modules) {
236
+            // $this->hooks is an array with context as key and value is an array of modules that handle this context
218 237
         {
219 238
             if (! empty($modules))
220 239
             {
@@ -224,9 +243,12 @@  discard block
 block discarded – undo
224 243
 
225 244
                     // test to avoid running twice a hook, when a module implements several active contexts
226 245
                     if (in_array($module,$modulealreadyexecuted)) continue;
246
+        }
227 247
 
228 248
                 	// jump to next module/class if method does not exist
229
-                    if (! method_exists($actionclassinstance,$method)) continue;
249
+                    if (! method_exists($actionclassinstance,$method)) {
250
+                        continue;
251
+                    }
230 252
 
231 253
                     $this->resNbOfHooks++;
232 254
 
@@ -251,20 +273,30 @@  discard block
 block discarded – undo
251 273
                     		dol_syslog("Error on hook module=".$module.", method ".$method.", class ".get_class($actionclassinstance).", hooktype=".$hooktype.(empty($this->error)?'':" ".$this->error).(empty($this->errors)?'':" ".join(",",$this->errors)), LOG_ERR);
252 274
                     	}
253 275
 
254
-                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results))  $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
255
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
276
+                    	if (isset($actionclassinstance->results) && is_array($actionclassinstance->results)) {
277
+                    	    $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
278
+                    	}
279
+                    	if (! empty($actionclassinstance->resprints)) {
280
+                    	    $this->resPrint.=$actionclassinstance->resprints;
281
+                    	}
256 282
                     }
257 283
                     // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...)
258 284
                     else
259 285
 					{
260 286
                     	// TODO. this test should be done into the method of hook by returning nothing
261
-                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue;
287
+                    	if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) {
288
+                    	    continue;
289
+                    	}
262 290
 
263 291
                     	//dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG);
264 292
                     	$resaction = $actionclassinstance->$method($parameters, $object, $action, $this); // $object and $action can be changed by method ($object->id during creation for example or $action to go back to other action for example)
265 293
 
266
-                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
267
-                    	if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints;
294
+                    	if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) {
295
+                    	    $this->resArray =array_merge($this->resArray, $actionclassinstance->results);
296
+                    	}
297
+                    	if (! empty($actionclassinstance->resprints)) {
298
+                    	    $this->resPrint.=$actionclassinstance->resprints;
299
+                    	}
268 300
                     	// TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string
269 301
                     	if (! is_array($resaction) && ! is_numeric($resaction))
270 302
                     	{
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/menubase.class.php 3 patches
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
     public $errors = array();
46 46
 
47 47
     /**
48
-	 * @var int ID
49
-	 */
50
-	public $id;
48
+     * @var int ID
49
+     */
50
+    public $id;
51 51
 
52 52
     public $menu_handler;
53 53
     public $module;
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 
87 87
 
88 88
     /**
89
-	 *	Constructor
90
-	 *
91
-	 *  @param		DoliDB		$db 		    Database handler
89
+     *	Constructor
90
+     *
91
+     *  @param		DoliDB		$db 		    Database handler
92 92
      *  @param     	string		$menu_handler	Menu handler
93 93
      */
94 94
     function __construct($db,$menu_handler='')
@@ -137,22 +137,22 @@  discard block
 block discarded – undo
137 137
         // an insert with a forced id.
138 138
         if (in_array($this->db->type,array('pgsql')))
139 139
         {
140
-          $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu";
141
-          $resqlrowid=$this->db->query($sql);
142
-          if ($resqlrowid)
143
-          {
144
-               $obj=$this->db->fetch_object($resqlrowid);
145
-               $maxrowid=$obj->maxrowid;
146
-
147
-               // Max rowid can be empty if there is no record yet
148
-               if(empty($maxrowid)) $maxrowid=1;
149
-
150
-               $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")";
151
-               //print $sql; exit;
152
-               $resqlrowidset=$this->db->query($sql);
153
-               if (! $resqlrowidset) dol_print_error($this->db);
154
-          }
155
-          else dol_print_error($this->db);
140
+            $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu";
141
+            $resqlrowid=$this->db->query($sql);
142
+            if ($resqlrowid)
143
+            {
144
+                $obj=$this->db->fetch_object($resqlrowid);
145
+                $maxrowid=$obj->maxrowid;
146
+
147
+                // Max rowid can be empty if there is no record yet
148
+                if(empty($maxrowid)) $maxrowid=1;
149
+
150
+                $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")";
151
+                //print $sql; exit;
152
+                $resqlrowidset=$this->db->query($sql);
153
+                if (! $resqlrowidset) dol_print_error($this->db);
154
+            }
155
+            else dol_print_error($this->db);
156 156
         }
157 157
 
158 158
         // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
@@ -167,74 +167,74 @@  discard block
 block discarded – undo
167 167
         $result=$this->db->query($sql);
168 168
         if ($result)
169 169
         {
170
-        	$row = $this->db->fetch_row($result);
171
-
172
-        	if ($row[0] == 0)   // If not found
173
-        	{
174
-		        // Insert request
175
-		        $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu(";
176
-		        $sql.= "menu_handler,";
177
-		        $sql.= "entity,";
178
-		        $sql.= "module,";
179
-		        $sql.= "type,";
180
-		        $sql.= "mainmenu,";
181
-		        $sql.= "leftmenu,";
182
-		        $sql.= "fk_menu,";
183
-		        $sql.= "fk_mainmenu,";
184
-		        $sql.= "fk_leftmenu,";
185
-		        $sql.= "position,";
186
-		        $sql.= "url,";
187
-		        $sql.= "target,";
188
-		        $sql.= "titre,";
189
-		        $sql.= "langs,";
190
-		        $sql.= "perms,";
191
-		        $sql.= "enabled,";
192
-		        $sql.= "usertype";
193
-		        $sql.= ") VALUES (";
194
-		        $sql.= " '".$this->db->escape($this->menu_handler)."',";
195
-		        $sql.= " '".$this->db->escape($conf->entity)."',";
196
-		        $sql.= " '".$this->db->escape($this->module)."',";
197
-		        $sql.= " '".$this->db->escape($this->type)."',";
198
-		        $sql.= " ".($this->mainmenu?"'".$this->db->escape($this->mainmenu)."'":"''").",";    // Can't be null
199
-		        $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").",";
200
-		        $sql.= " ".((int) $this->fk_menu).",";
201
-		        $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").",";
202
-		        $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").",";
203
-		        $sql.= " ".((int) $this->position).",";
204
-		        $sql.= " '".$this->db->escape($this->url)."',";
205
-		        $sql.= " '".$this->db->escape($this->target)."',";
206
-		        $sql.= " '".$this->db->escape($this->titre)."',";
207
-		        $sql.= " '".$this->db->escape($this->langs)."',";
208
-		        $sql.= " '".$this->db->escape($this->perms)."',";
209
-		        $sql.= " '".$this->db->escape($this->enabled)."',";
210
-		        $sql.= " '".$this->db->escape($this->user)."'";
211
-		        $sql.= ")";
212
-
213
-		        dol_syslog(get_class($this)."::create", LOG_DEBUG);
214
-		        $resql=$this->db->query($sql);
215
-		        if ($resql)
216
-		        {
217
-		            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu");
218
-		            dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG);
219
-
220
-		            return $this->id;
221
-		        }
222
-		        else
223
-		        {
224
-		            $this->error="Error ".$this->db->lasterror();
225
-		            return -1;
226
-		        }
227
-        	}
228
-        	else
229
-        	{
230
-        		dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
231
-        		$this->error = 'Error Menu entry already exists';
232
-        		return 0;
233
-        	}
170
+            $row = $this->db->fetch_row($result);
171
+
172
+            if ($row[0] == 0)   // If not found
173
+            {
174
+                // Insert request
175
+                $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu(";
176
+                $sql.= "menu_handler,";
177
+                $sql.= "entity,";
178
+                $sql.= "module,";
179
+                $sql.= "type,";
180
+                $sql.= "mainmenu,";
181
+                $sql.= "leftmenu,";
182
+                $sql.= "fk_menu,";
183
+                $sql.= "fk_mainmenu,";
184
+                $sql.= "fk_leftmenu,";
185
+                $sql.= "position,";
186
+                $sql.= "url,";
187
+                $sql.= "target,";
188
+                $sql.= "titre,";
189
+                $sql.= "langs,";
190
+                $sql.= "perms,";
191
+                $sql.= "enabled,";
192
+                $sql.= "usertype";
193
+                $sql.= ") VALUES (";
194
+                $sql.= " '".$this->db->escape($this->menu_handler)."',";
195
+                $sql.= " '".$this->db->escape($conf->entity)."',";
196
+                $sql.= " '".$this->db->escape($this->module)."',";
197
+                $sql.= " '".$this->db->escape($this->type)."',";
198
+                $sql.= " ".($this->mainmenu?"'".$this->db->escape($this->mainmenu)."'":"''").",";    // Can't be null
199
+                $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").",";
200
+                $sql.= " ".((int) $this->fk_menu).",";
201
+                $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").",";
202
+                $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").",";
203
+                $sql.= " ".((int) $this->position).",";
204
+                $sql.= " '".$this->db->escape($this->url)."',";
205
+                $sql.= " '".$this->db->escape($this->target)."',";
206
+                $sql.= " '".$this->db->escape($this->titre)."',";
207
+                $sql.= " '".$this->db->escape($this->langs)."',";
208
+                $sql.= " '".$this->db->escape($this->perms)."',";
209
+                $sql.= " '".$this->db->escape($this->enabled)."',";
210
+                $sql.= " '".$this->db->escape($this->user)."'";
211
+                $sql.= ")";
212
+
213
+                dol_syslog(get_class($this)."::create", LOG_DEBUG);
214
+                $resql=$this->db->query($sql);
215
+                if ($resql)
216
+                {
217
+                    $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu");
218
+                    dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG);
219
+
220
+                    return $this->id;
221
+                }
222
+                else
223
+                {
224
+                    $this->error="Error ".$this->db->lasterror();
225
+                    return -1;
226
+                }
227
+            }
228
+            else
229
+            {
230
+                dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
231
+                $this->error = 'Error Menu entry already exists';
232
+                return 0;
233
+            }
234 234
         }
235 235
         else
236 236
         {
237
-        	return -1;
237
+            return -1;
238 238
         }
239 239
     }
240 240
 
@@ -480,16 +480,16 @@  discard block
 block discarded – undo
480 480
         $mainmenu=$mymainmenu;  // To export to dol_eval function
481 481
         $leftmenu=$myleftmenu;  // To export to dol_eval function
482 482
 
483
-		// Detect what is top mainmenu id
483
+        // Detect what is top mainmenu id
484 484
         $menutopid='';
485 485
         foreach($tabMenu as $key => $val)
486 486
         {
487
-        	// Define menutopid of mainmenu
488
-        	if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu)
489
-        	{
490
-        		$menutopid=$val['rowid'];
491
-        		break;
492
-        	}
487
+            // Define menutopid of mainmenu
488
+            if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu)
489
+            {
490
+                $menutopid=$val['rowid'];
491
+                break;
492
+            }
493 493
         }
494 494
 
495 495
         // We initialize newmenu with first already found menu entries
@@ -501,50 +501,50 @@  discard block
 block discarded – undo
501 501
         // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
502 502
         foreach($tabMenu as $key => $val)
503 503
         {
504
-        	//var_dump($tabMenu);
505
-        	if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu)    // We found a menu entry not linked to parent with good mainmenu
506
-        	{
507
-        		//print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>';
508
-        		//var_dump($this->newmenu->liste);exit;
509
-
510
-        		if (empty($val['fk_leftmenu']))
511
-        		{
512
-        			$this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
513
-        			//var_dump($this->newmenu->liste);
514
-        		}
515
-        		else
516
-        		{
517
-        			// Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
518
-        			$searchlastsub=0;$lastid=0;$nextid=0;$found=0;
519
-        			foreach($this->newmenu->liste as $keyparent => $valparent)
520
-        			{
521
-        				//var_dump($valparent);
522
-        				if ($searchlastsub)    // If we started to search for last submenu
523
-        				{
524
-        					if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent;
525
-        					if ($valparent['level'] < $searchlastsub)
526
-        					{
527
-        						$nextid=$keyparent;
528
-        						break;
529
-        					}
530
-        				}
531
-        				if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu'])
532
-        				{
533
-        					//print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
534
-        					// Now we look to find last subelement of this parent (we add at end)
535
-        					$searchlastsub=($valparent['level']+1);
536
-        					$lastid=$keyparent;
537
-        					$found=1;
538
-        				}
539
-        			}
540
-        			//print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
541
-        			if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
542
-        			else {
543
-        			    dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING);
544
-        			    //print "Parent menu not found !!<br>";
545
-        			}
546
-        		}
547
-        	}
504
+            //var_dump($tabMenu);
505
+            if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu)    // We found a menu entry not linked to parent with good mainmenu
506
+            {
507
+                //print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>';
508
+                //var_dump($this->newmenu->liste);exit;
509
+
510
+                if (empty($val['fk_leftmenu']))
511
+                {
512
+                    $this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
513
+                    //var_dump($this->newmenu->liste);
514
+                }
515
+                else
516
+                {
517
+                    // Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
518
+                    $searchlastsub=0;$lastid=0;$nextid=0;$found=0;
519
+                    foreach($this->newmenu->liste as $keyparent => $valparent)
520
+                    {
521
+                        //var_dump($valparent);
522
+                        if ($searchlastsub)    // If we started to search for last submenu
523
+                        {
524
+                            if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent;
525
+                            if ($valparent['level'] < $searchlastsub)
526
+                            {
527
+                                $nextid=$keyparent;
528
+                                break;
529
+                            }
530
+                        }
531
+                        if ($valparent['mainmenu'] == $val['fk_mainmenu'] && $valparent['leftmenu'] == $val['fk_leftmenu'])
532
+                        {
533
+                            //print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
534
+                            // Now we look to find last subelement of this parent (we add at end)
535
+                            $searchlastsub=($valparent['level']+1);
536
+                            $lastid=$keyparent;
537
+                            $found=1;
538
+                        }
539
+                    }
540
+                    //print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
541
+                    if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
542
+                    else {
543
+                        dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING);
544
+                        //print "Parent menu not found !!<br>";
545
+                    }
546
+                }
547
+            }
548 548
         }
549 549
 
550 550
         return $this->newmenu;
@@ -577,10 +577,10 @@  discard block
 block discarded – undo
577 577
         if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)";
578 578
         if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)";
579 579
         $sql.= " ORDER BY m.position, m.rowid";
580
-		//print $sql;
580
+        //print $sql;
581 581
 
582
-		//$tmp1=microtime(true);
583
-		//print '>>> 1 0<br>';
582
+        //$tmp1=microtime(true);
583
+        //print '>>> 1 0<br>';
584 584
         dol_syslog(get_class($this)."::menuLoad mymainmenu=".$mymainmenu." myleftmenu=".$myleftmenu." type_user=".$type_user." menu_handler=".$menu_handler." tabMenu size=".count($tabMenu)."", LOG_DEBUG);
585 585
         $resql = $this->db->query($sql);
586 586
         if ($resql)
@@ -598,9 +598,9 @@  discard block
 block discarded – undo
598 598
                 $perms = true;
599 599
                 if ($menu['perms'])
600 600
                 {
601
-                	$tmpcond=$menu['perms'];
602
-                	if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
603
-                	$perms = verifCond($tmpcond);
601
+                    $tmpcond=$menu['perms'];
602
+                    if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
603
+                    $perms = verifCond($tmpcond);
604 604
                     //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
605 605
                 }
606 606
 
@@ -608,21 +608,21 @@  discard block
 block discarded – undo
608 608
                 $enabled = true;
609 609
                 if ($menu['enabled'])
610 610
                 {
611
-                	$tmpcond=$menu['enabled'];
612
-                	if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
611
+                    $tmpcond=$menu['enabled'];
612
+                    if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
613 613
                     $enabled = verifCond($tmpcond);
614 614
                 }
615 615
 
616 616
                 // Define $title
617 617
                 if ($enabled)
618 618
                 {
619
-                	$title = $langs->trans($menu['titre']);		// If $menu['titre'] start with $, a dol_eval is done.
620
-                	//var_dump($title.'-'.$menu['titre']);
619
+                    $title = $langs->trans($menu['titre']);		// If $menu['titre'] start with $, a dol_eval is done.
620
+                    //var_dump($title.'-'.$menu['titre']);
621 621
                     if ($title == $menu['titre'])   // Translation not found
622 622
                     {
623 623
                         if (! empty($menu['langs']))    // If there is a dedicated translation file
624 624
                         {
625
-                        	//print 'Load file '.$menu['langs'].'<br>';
625
+                            //print 'Load file '.$menu['langs'].'<br>';
626 626
                             $langs->load($menu['langs']);
627 627
                         }
628 628
 
@@ -636,18 +636,18 @@  discard block
 block discarded – undo
636 636
                         }
637 637
                         else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle)
638 638
                         {
639
-                        	$tab_title = explode("||",$menu['titre']);
640
-                        	$alt_title = explode("@",$tab_title[1]);
641
-                        	$title_enabled = verifCond($alt_title[1]);
642
-                        	$title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
639
+                            $tab_title = explode("||",$menu['titre']);
640
+                            $alt_title = explode("@",$tab_title[1]);
641
+                            $title_enabled = verifCond($alt_title[1]);
642
+                            $title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
643 643
                         }
644 644
                         else
645 645
                         {
646 646
                             $title = $langs->trans($menu['titre']);
647 647
                         }
648 648
                     }
649
-					//$tmp4=microtime(true);
650
-					//print '>>> 3 '.($tmp4 - $tmp3).'<br>';
649
+                    //$tmp4=microtime(true);
650
+                    //print '>>> 3 '.($tmp4 - $tmp3).'<br>';
651 651
 
652 652
                     // We complete tabMenu
653 653
                     $tabMenu[$b]['rowid']       = $menu['rowid'];
@@ -712,5 +712,5 @@  discard block
 block discarded – undo
712 712
                 $this->recur($tab, $tab[$x]['rowid'], ($level+1));
713 713
             }
714 714
         }
715
-   }
715
+    }
716 716
 }
Please login to merge, or discard this patch.
Spacing   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
     public $titre;
79 79
     public $langs;
80 80
     public $level;
81
-    public $leftmenu;		//<! Not used
81
+    public $leftmenu; //<! Not used
82 82
     public $perms;
83 83
     public $enabled;
84 84
     public $user;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	 *  @param		DoliDB		$db 		    Database handler
92 92
      *  @param     	string		$menu_handler	Menu handler
93 93
      */
94
-    function __construct($db,$menu_handler='')
94
+    function __construct($db, $menu_handler = '')
95 95
     {
96 96
         $this->db = $db;
97 97
         $this->menu_handler = $menu_handler;
@@ -105,29 +105,29 @@  discard block
 block discarded – undo
105 105
      *      @param      User	$user       User that create
106 106
      *      @return     int      			<0 if KO, Id of record if OK
107 107
      */
108
-    function create($user=null)
108
+    function create($user = null)
109 109
     {
110 110
         global $conf, $langs;
111 111
 
112 112
         // Clean parameters
113
-        $this->menu_handler=trim($this->menu_handler);
114
-        $this->module=trim($this->module);
115
-        $this->type=trim($this->type);
116
-        $this->mainmenu=trim($this->mainmenu);
117
-        $this->leftmenu=trim($this->leftmenu);
118
-        $this->fk_menu = (int) $this->fk_menu;          // If -1, fk_mainmenu and fk_leftmenu must be defined
119
-        $this->fk_mainmenu=trim($this->fk_mainmenu);
120
-        $this->fk_leftmenu=trim($this->fk_leftmenu);
113
+        $this->menu_handler = trim($this->menu_handler);
114
+        $this->module = trim($this->module);
115
+        $this->type = trim($this->type);
116
+        $this->mainmenu = trim($this->mainmenu);
117
+        $this->leftmenu = trim($this->leftmenu);
118
+        $this->fk_menu = (int) $this->fk_menu; // If -1, fk_mainmenu and fk_leftmenu must be defined
119
+        $this->fk_mainmenu = trim($this->fk_mainmenu);
120
+        $this->fk_leftmenu = trim($this->fk_leftmenu);
121 121
         $this->position = (int) $this->position;
122
-        $this->url=trim($this->url);
123
-        $this->target=trim($this->target);
124
-        $this->titre=trim($this->titre);
125
-        $this->langs=trim($this->langs);
126
-        $this->perms=trim($this->perms);
127
-        $this->enabled=trim($this->enabled);
128
-        $this->user=trim($this->user);
129
-        if (empty($this->position)) $this->position=0;
130
-        if (! $this->level) $this->level=0;
122
+        $this->url = trim($this->url);
123
+        $this->target = trim($this->target);
124
+        $this->titre = trim($this->titre);
125
+        $this->langs = trim($this->langs);
126
+        $this->perms = trim($this->perms);
127
+        $this->enabled = trim($this->enabled);
128
+        $this->user = trim($this->user);
129
+        if (empty($this->position)) $this->position = 0;
130
+        if (!$this->level) $this->level = 0;
131 131
 
132 132
         // Check parameters
133 133
         if (empty($this->menu_handler)) return -1;
@@ -135,36 +135,36 @@  discard block
 block discarded – undo
135 135
         // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
136 136
         // may use an already used value because its internal cursor does not increase when we do
137 137
         // an insert with a forced id.
138
-        if (in_array($this->db->type,array('pgsql')))
138
+        if (in_array($this->db->type, array('pgsql')))
139 139
         {
140 140
           $sql = "SELECT MAX(rowid) as maxrowid FROM ".MAIN_DB_PREFIX."menu";
141
-          $resqlrowid=$this->db->query($sql);
141
+          $resqlrowid = $this->db->query($sql);
142 142
           if ($resqlrowid)
143 143
           {
144
-               $obj=$this->db->fetch_object($resqlrowid);
145
-               $maxrowid=$obj->maxrowid;
144
+               $obj = $this->db->fetch_object($resqlrowid);
145
+               $maxrowid = $obj->maxrowid;
146 146
 
147 147
                // Max rowid can be empty if there is no record yet
148
-               if(empty($maxrowid)) $maxrowid=1;
148
+               if (empty($maxrowid)) $maxrowid = 1;
149 149
 
150 150
                $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")";
151 151
                //print $sql; exit;
152
-               $resqlrowidset=$this->db->query($sql);
153
-               if (! $resqlrowidset) dol_print_error($this->db);
152
+               $resqlrowidset = $this->db->query($sql);
153
+               if (!$resqlrowidset) dol_print_error($this->db);
154 154
           }
155 155
           else dol_print_error($this->db);
156 156
         }
157 157
 
158 158
         // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
159 159
         $sql = "SELECT count(*)";
160
-        $sql.= " FROM ".MAIN_DB_PREFIX."menu";
161
-        $sql.= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
162
-        $sql.= " AND fk_menu = ".((int) $this->fk_menu);
163
-        $sql.= " AND position = ".((int) $this->position);
164
-        $sql.= " AND url = '".$this->db->escape($this->url)."'";
165
-        $sql.= " AND entity = ".$conf->entity;
166
-
167
-        $result=$this->db->query($sql);
160
+        $sql .= " FROM ".MAIN_DB_PREFIX."menu";
161
+        $sql .= " WHERE menu_handler = '".$this->db->escape($this->menu_handler)."'";
162
+        $sql .= " AND fk_menu = ".((int) $this->fk_menu);
163
+        $sql .= " AND position = ".((int) $this->position);
164
+        $sql .= " AND url = '".$this->db->escape($this->url)."'";
165
+        $sql .= " AND entity = ".$conf->entity;
166
+
167
+        $result = $this->db->query($sql);
168 168
         if ($result)
169 169
         {
170 170
         	$row = $this->db->fetch_row($result);
@@ -173,45 +173,45 @@  discard block
 block discarded – undo
173 173
         	{
174 174
 		        // Insert request
175 175
 		        $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu(";
176
-		        $sql.= "menu_handler,";
177
-		        $sql.= "entity,";
178
-		        $sql.= "module,";
179
-		        $sql.= "type,";
180
-		        $sql.= "mainmenu,";
181
-		        $sql.= "leftmenu,";
182
-		        $sql.= "fk_menu,";
183
-		        $sql.= "fk_mainmenu,";
184
-		        $sql.= "fk_leftmenu,";
185
-		        $sql.= "position,";
186
-		        $sql.= "url,";
187
-		        $sql.= "target,";
188
-		        $sql.= "titre,";
189
-		        $sql.= "langs,";
190
-		        $sql.= "perms,";
191
-		        $sql.= "enabled,";
192
-		        $sql.= "usertype";
193
-		        $sql.= ") VALUES (";
194
-		        $sql.= " '".$this->db->escape($this->menu_handler)."',";
195
-		        $sql.= " '".$this->db->escape($conf->entity)."',";
196
-		        $sql.= " '".$this->db->escape($this->module)."',";
197
-		        $sql.= " '".$this->db->escape($this->type)."',";
198
-		        $sql.= " ".($this->mainmenu?"'".$this->db->escape($this->mainmenu)."'":"''").",";    // Can't be null
199
-		        $sql.= " ".($this->leftmenu?"'".$this->db->escape($this->leftmenu)."'":"null").",";
200
-		        $sql.= " ".((int) $this->fk_menu).",";
201
-		        $sql.= " ".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").",";
202
-		        $sql.= " ".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").",";
203
-		        $sql.= " ".((int) $this->position).",";
204
-		        $sql.= " '".$this->db->escape($this->url)."',";
205
-		        $sql.= " '".$this->db->escape($this->target)."',";
206
-		        $sql.= " '".$this->db->escape($this->titre)."',";
207
-		        $sql.= " '".$this->db->escape($this->langs)."',";
208
-		        $sql.= " '".$this->db->escape($this->perms)."',";
209
-		        $sql.= " '".$this->db->escape($this->enabled)."',";
210
-		        $sql.= " '".$this->db->escape($this->user)."'";
211
-		        $sql.= ")";
176
+		        $sql .= "menu_handler,";
177
+		        $sql .= "entity,";
178
+		        $sql .= "module,";
179
+		        $sql .= "type,";
180
+		        $sql .= "mainmenu,";
181
+		        $sql .= "leftmenu,";
182
+		        $sql .= "fk_menu,";
183
+		        $sql .= "fk_mainmenu,";
184
+		        $sql .= "fk_leftmenu,";
185
+		        $sql .= "position,";
186
+		        $sql .= "url,";
187
+		        $sql .= "target,";
188
+		        $sql .= "titre,";
189
+		        $sql .= "langs,";
190
+		        $sql .= "perms,";
191
+		        $sql .= "enabled,";
192
+		        $sql .= "usertype";
193
+		        $sql .= ") VALUES (";
194
+		        $sql .= " '".$this->db->escape($this->menu_handler)."',";
195
+		        $sql .= " '".$this->db->escape($conf->entity)."',";
196
+		        $sql .= " '".$this->db->escape($this->module)."',";
197
+		        $sql .= " '".$this->db->escape($this->type)."',";
198
+		        $sql .= " ".($this->mainmenu ? "'".$this->db->escape($this->mainmenu)."'" : "''").","; // Can't be null
199
+		        $sql .= " ".($this->leftmenu ? "'".$this->db->escape($this->leftmenu)."'" : "null").",";
200
+		        $sql .= " ".((int) $this->fk_menu).",";
201
+		        $sql .= " ".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
202
+		        $sql .= " ".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
203
+		        $sql .= " ".((int) $this->position).",";
204
+		        $sql .= " '".$this->db->escape($this->url)."',";
205
+		        $sql .= " '".$this->db->escape($this->target)."',";
206
+		        $sql .= " '".$this->db->escape($this->titre)."',";
207
+		        $sql .= " '".$this->db->escape($this->langs)."',";
208
+		        $sql .= " '".$this->db->escape($this->perms)."',";
209
+		        $sql .= " '".$this->db->escape($this->enabled)."',";
210
+		        $sql .= " '".$this->db->escape($this->user)."'";
211
+		        $sql .= ")";
212 212
 
213 213
 		        dol_syslog(get_class($this)."::create", LOG_DEBUG);
214
-		        $resql=$this->db->query($sql);
214
+		        $resql = $this->db->query($sql);
215 215
 		        if ($resql)
216 216
 		        {
217 217
 		            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."menu");
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		        }
222 222
 		        else
223 223
 		        {
224
-		            $this->error="Error ".$this->db->lasterror();
224
+		            $this->error = "Error ".$this->db->lasterror();
225 225
 		            return -1;
226 226
 		        }
227 227
         	}
@@ -245,57 +245,57 @@  discard block
 block discarded – undo
245 245
      *  @param  int		$notrigger	    0=no, 1=yes (no update trigger)
246 246
      *  @return int 		        	<0 if KO, >0 if OK
247 247
      */
248
-    function update($user=null, $notrigger=0)
248
+    function update($user = null, $notrigger = 0)
249 249
     {
250 250
         global $conf, $langs;
251 251
 
252 252
         // Clean parameters
253
-        $this->rowid=trim($this->rowid);
254
-        $this->menu_handler=trim($this->menu_handler);
255
-        $this->module=trim($this->module);
256
-        $this->type=trim($this->type);
257
-        $this->mainmenu=trim($this->mainmenu);
258
-        $this->leftmenu=trim($this->leftmenu);
253
+        $this->rowid = trim($this->rowid);
254
+        $this->menu_handler = trim($this->menu_handler);
255
+        $this->module = trim($this->module);
256
+        $this->type = trim($this->type);
257
+        $this->mainmenu = trim($this->mainmenu);
258
+        $this->leftmenu = trim($this->leftmenu);
259 259
         $this->fk_menu = (int) $this->fk_menu;
260
-        $this->fk_mainmenu=trim($this->fk_mainmenu);
261
-        $this->fk_leftmenu=trim($this->fk_leftmenu);
260
+        $this->fk_mainmenu = trim($this->fk_mainmenu);
261
+        $this->fk_leftmenu = trim($this->fk_leftmenu);
262 262
         $this->position = (int) $this->position;
263
-        $this->url=trim($this->url);
264
-        $this->target=trim($this->target);
265
-        $this->titre=trim($this->titre);
266
-        $this->langs=trim($this->langs);
267
-        $this->perms=trim($this->perms);
268
-        $this->enabled=trim($this->enabled);
269
-        $this->user=trim($this->user);
263
+        $this->url = trim($this->url);
264
+        $this->target = trim($this->target);
265
+        $this->titre = trim($this->titre);
266
+        $this->langs = trim($this->langs);
267
+        $this->perms = trim($this->perms);
268
+        $this->enabled = trim($this->enabled);
269
+        $this->user = trim($this->user);
270 270
 
271 271
         // Check parameters
272 272
         // Put here code to add control on parameters values
273 273
 
274 274
         // Update request
275 275
         $sql = "UPDATE ".MAIN_DB_PREFIX."menu SET";
276
-        $sql.= " menu_handler='".$this->db->escape($this->menu_handler)."',";
277
-        $sql.= " module='".$this->db->escape($this->module)."',";
278
-        $sql.= " type='".$this->db->escape($this->type)."',";
279
-        $sql.= " mainmenu='".$this->db->escape($this->mainmenu)."',";
280
-        $sql.= " leftmenu='".$this->db->escape($this->leftmenu)."',";
281
-        $sql.= " fk_menu=".$this->fk_menu.",";
282
-        $sql.= " fk_mainmenu=".($this->fk_mainmenu?"'".$this->db->escape($this->fk_mainmenu)."'":"null").",";
283
-        $sql.= " fk_leftmenu=".($this->fk_leftmenu?"'".$this->db->escape($this->fk_leftmenu)."'":"null").",";
284
-        $sql.= " position=".($this->position > 0 ? $this->position : 0).",";
285
-        $sql.= " url='".$this->db->escape($this->url)."',";
286
-        $sql.= " target='".$this->db->escape($this->target)."',";
287
-        $sql.= " titre='".$this->db->escape($this->titre)."',";
288
-        $sql.= " langs='".$this->db->escape($this->langs)."',";
289
-        $sql.= " perms='".$this->db->escape($this->perms)."',";
290
-        $sql.= " enabled='".$this->db->escape($this->enabled)."',";
291
-        $sql.= " usertype='".$this->db->escape($this->user)."'";
292
-        $sql.= " WHERE rowid=".$this->id;
276
+        $sql .= " menu_handler='".$this->db->escape($this->menu_handler)."',";
277
+        $sql .= " module='".$this->db->escape($this->module)."',";
278
+        $sql .= " type='".$this->db->escape($this->type)."',";
279
+        $sql .= " mainmenu='".$this->db->escape($this->mainmenu)."',";
280
+        $sql .= " leftmenu='".$this->db->escape($this->leftmenu)."',";
281
+        $sql .= " fk_menu=".$this->fk_menu.",";
282
+        $sql .= " fk_mainmenu=".($this->fk_mainmenu ? "'".$this->db->escape($this->fk_mainmenu)."'" : "null").",";
283
+        $sql .= " fk_leftmenu=".($this->fk_leftmenu ? "'".$this->db->escape($this->fk_leftmenu)."'" : "null").",";
284
+        $sql .= " position=".($this->position > 0 ? $this->position : 0).",";
285
+        $sql .= " url='".$this->db->escape($this->url)."',";
286
+        $sql .= " target='".$this->db->escape($this->target)."',";
287
+        $sql .= " titre='".$this->db->escape($this->titre)."',";
288
+        $sql .= " langs='".$this->db->escape($this->langs)."',";
289
+        $sql .= " perms='".$this->db->escape($this->perms)."',";
290
+        $sql .= " enabled='".$this->db->escape($this->enabled)."',";
291
+        $sql .= " usertype='".$this->db->escape($this->user)."'";
292
+        $sql .= " WHERE rowid=".$this->id;
293 293
 
294 294
         dol_syslog(get_class($this)."::update", LOG_DEBUG);
295 295
         $resql = $this->db->query($sql);
296
-        if (! $resql)
296
+        if (!$resql)
297 297
         {
298
-            $this->error="Error ".$this->db->lasterror();
298
+            $this->error = "Error ".$this->db->lasterror();
299 299
             return -1;
300 300
         }
301 301
 
@@ -310,42 +310,42 @@  discard block
 block discarded – undo
310 310
      *   @param		User    $user       User that load
311 311
      *   @return	int         		<0 if KO, >0 if OK
312 312
      */
313
-    function fetch($id, $user=null)
313
+    function fetch($id, $user = null)
314 314
     {
315 315
         global $langs;
316 316
 
317 317
         $sql = "SELECT";
318
-        $sql.= " t.rowid,";
319
-        $sql.= " t.menu_handler,";
320
-        $sql.= " t.entity,";
321
-        $sql.= " t.module,";
322
-        $sql.= " t.type,";
323
-        $sql.= " t.mainmenu,";
324
-        $sql.= " t.leftmenu,";
325
-        $sql.= " t.fk_menu,";
326
-        $sql.= " t.fk_mainmenu,";
327
-        $sql.= " t.fk_leftmenu,";
328
-        $sql.= " t.position,";
329
-        $sql.= " t.url,";
330
-        $sql.= " t.target,";
331
-        $sql.= " t.titre,";
332
-        $sql.= " t.langs,";
333
-        $sql.= " t.perms,";
334
-        $sql.= " t.enabled,";
335
-        $sql.= " t.usertype as user,";
336
-        $sql.= " t.tms";
337
-        $sql.= " FROM ".MAIN_DB_PREFIX."menu as t";
338
-        $sql.= " WHERE t.rowid = ".$id;
318
+        $sql .= " t.rowid,";
319
+        $sql .= " t.menu_handler,";
320
+        $sql .= " t.entity,";
321
+        $sql .= " t.module,";
322
+        $sql .= " t.type,";
323
+        $sql .= " t.mainmenu,";
324
+        $sql .= " t.leftmenu,";
325
+        $sql .= " t.fk_menu,";
326
+        $sql .= " t.fk_mainmenu,";
327
+        $sql .= " t.fk_leftmenu,";
328
+        $sql .= " t.position,";
329
+        $sql .= " t.url,";
330
+        $sql .= " t.target,";
331
+        $sql .= " t.titre,";
332
+        $sql .= " t.langs,";
333
+        $sql .= " t.perms,";
334
+        $sql .= " t.enabled,";
335
+        $sql .= " t.usertype as user,";
336
+        $sql .= " t.tms";
337
+        $sql .= " FROM ".MAIN_DB_PREFIX."menu as t";
338
+        $sql .= " WHERE t.rowid = ".$id;
339 339
 
340 340
         dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
341
-        $resql=$this->db->query($sql);
341
+        $resql = $this->db->query($sql);
342 342
         if ($resql)
343 343
         {
344 344
             if ($this->db->num_rows($resql))
345 345
             {
346 346
                 $obj = $this->db->fetch_object($resql);
347 347
 
348
-                $this->id    = $obj->rowid;
348
+                $this->id = $obj->rowid;
349 349
 
350 350
                 $this->menu_handler = $obj->menu_handler;
351 351
                 $this->entity = $obj->entity;
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
                 $this->titre = $obj->titre;
363 363
                 $this->langs = $obj->langs;
364 364
                 $this->perms = $obj->perms;
365
-                $this->enabled = str_replace("\"","'",$obj->enabled);
365
+                $this->enabled = str_replace("\"", "'", $obj->enabled);
366 366
                 $this->user = $obj->user;
367 367
                 $this->tms = $this->db->jdate($obj->tms);
368 368
             }
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
         }
373 373
         else
374 374
         {
375
-            $this->error="Error ".$this->db->lasterror();
375
+            $this->error = "Error ".$this->db->lasterror();
376 376
             return -1;
377 377
         }
378 378
     }
@@ -389,13 +389,13 @@  discard block
 block discarded – undo
389 389
         global $conf, $langs;
390 390
 
391 391
         $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu";
392
-        $sql.= " WHERE rowid=".$this->id;
392
+        $sql .= " WHERE rowid=".$this->id;
393 393
 
394 394
         dol_syslog(get_class($this)."::delete", LOG_DEBUG);
395 395
         $resql = $this->db->query($sql);
396
-        if (! $resql)
396
+        if (!$resql)
397 397
         {
398
-            $this->error="Error ".$this->db->lasterror();
398
+            $this->error = "Error ".$this->db->lasterror();
399 399
             return -1;
400 400
         }
401 401
 
@@ -412,24 +412,24 @@  discard block
 block discarded – undo
412 412
      */
413 413
     function initAsSpecimen()
414 414
     {
415
-        $this->id=0;
416
-
417
-        $this->menu_handler='all';
418
-        $this->module='specimen';
419
-        $this->type='top';
420
-        $this->mainmenu='';
421
-        $this->fk_menu='0';
422
-        $this->position='';
423
-        $this->url='http://dummy';
424
-        $this->target='';
425
-        $this->titre='Specimen menu';
426
-        $this->langs='';
427
-        $this->level='';
428
-        $this->leftmenu='';
429
-        $this->perms='';
430
-        $this->enabled='';
431
-        $this->user='';
432
-        $this->tms='';
415
+        $this->id = 0;
416
+
417
+        $this->menu_handler = 'all';
418
+        $this->module = 'specimen';
419
+        $this->type = 'top';
420
+        $this->mainmenu = '';
421
+        $this->fk_menu = '0';
422
+        $this->position = '';
423
+        $this->url = 'http://dummy';
424
+        $this->target = '';
425
+        $this->titre = 'Specimen menu';
426
+        $this->langs = '';
427
+        $this->level = '';
428
+        $this->leftmenu = '';
429
+        $this->perms = '';
430
+        $this->enabled = '';
431
+        $this->user = '';
432
+        $this->tms = '';
433 433
     }
434 434
 
435 435
 
@@ -445,16 +445,16 @@  discard block
 block discarded – undo
445 445
      */
446 446
     function menuTopCharger($mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
447 447
     {
448
-        global $langs, $user, $conf;	// To export to dol_eval function
449
-        global $mainmenu,$leftmenu;		// To export to dol_eval function
448
+        global $langs, $user, $conf; // To export to dol_eval function
449
+        global $mainmenu, $leftmenu; // To export to dol_eval function
450 450
 
451
-        $mainmenu=$mymainmenu;  // To export to dol_eval function
452
-        $leftmenu=$myleftmenu;  // To export to dol_eval function
451
+        $mainmenu = $mymainmenu; // To export to dol_eval function
452
+        $leftmenu = $myleftmenu; // To export to dol_eval function
453 453
 
454
-        $newTabMenu=array();
455
-        foreach($tabMenu as $val)
454
+        $newTabMenu = array();
455
+        foreach ($tabMenu as $val)
456 456
         {
457
-            if ($val['type']=='top') $newTabMenu[]=$val;
457
+            if ($val['type'] == 'top') $newTabMenu[] = $val;
458 458
         }
459 459
 
460 460
         return $newTabMenu;
@@ -474,20 +474,20 @@  discard block
 block discarded – undo
474 474
      */
475 475
     function menuLeftCharger($newmenu, $mymainmenu, $myleftmenu, $type_user, $menu_handler, &$tabMenu)
476 476
     {
477
-        global $langs, $user, $conf; 	// To export to dol_eval function
478
-        global $mainmenu,$leftmenu; 	// To export to dol_eval function
477
+        global $langs, $user, $conf; // To export to dol_eval function
478
+        global $mainmenu, $leftmenu; // To export to dol_eval function
479 479
 
480
-        $mainmenu=$mymainmenu;  // To export to dol_eval function
481
-        $leftmenu=$myleftmenu;  // To export to dol_eval function
480
+        $mainmenu = $mymainmenu; // To export to dol_eval function
481
+        $leftmenu = $myleftmenu; // To export to dol_eval function
482 482
 
483 483
 		// Detect what is top mainmenu id
484
-        $menutopid='';
485
-        foreach($tabMenu as $key => $val)
484
+        $menutopid = '';
485
+        foreach ($tabMenu as $key => $val)
486 486
         {
487 487
         	// Define menutopid of mainmenu
488 488
         	if (empty($menutopid) && $val['type'] == 'top' && $val['mainmenu'] == $mainmenu)
489 489
         	{
490
-        		$menutopid=$val['rowid'];
490
+        		$menutopid = $val['rowid'];
491 491
         		break;
492 492
         	}
493 493
         }
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
         $this->recur($tabMenu, $menutopid, 1);
500 500
 
501 501
         // Now complete $this->newmenu->list when fk_menu value is -1 (left menu added by modules with no top menu)
502
-        foreach($tabMenu as $key => $val)
502
+        foreach ($tabMenu as $key => $val)
503 503
         {
504 504
         	//var_dump($tabMenu);
505 505
         	if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu)    // We found a menu entry not linked to parent with good mainmenu
@@ -515,16 +515,16 @@  discard block
 block discarded – undo
515 515
         		else
516 516
         		{
517 517
         			// Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
518
-        			$searchlastsub=0;$lastid=0;$nextid=0;$found=0;
519
-        			foreach($this->newmenu->liste as $keyparent => $valparent)
518
+        			$searchlastsub = 0; $lastid = 0; $nextid = 0; $found = 0;
519
+        			foreach ($this->newmenu->liste as $keyparent => $valparent)
520 520
         			{
521 521
         				//var_dump($valparent);
522 522
         				if ($searchlastsub)    // If we started to search for last submenu
523 523
         				{
524
-        					if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent;
524
+        					if ($valparent['level'] >= $searchlastsub) $lastid = $keyparent;
525 525
         					if ($valparent['level'] < $searchlastsub)
526 526
         					{
527
-        						$nextid=$keyparent;
527
+        						$nextid = $keyparent;
528 528
         						break;
529 529
         					}
530 530
         				}
@@ -532,9 +532,9 @@  discard block
 block discarded – undo
532 532
         				{
533 533
         					//print "We found parent: keyparent='.$keyparent.' - level=".$valparent['level'].' - '.join(',',$valparent).'<br>';
534 534
         					// Now we look to find last subelement of this parent (we add at end)
535
-        					$searchlastsub=($valparent['level']+1);
536
-        					$lastid=$keyparent;
537
-        					$found=1;
535
+        					$searchlastsub = ($valparent['level'] + 1);
536
+        					$lastid = $keyparent;
537
+        					$found = 1;
538 538
         				}
539 539
         			}
540 540
         			//print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
@@ -566,17 +566,17 @@  discard block
 block discarded – undo
566 566
         global $langs, $user, $conf; // To export to dol_eval function
567 567
         global $mainmenu, $leftmenu; // To export to dol_eval function
568 568
 
569
-        $menutopid=0;
570
-        $mainmenu=$mymainmenu;  // To export to dol_eval function
571
-        $leftmenu=$myleftmenu;  // To export to dol_eval function
569
+        $menutopid = 0;
570
+        $mainmenu = $mymainmenu; // To export to dol_eval function
571
+        $leftmenu = $myleftmenu; // To export to dol_eval function
572 572
 
573 573
         $sql = "SELECT m.rowid, m.type, m.module, m.fk_menu, m.fk_mainmenu, m.fk_leftmenu, m.url, m.titre, m.langs, m.perms, m.enabled, m.target, m.mainmenu, m.leftmenu, m.position";
574
-        $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
575
-        $sql.= " WHERE m.entity IN (0,".$conf->entity.")";
576
-        $sql.= " AND m.menu_handler IN ('".$menu_handler."','all')";
577
-        if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)";
578
-        if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)";
579
-        $sql.= " ORDER BY m.position, m.rowid";
574
+        $sql .= " FROM ".MAIN_DB_PREFIX."menu as m";
575
+        $sql .= " WHERE m.entity IN (0,".$conf->entity.")";
576
+        $sql .= " AND m.menu_handler IN ('".$menu_handler."','all')";
577
+        if ($type_user == 0) $sql .= " AND m.usertype IN (0,2)";
578
+        if ($type_user == 1) $sql .= " AND m.usertype IN (1,2)";
579
+        $sql .= " ORDER BY m.position, m.rowid";
580 580
 		//print $sql;
581 581
 
582 582
 		//$tmp1=microtime(true);
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
                 $perms = true;
599 599
                 if ($menu['perms'])
600 600
                 {
601
-                	$tmpcond=$menu['perms'];
602
-                	if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
601
+                	$tmpcond = $menu['perms'];
602
+                	if ($leftmenu == 'all') $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
603 603
                 	$perms = verifCond($tmpcond);
604 604
                     //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
605 605
                 }
@@ -608,19 +608,19 @@  discard block
 block discarded – undo
608 608
                 $enabled = true;
609 609
                 if ($menu['enabled'])
610 610
                 {
611
-                	$tmpcond=$menu['enabled'];
612
-                	if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
611
+                	$tmpcond = $menu['enabled'];
612
+                	if ($leftmenu == 'all') $tmpcond = preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/', '1==1', $tmpcond); // Force part of condition to true
613 613
                     $enabled = verifCond($tmpcond);
614 614
                 }
615 615
 
616 616
                 // Define $title
617 617
                 if ($enabled)
618 618
                 {
619
-                	$title = $langs->trans($menu['titre']);		// If $menu['titre'] start with $, a dol_eval is done.
619
+                	$title = $langs->trans($menu['titre']); // If $menu['titre'] start with $, a dol_eval is done.
620 620
                 	//var_dump($title.'-'.$menu['titre']);
621 621
                     if ($title == $menu['titre'])   // Translation not found
622 622
                     {
623
-                        if (! empty($menu['langs']))    // If there is a dedicated translation file
623
+                        if (!empty($menu['langs']))    // If there is a dedicated translation file
624 624
                         {
625 625
                         	//print 'Load file '.$menu['langs'].'<br>';
626 626
                             $langs->load($menu['langs']);
@@ -629,15 +629,15 @@  discard block
 block discarded – undo
629 629
                         $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
630 630
                         $menu['titre'] = make_substitutions($menu['titre'], $substitarray);
631 631
 
632
-                        if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2
632
+                        if (preg_match("/\//", $menu['titre'])) // To manage translation when title is string1/string2
633 633
                         {
634
-                            $tab_titre = explode("/",$menu['titre']);
634
+                            $tab_titre = explode("/", $menu['titre']);
635 635
                             $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
636 636
                         }
637
-                        else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle)
637
+                        else if (preg_match('/\|\|/', $menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle)
638 638
                         {
639
-                        	$tab_title = explode("||",$menu['titre']);
640
-                        	$alt_title = explode("@",$tab_title[1]);
639
+                        	$tab_title = explode("||", $menu['titre']);
640
+                        	$alt_title = explode("@", $tab_title[1]);
641 641
                         	$title_enabled = verifCond($alt_title[1]);
642 642
                         	$title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
643 643
                         }
@@ -654,10 +654,10 @@  discard block
 block discarded – undo
654 654
                     $tabMenu[$b]['module']      = $menu['module'];
655 655
                     $tabMenu[$b]['fk_menu']     = $menu['fk_menu'];
656 656
                     $tabMenu[$b]['url']         = $menu['url'];
657
-                    if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url']))
657
+                    if (!preg_match("/^(http:\/\/|https:\/\/)/i", $tabMenu[$b]['url']))
658 658
                     {
659
-                        if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&amp;idmenu='.$menu['rowid'];
660
-                        else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid'];
659
+                        if (preg_match('/\?/', $tabMenu[$b]['url'])) $tabMenu[$b]['url'] .= '&amp;idmenu='.$menu['rowid'];
660
+                        else $tabMenu[$b]['url'] .= '?idmenu='.$menu['rowid'];
661 661
                     }
662 662
                     $tabMenu[$b]['titre']       = $title;
663 663
                     $tabMenu[$b]['target']      = $menu['target'];
@@ -706,10 +706,10 @@  discard block
 block discarded – undo
706 706
         for ($x = 0; $x < $num; $x++)
707 707
         {
708 708
             //si un element a pour pere : $pere
709
-            if ( (($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled'])
709
+            if ((($tab[$x]['fk_menu'] >= 0 && $tab[$x]['fk_menu'] == $pere)) && $tab[$x]['enabled'])
710 710
             {
711
-                $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level-1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu']);
712
-                $this->recur($tab, $tab[$x]['rowid'], ($level+1));
711
+                $this->newmenu->add($tab[$x]['url'], $tab[$x]['titre'], ($level - 1), $tab[$x]['perms'], $tab[$x]['target'], $tab[$x]['mainmenu'], $tab[$x]['leftmenu']);
712
+                $this->recur($tab, $tab[$x]['rowid'], ($level + 1));
713 713
             }
714 714
         }
715 715
    }
Please login to merge, or discard this patch.
Braces   +67 added lines, -36 removed lines patch added patch discarded remove patch
@@ -126,11 +126,17 @@  discard block
 block discarded – undo
126 126
         $this->perms=trim($this->perms);
127 127
         $this->enabled=trim($this->enabled);
128 128
         $this->user=trim($this->user);
129
-        if (empty($this->position)) $this->position=0;
130
-        if (! $this->level) $this->level=0;
129
+        if (empty($this->position)) {
130
+            $this->position=0;
131
+        }
132
+        if (! $this->level) {
133
+            $this->level=0;
134
+        }
131 135
 
132 136
         // Check parameters
133
-        if (empty($this->menu_handler)) return -1;
137
+        if (empty($this->menu_handler)) {
138
+            return -1;
139
+        }
134 140
 
135 141
         // For PGSQL, we must first found the max rowid and use it as rowid in insert because postgresql
136 142
         // may use an already used value because its internal cursor does not increase when we do
@@ -145,14 +151,19 @@  discard block
 block discarded – undo
145 151
                $maxrowid=$obj->maxrowid;
146 152
 
147 153
                // Max rowid can be empty if there is no record yet
148
-               if(empty($maxrowid)) $maxrowid=1;
154
+               if(empty($maxrowid)) {
155
+                   $maxrowid=1;
156
+               }
149 157
 
150 158
                $sql = "SELECT setval('".MAIN_DB_PREFIX."menu_rowid_seq', ".($maxrowid).")";
151 159
                //print $sql; exit;
152 160
                $resqlrowidset=$this->db->query($sql);
153
-               if (! $resqlrowidset) dol_print_error($this->db);
161
+               if (! $resqlrowidset) {
162
+                   dol_print_error($this->db);
163
+               }
164
+          } else {
165
+              dol_print_error($this->db);
154 166
           }
155
-          else dol_print_error($this->db);
156 167
         }
157 168
 
158 169
         // Check that entry does not exists yet on key menu_handler-fk_menu-position-url-entity, to avoid errors with postgresql
@@ -169,10 +180,12 @@  discard block
 block discarded – undo
169 180
         {
170 181
         	$row = $this->db->fetch_row($result);
171 182
 
172
-        	if ($row[0] == 0)   // If not found
183
+        	if ($row[0] == 0) {
184
+        	    // If not found
173 185
         	{
174 186
 		        // Insert request
175 187
 		        $sql = "INSERT INTO ".MAIN_DB_PREFIX."menu(";
188
+        	}
176 189
 		        $sql.= "menu_handler,";
177 190
 		        $sql.= "entity,";
178 191
 		        $sql.= "module,";
@@ -218,21 +231,18 @@  discard block
 block discarded – undo
218 231
 		            dol_syslog(get_class($this)."::create record added has rowid=".$this->id, LOG_DEBUG);
219 232
 
220 233
 		            return $this->id;
221
-		        }
222
-		        else
234
+		        } else
223 235
 		        {
224 236
 		            $this->error="Error ".$this->db->lasterror();
225 237
 		            return -1;
226 238
 		        }
227
-        	}
228
-        	else
239
+        	} else
229 240
         	{
230 241
         		dol_syslog(get_class($this)."::create menu entry already exists", LOG_WARNING);
231 242
         		$this->error = 'Error Menu entry already exists';
232 243
         		return 0;
233 244
         	}
234
-        }
235
-        else
245
+        } else
236 246
         {
237 247
         	return -1;
238 248
         }
@@ -369,8 +379,7 @@  discard block
 block discarded – undo
369 379
             $this->db->free($resql);
370 380
 
371 381
             return 1;
372
-        }
373
-        else
382
+        } else
374 383
         {
375 384
             $this->error="Error ".$this->db->lasterror();
376 385
             return -1;
@@ -454,7 +463,9 @@  discard block
 block discarded – undo
454 463
         $newTabMenu=array();
455 464
         foreach($tabMenu as $val)
456 465
         {
457
-            if ($val['type']=='top') $newTabMenu[]=$val;
466
+            if ($val['type']=='top') {
467
+                $newTabMenu[]=$val;
468
+            }
458 469
         }
459 470
 
460 471
         return $newTabMenu;
@@ -502,7 +513,8 @@  discard block
 block discarded – undo
502 513
         foreach($tabMenu as $key => $val)
503 514
         {
504 515
         	//var_dump($tabMenu);
505
-        	if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu)    // We found a menu entry not linked to parent with good mainmenu
516
+        	if ($val['fk_menu'] == -1 && $val['fk_mainmenu'] == $mainmenu) {
517
+        	    // We found a menu entry not linked to parent with good mainmenu
506 518
         	{
507 519
         		//print 'Try to add menu (current is mainmenu='.$mainmenu.' leftmenu='.$leftmenu.') for '.join(',',$val).' fk_mainmenu='.$val['fk_mainmenu'].' fk_leftmenu='.$val['fk_leftmenu'].'<br>';
508 520
         		//var_dump($this->newmenu->liste);exit;
@@ -510,18 +522,20 @@  discard block
 block discarded – undo
510 522
         		if (empty($val['fk_leftmenu']))
511 523
         		{
512 524
         			$this->newmenu->add($val['url'], $val['titre'], 0, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
525
+        	}
513 526
         			//var_dump($this->newmenu->liste);
514
-        		}
515
-        		else
527
+        		} else
516 528
         		{
517 529
         			// Search first menu with this couple (mainmenu,leftmenu)=(fk_mainmenu,fk_leftmenu)
518 530
         			$searchlastsub=0;$lastid=0;$nextid=0;$found=0;
519 531
         			foreach($this->newmenu->liste as $keyparent => $valparent)
520 532
         			{
521 533
         				//var_dump($valparent);
522
-        				if ($searchlastsub)    // If we started to search for last submenu
534
+        				if ($searchlastsub) {
535
+        				    // If we started to search for last submenu
523 536
         				{
524 537
         					if ($valparent['level'] >= $searchlastsub) $lastid=$keyparent;
538
+        				}
525 539
         					if ($valparent['level'] < $searchlastsub)
526 540
         					{
527 541
         						$nextid=$keyparent;
@@ -538,8 +552,9 @@  discard block
 block discarded – undo
538 552
         				}
539 553
         			}
540 554
         			//print 'We must insert menu entry between entry '.$lastid.' and '.$nextid.'<br>';
541
-        			if ($found) $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
542
-        			else {
555
+        			if ($found) {
556
+        			    $this->newmenu->insert($lastid, $val['url'], $val['titre'], $searchlastsub, $val['perms'], $val['target'], $val['mainmenu'], $val['leftmenu'], $val['position']);
557
+        			} else {
543 558
         			    dol_syslog("Error. Modules ".$val['module']." has defined a menu entry with a parent='fk_mainmenu=".$val['fk_leftmenu'].",fk_leftmenu=".$val['fk_leftmenu']."' and position=".$val['position'].'. The parent was not found. May be you forget it into your definition of menu, or may be the parent has a "position" that is after the child (fix field "position" of parent or child in this case).', LOG_WARNING);
544 559
         			    //print "Parent menu not found !!<br>";
545 560
         			}
@@ -574,8 +589,12 @@  discard block
 block discarded – undo
574 589
         $sql.= " FROM ".MAIN_DB_PREFIX."menu as m";
575 590
         $sql.= " WHERE m.entity IN (0,".$conf->entity.")";
576 591
         $sql.= " AND m.menu_handler IN ('".$menu_handler."','all')";
577
-        if ($type_user == 0) $sql.= " AND m.usertype IN (0,2)";
578
-        if ($type_user == 1) $sql.= " AND m.usertype IN (1,2)";
592
+        if ($type_user == 0) {
593
+            $sql.= " AND m.usertype IN (0,2)";
594
+        }
595
+        if ($type_user == 1) {
596
+            $sql.= " AND m.usertype IN (1,2)";
597
+        }
579 598
         $sql.= " ORDER BY m.position, m.rowid";
580 599
 		//print $sql;
581 600
 
@@ -599,7 +618,10 @@  discard block
 block discarded – undo
599 618
                 if ($menu['perms'])
600 619
                 {
601 620
                 	$tmpcond=$menu['perms'];
602
-                	if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
621
+                	if ($leftmenu == 'all') {
622
+                	    $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);
623
+                	}
624
+                	// Force part of condition to true
603 625
                 	$perms = verifCond($tmpcond);
604 626
                     //print "verifCond rowid=".$menu['rowid']." ".$tmpcond.":".$perms."<br>\n";
605 627
                 }
@@ -609,7 +631,10 @@  discard block
 block discarded – undo
609 631
                 if ($menu['enabled'])
610 632
                 {
611 633
                 	$tmpcond=$menu['enabled'];
612
-                	if ($leftmenu == 'all') $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);	// Force part of condition to true
634
+                	if ($leftmenu == 'all') {
635
+                	    $tmpcond=preg_replace('/\$leftmenu\s*==\s*["\'a-zA-Z_]+/','1==1',$tmpcond);
636
+                	}
637
+                	// Force part of condition to true
613 638
                     $enabled = verifCond($tmpcond);
614 639
                 }
615 640
 
@@ -618,30 +643,34 @@  discard block
 block discarded – undo
618 643
                 {
619 644
                 	$title = $langs->trans($menu['titre']);		// If $menu['titre'] start with $, a dol_eval is done.
620 645
                 	//var_dump($title.'-'.$menu['titre']);
621
-                    if ($title == $menu['titre'])   // Translation not found
646
+                    if ($title == $menu['titre']) {
647
+                        // Translation not found
622 648
                     {
623 649
                         if (! empty($menu['langs']))    // If there is a dedicated translation file
624 650
                         {
625 651
                         	//print 'Load file '.$menu['langs'].'<br>';
626 652
                             $langs->load($menu['langs']);
653
+                    }
627 654
                         }
628 655
 
629 656
                         $substitarray = array('__LOGIN__' => $user->login, '__USER_ID__' => $user->id, '__USER_SUPERVISOR_ID__' => $user->fk_user);
630 657
                         $menu['titre'] = make_substitutions($menu['titre'], $substitarray);
631 658
 
632
-                        if (preg_match("/\//",$menu['titre'])) // To manage translation when title is string1/string2
659
+                        if (preg_match("/\//",$menu['titre'])) {
660
+                            // To manage translation when title is string1/string2
633 661
                         {
634 662
                             $tab_titre = explode("/",$menu['titre']);
635
-                            $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
636 663
                         }
637
-                        else if (preg_match('/\|\|/',$menu['titre'])) // To manage different translation (Title||AltTitle@ConditionForAltTitle)
664
+                            $title = $langs->trans($tab_titre[0])."/".$langs->trans($tab_titre[1]);
665
+                        } else if (preg_match('/\|\|/',$menu['titre'])) {
666
+                            // To manage different translation (Title||AltTitle@ConditionForAltTitle)
638 667
                         {
639 668
                         	$tab_title = explode("||",$menu['titre']);
669
+                        }
640 670
                         	$alt_title = explode("@",$tab_title[1]);
641 671
                         	$title_enabled = verifCond($alt_title[1]);
642 672
                         	$title = ($title_enabled ? $langs->trans($alt_title[0]) : $langs->trans($tab_title[0]));
643
-                        }
644
-                        else
673
+                        } else
645 674
                         {
646 675
                             $title = $langs->trans($menu['titre']);
647 676
                         }
@@ -656,8 +685,11 @@  discard block
 block discarded – undo
656 685
                     $tabMenu[$b]['url']         = $menu['url'];
657 686
                     if (! preg_match("/^(http:\/\/|https:\/\/)/i",$tabMenu[$b]['url']))
658 687
                     {
659
-                        if (preg_match('/\?/',$tabMenu[$b]['url'])) $tabMenu[$b]['url'].='&amp;idmenu='.$menu['rowid'];
660
-                        else $tabMenu[$b]['url'].='?idmenu='.$menu['rowid'];
688
+                        if (preg_match('/\?/',$tabMenu[$b]['url'])) {
689
+                            $tabMenu[$b]['url'].='&amp;idmenu='.$menu['rowid'];
690
+                        } else {
691
+                            $tabMenu[$b]['url'].='?idmenu='.$menu['rowid'];
692
+                        }
661 693
                     }
662 694
                     $tabMenu[$b]['titre']       = $title;
663 695
                     $tabMenu[$b]['target']      = $menu['target'];
@@ -683,8 +715,7 @@  discard block
 block discarded – undo
683 715
             // into the leftMenuCharger later to avoid useless operations.
684 716
 
685 717
             return 1;
686
-        }
687
-        else
718
+        } else
688 719
         {
689 720
             dol_print_error($this->db);
690 721
             return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/dolreceiptprinter.class.php 2 patches
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -545,8 +545,7 @@
 block discarded – undo
545 545
         $ret = $this->InitPrinter($printerid);
546 546
         if ($ret>0) {
547 547
             setEventMessages($this->error, $this->errors, 'errors');
548
-        }
549
-        else
548
+        } else
550 549
         {
551 550
             $nboflines = count($vals);
552 551
             for ($line=0; $line < $nboflines; $line++)
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
  *
93 93
  */
94 94
 
95
-require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/Escpos.php';
95
+require_once DOL_DOCUMENT_ROOT.'/includes/mike42/escpos-php/Escpos.php';
96 96
 
97 97
 
98 98
 /**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     /**
119 119
      * @var string Error code (or message)
120 120
      */
121
-    public $error='';
121
+    public $error = '';
122 122
 
123 123
     /**
124 124
      * @var string[] Error codes (or messages)
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     function __construct($db)
136 136
     {
137
-        $this->db=$db;
137
+        $this->db = $db;
138 138
         $this->tags = array(
139 139
             'dol_align_left',
140 140
             'dol_align_center',
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
         $line = 0;
219 219
         $obj = array();
220 220
         $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
221
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
222
-        $sql.= ' WHERE entity = '.$conf->entity;
221
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
222
+        $sql .= ' WHERE entity = '.$conf->entity;
223 223
         $resql = $this->db->query($sql);
224 224
         if ($resql) {
225 225
             $num = $this->db->num_rows($resql);
@@ -286,8 +286,8 @@  discard block
 block discarded – undo
286 286
         $line = 0;
287 287
         $obj = array();
288 288
         $sql = 'SELECT rowid, name, template';
289
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
290
-        $sql.= ' WHERE entity = '.$conf->entity;
289
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
290
+        $sql .= ' WHERE entity = '.$conf->entity;
291 291
         $resql = $this->db->query($sql);
292 292
         if ($resql) {
293 293
             $num = $this->db->num_rows($resql);
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
      *  @param    string    $htmlname       select html name
312 312
      *  @return  int                        0 if OK; >0 if KO
313 313
      */
314
-    function selectTypePrinter($selected='', $htmlname='printertypeid')
314
+    function selectTypePrinter($selected = '', $htmlname = 'printertypeid')
315 315
     {
316 316
         global $langs;
317 317
 
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
      *  @param    string    $htmlname       select html name
336 336
      *  @return  int                        0 if OK; >0 if KO
337 337
      */
338
-    function selectProfilePrinter($selected='', $htmlname='printerprofileid')
338
+    function selectProfilePrinter($selected = '', $htmlname = 'printerprofileid')
339 339
     {
340 340
         global $langs;
341 341
 
@@ -368,10 +368,10 @@  discard block
 block discarded – undo
368 368
         global $conf;
369 369
         $error = 0;
370 370
         $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt';
371
-        $sql.= ' (name, fk_type, fk_profile, parameter, entity)';
372
-        $sql.= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')';
371
+        $sql .= ' (name, fk_type, fk_profile, parameter, entity)';
372
+        $sql .= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')';
373 373
         $resql = $this->db->query($sql);
374
-        if (! $resql) {
374
+        if (!$resql) {
375 375
             $error++;
376 376
             $this->errors[] = $this->db->lasterror;
377 377
         }
@@ -395,13 +395,13 @@  discard block
 block discarded – undo
395 395
         global $conf;
396 396
         $error = 0;
397 397
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt';
398
-        $sql.= ' SET name="'.$this->db->escape($name).'"';
399
-        $sql.= ', fk_type='.$type;
400
-        $sql.= ', fk_profile='.$profile;
401
-        $sql.= ', parameter="'.$this->db->escape($parameter).'"';
402
-        $sql.= ' WHERE rowid='.$printerid;
398
+        $sql .= ' SET name="'.$this->db->escape($name).'"';
399
+        $sql .= ', fk_type='.$type;
400
+        $sql .= ', fk_profile='.$profile;
401
+        $sql .= ', parameter="'.$this->db->escape($parameter).'"';
402
+        $sql .= ' WHERE rowid='.$printerid;
403 403
         $resql = $this->db->query($sql);
404
-        if (! $resql) {
404
+        if (!$resql) {
405 405
             $error++;
406 406
             $this->errors[] = $this->db->lasterror;
407 407
         }
@@ -421,9 +421,9 @@  discard block
 block discarded – undo
421 421
         global $conf;
422 422
         $error = 0;
423 423
         $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt';
424
-        $sql.= ' WHERE rowid='.$printerid;
424
+        $sql .= ' WHERE rowid='.$printerid;
425 425
         $resql = $this->db->query($sql);
426
-        if (! $resql) {
426
+        if (!$resql) {
427 427
             $error++;
428 428
             $this->errors[] = $this->db->lasterror;
429 429
         }
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
         global $conf;
446 446
         $error = 0;
447 447
         $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt_template';
448
-        $sql.= ' SET name="'.$this->db->escape($name).'"';
449
-        $sql.= ', template="'.$this->db->escape($template).'"';
450
-        $sql.= ' WHERE rowid='.$templateid;
448
+        $sql .= ' SET name="'.$this->db->escape($name).'"';
449
+        $sql .= ', template="'.$this->db->escape($template).'"';
450
+        $sql .= ' WHERE rowid='.$templateid;
451 451
         $resql = $this->db->query($sql);
452
-        if (! $resql) {
452
+        if (!$resql) {
453 453
             $error++;
454 454
             $this->errors[] = $this->db->lasterror;
455 455
         }
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
         // phpcs:enable
470 470
         global $conf;
471 471
         $error = 0;
472
-        $img = new EscposImage(DOL_BASE_URI . '/theme/common/dolibarr_logo_bw.png');
472
+        $img = new EscposImage(DOL_BASE_URI.'/theme/common/dolibarr_logo_bw.png');
473 473
         $ret = $this->InitPrinter($printerid);
474
-        if ($ret>0) {
474
+        if ($ret > 0) {
475 475
             setEventMessages($this->error, $this->errors, 'errors');
476 476
         } else {
477 477
             try {
@@ -543,35 +543,35 @@  discard block
 block discarded – undo
543 543
         $level = 0;
544 544
         $html = '<table border="1" style="width:210px"><pre>';
545 545
         $ret = $this->InitPrinter($printerid);
546
-        if ($ret>0) {
546
+        if ($ret > 0) {
547 547
             setEventMessages($this->error, $this->errors, 'errors');
548 548
         }
549 549
         else
550 550
         {
551 551
             $nboflines = count($vals);
552
-            for ($line=0; $line < $nboflines; $line++)
552
+            for ($line = 0; $line < $nboflines; $line++)
553 553
             {
554 554
                 switch ($vals[$line]['tag']) {
555 555
                     case 'DOL_ALIGN_CENTER':
556 556
                         $this->printer->setJustification(Escpos::JUSTIFY_CENTER);
557
-                        $html.='<center>';
557
+                        $html .= '<center>';
558 558
                         $this->printer->text($vals[$line]['value']);
559 559
                         break;
560 560
                     case 'DOL_ALIGN_RIGHT':
561 561
                         $this->printer->setJustification(Escpos::JUSTIFY_RIGHT);
562
-                        $html.='<right>';
562
+                        $html .= '<right>';
563 563
                         break;
564 564
                     case 'DOL_ALIGN_LEFT':
565 565
                         $this->printer->setJustification(Escpos::JUSTIFY_LEFT);
566
-                        $html.='<left>';
566
+                        $html .= '<left>';
567 567
                         break;
568 568
                     case 'DOL_OPEN_DRAWER':
569 569
                         $this->printer->pulse();
570
-                        $html.= ' &#991;'.nl2br($vals[$line]['value']);
570
+                        $html .= ' &#991;'.nl2br($vals[$line]['value']);
571 571
                         break;
572 572
                     case 'DOL_ACTIVATE_BUZZER':
573 573
                         //$this->printer->buzzer();
574
-                        $html.= ' &#x266b;'.nl2br($vals[$line]['value']);
574
+                        $html .= ' &#x266b;'.nl2br($vals[$line]['value']);
575 575
                         break;
576 576
                     case 'DOL_PRINT_BARCODE':
577 577
                         // $vals[$line]['value'] -> barcode($content, $type)
@@ -584,15 +584,15 @@  discard block
 block discarded – undo
584 584
                     case 'DOL_PRINT_QRCODE':
585 585
                         // $vals[$line]['value'] -> qrCode($content, $ec, $size, $model)
586 586
                         $this->printer->qrcode($vals[$line]['value']);
587
-                        $html.='QRCODE: '.$vals[$line]['value'];
587
+                        $html .= 'QRCODE: '.$vals[$line]['value'];
588 588
                         break;
589 589
                     case 'DOL_CUT_PAPER_FULL':
590 590
                         $this->printer->cut(Escpos::CUT_FULL);
591
-                        $html.= ' &#9986;'.nl2br($vals[$line]['value']);
591
+                        $html .= ' &#9986;'.nl2br($vals[$line]['value']);
592 592
                         break;
593 593
                     case 'DOL_CUT_PAPER_PARTIAL':
594 594
                         $this->printer->cut(Escpos::CUT_PARTIAL);
595
-                        $html.= ' &#9986;'.nl2br($vals[$line]['value']);
595
+                        $html .= ' &#9986;'.nl2br($vals[$line]['value']);
596 596
                         break;
597 597
                     case 'DOL_USE_FONT_A':
598 598
                         $this->printer->setFont(Escpos::FONT_A);
@@ -608,13 +608,13 @@  discard block
 block discarded – undo
608 608
                         break;
609 609
                     default:
610 610
                         $this->printer->text($vals[$line]['value']);
611
-                        $html.= nl2br($vals[$line]['value']);
611
+                        $html .= nl2br($vals[$line]['value']);
612 612
                         $this->errors[] = 'UnknowTag: &lt;'.strtolower($vals[$line]['tag']).'&gt;';
613 613
                         $error++;
614 614
                         break;
615 615
                 }
616 616
             }
617
-            $html.= '</pre></table>';
617
+            $html .= '</pre></table>';
618 618
             print $html;
619 619
             // Close and print
620 620
             // uncomment next line to see content sent to printer
@@ -635,9 +635,9 @@  discard block
 block discarded – undo
635 635
         global $conf;
636 636
         $error = 0;
637 637
         $sql = 'SELECT template';
638
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
639
-        $sql.= ' WHERE rowid='.$templateid;
640
-        $sql.= ' AND entity = '.$conf->entity;
638
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template';
639
+        $sql .= ' WHERE rowid='.$templateid;
640
+        $sql .= ' AND entity = '.$conf->entity;
641 641
         $resql = $this->db->query($sql);
642 642
         if ($resql) {
643 643
             $obj = $this->db->fetch_array($resql);
@@ -667,11 +667,11 @@  discard block
 block discarded – undo
667 667
     {
668 668
         // phpcs:enable
669 669
         global $conf;
670
-        $error=0;
670
+        $error = 0;
671 671
         $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter';
672
-        $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
673
-        $sql.= ' WHERE rowid = '.$printerid;
674
-        $sql.= ' AND entity = '.$conf->entity;
672
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
673
+        $sql .= ' WHERE rowid = '.$printerid;
674
+        $sql .= ' AND entity = '.$conf->entity;
675 675
         $resql = $this->db->query($sql);
676 676
         if ($resql) {
677 677
             $obj = $this->db->fetch_array($resql);
@@ -683,12 +683,12 @@  discard block
 block discarded – undo
683 683
             $error++;
684 684
             $this->errors[] = 'PrinterDontExist';
685 685
         }
686
-        if (! $error) {
686
+        if (!$error) {
687 687
             $parameter = $obj['parameter'];
688 688
             try {
689 689
                 switch ($obj['fk_type']) {
690 690
                     case 1:
691
-                        require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
691
+                        require_once DOL_DOCUMENT_ROOT.'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
692 692
                         $this->connector = new DummyPrintConnector();
693 693
                         break;
694 694
                     case 2:
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.
dolibarr/htdocs/core/class/fiscalyear.class.php 3 patches
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -28,384 +28,384 @@
 block discarded – undo
28 28
  */
29 29
 class Fiscalyear extends CommonObject
30 30
 {
31
-	/**
32
-	 * @var string ID to identify managed object
33
-	 */
34
-	public $element='fiscalyear';
35
-
36
-	/**
37
-	 * @var string Name of table without prefix where object is stored
38
-	 */
39
-	public $table_element='accounting_fiscalyear';
40
-
41
-	/**
42
-	 * @var int    Name of subtable line
43
-	 */
44
-	public $table_element_line = '';
45
-
46
-	/**
47
-	 * @var int Field with ID of parent key if this field has a parent
48
-	 */
49
-	public $fk_element = '';
50
-
51
-	/**
52
-	 * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
53
-	 * @var int
54
-	 */
55
-	public $ismultientitymanaged = 1;
56
-
57
-	/**
58
-	 * @var int ID
59
-	 */
60
-	public $rowid;
61
-
62
-	/**
63
-	 * @var string fiscal year label
64
-	 */
65
-	public $label;
66
-
67
-	public $date_start;
68
-	public $date_end;
69
-	public $datec;
70
-	public $statut;		// 0=open, 1=closed
71
-
72
-	/**
73
-	 * @var int Entity
74
-	 */
75
-	public $entity;
76
-
77
-	public $statuts=array();
78
-	public $statuts_short=array();
79
-
80
-	/**
81
-	 * Constructor
82
-	 *
83
-	 * @param	DoliDB		$db		Database handler
84
-	 */
85
-	function __construct(DoliDB $db)
86
-	{
87
-		global $langs;
88
-
89
-		$this->db = $db;
90
-
91
-		$this->statuts_short = array(0 => 'Opened', 1 => 'Closed');
92
-		$this->statuts = array(0 => 'Opened', 1 => 'Closed');
93
-	}
94
-
95
-	/**
96
-	 *	Create object in database
97
-	 *
98
-	 *	@param		User	$user   User making creation
99
-	 *	@return 	int				<0 if KO, >0 if OK
100
-	 */
101
-	function create($user)
102
-	{
103
-		global $conf;
104
-
105
-		$error = 0;
106
-
107
-		$now=dol_now();
108
-
109
-		$this->db->begin();
110
-
111
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear (";
112
-		$sql.= "label";
113
-		$sql.= ", date_start";
114
-		$sql.= ", date_end";
115
-		$sql.= ", statut";
116
-		$sql.= ", entity";
117
-		$sql.= ", datec";
118
-		$sql.= ", fk_user_author";
119
-		$sql.= ") VALUES (";
120
-		$sql.= " '".$this->db->escape($this->label)."'";
121
-		$sql.= ", '".$this->db->idate($this->date_start)."'";
122
-		$sql.= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'":"null");
123
-		$sql.= ", 0";
124
-		$sql.= ", ".$conf->entity;
125
-		$sql.= ", '".$this->db->idate($now)."'";
126
-		$sql.= ", ". $user->id;
127
-		$sql.= ")";
128
-
129
-		dol_syslog(get_class($this)."::create", LOG_DEBUG);
130
-		$result = $this->db->query($sql);
131
-		if ($result)
132
-		{
133
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear");
134
-
135
-			$result=$this->update($user);
136
-			if ($result > 0)
137
-			{
138
-				$this->db->commit();
139
-				return $this->id;
140
-			}
141
-			else
142
-			{
143
-				$this->error=$this->db->lasterror();
144
-				$this->db->rollback();
145
-				return $result;
146
-			}
147
-		}
148
-		else
149
-		{
150
-			$this->error=$this->db->lasterror()." sql=".$sql;
151
-			$this->db->rollback();
152
-			return -1;
153
-		}
154
-	}
155
-
156
-	/**
157
-	 *	Update record
158
-	 *
159
-	 *	@param	User	$user		User making update
160
-	 *	@return	int					<0 if KO, >0 if OK
161
-	 */
162
-	function update($user)
163
-	{
164
-		global $langs;
165
-
166
-		// Check parameters
167
-		if (empty($this->date_start) && empty($this->date_end))
168
-		{
169
-			$this->error='ErrorBadParameter';
170
-			return -1;
171
-		}
172
-
173
-		$this->db->begin();
174
-
175
-		$sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear";
176
-		$sql .= " SET label = '".$this->db->escape($this->label)."'";
177
-		$sql .= ", date_start = '".$this->db->idate($this->date_start)."'";
178
-		$sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null");
179
-		$sql .= ", statut = '".$this->db->escape($this->statut?$this->statut:0)."'";
180
-		$sql .= ", datec = " . ($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null');
181
-		$sql .= ", fk_user_modif = " . $user->id;
182
-		$sql .= " WHERE rowid = ".$this->id;
183
-
184
-		dol_syslog(get_class($this)."::update", LOG_DEBUG);
185
-		$result = $this->db->query($sql);
186
-		if ($result)
187
-		{
188
-			$this->db->commit();
189
-			return 1;
190
-		}
191
-		else
192
-		{
193
-			$this->error=$this->db->lasterror();
194
-			dol_syslog($this->error, LOG_ERR);
195
-			$this->db->rollback();
196
-			return -1;
197
-		}
198
-	}
199
-
200
-	/**
201
-	* Load an object from database
202
-	*
203
-	* @param	int		$id		Id of record to load
204
-	* @return	int				<0 if KO, >0 if OK
205
-	*/
206
-	function fetch($id)
207
-	{
208
-		$sql = "SELECT rowid, label, date_start, date_end, statut";
209
-		$sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
210
-		$sql.= " WHERE rowid = ".$id;
211
-
212
-		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
213
-		$result = $this->db->query($sql);
214
-		if ( $result )
215
-		{
216
-			$obj = $this->db->fetch_object($result);
217
-
218
-			$this->id			= $obj->rowid;
219
-			$this->ref			= $obj->rowid;
220
-			$this->date_start	= $this->db->jdate($obj->date_start);
221
-			$this->date_end		= $this->db->jdate($obj->date_end);
222
-			$this->label		= $obj->label;
223
-			$this->statut	    = $obj->statut;
224
-
225
-			return 1;
226
-		}
227
-		else
228
-		{
229
-			$this->error=$this->db->lasterror();
230
-			return -1;
231
-		}
232
-	}
233
-
234
-   /**
235
-	*	Delete record
236
-	*
237
-	*	@param	int		$id		Id of record to delete
238
-	*	@return	int				<0 if KO, >0 if OK
239
-	*/
240
-	function delete($id)
241
-	{
242
-		$this->db->begin();
243
-
244
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".$id;
245
-
246
-		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
247
-		$result = $this->db->query($sql);
248
-		if ($result)
249
-		{
250
-			$this->db->commit();
251
-			return 1;
252
-		}
253
-		else
254
-		{
255
-			$this->error=$this->db->lasterror();
256
-			$this->db->rollback();
257
-			return -1;
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * Give a label from a status
263
-	 *
264
-	 * @param	int		$mode   	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
265
-	 * @return  string   		   	Label
266
-	 */
267
-	function getLibStatut($mode=0)
268
-	{
269
-		return $this->LibStatut($this->statut,$mode);
270
-	}
271
-
272
-	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
273
-	/**
274
-	 *  Give a label from a status
275
-	 *
276
-	 *  @param	int		$statut     Id status
277
-	 *  @param  int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
278
-	 *  @return string      		Label
279
-	 */
280
-	function LibStatut($statut,$mode=0)
281
-	{
282
-		// phpcs:enable
283
-		global $langs;
284
-
285
-		if ($mode == 0)
286
-		{
287
-			return $langs->trans($this->statuts[$statut]);
288
-		}
289
-		elseif ($mode == 1)
290
-		{
291
-			return $langs->trans($this->statuts_short[$statut]);
292
-		}
293
-		elseif ($mode == 2)
294
-		{
295
-			if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
296
-			elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]);
297
-		}
298
-		elseif ($mode == 3)
299
-		{
300
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
301
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
302
-		}
303
-		elseif ($mode == 4)
304
-		{
305
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
306
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]);
307
-		}
308
-		elseif ($mode == 5)
309
-		{
310
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
311
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
312
-		}
313
-	}
314
-
315
-	/**
316
-	 * Information on record
317
-	 *
318
-	 * @param	int		$id      Id of record
319
-	 * @return	void
320
-	 */
321
-	function info($id)
322
-	{
323
-		$sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,';
324
-		$sql.= ' fy.tms';
325
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy';
326
-		$sql.= ' WHERE fy.rowid = '.$id;
327
-
328
-		dol_syslog(get_class($this)."::fetch info", LOG_DEBUG);
329
-		$result = $this->db->query($sql);
330
-
331
-		if ($result)
332
-		{
333
-			if ($this->db->num_rows($result))
334
-			{
335
-				$obj = $this->db->fetch_object($result);
336
-				$this->id = $obj->rowid;
337
-				if ($obj->fk_user_author)
338
-				{
339
-					$cuser = new User($this->db);
340
-					$cuser->fetch($obj->fk_user_author);
341
-					$this->user_creation = $cuser;
342
-				}
343
-				if ($obj->fk_user_modif)
344
-				{
345
-					$muser = new User($this->db);
346
-					$muser->fetch($obj->fk_user_modif);
347
-					$this->user_modification = $muser;
348
-				}
349
-				$this->date_creation     = $this->db->jdate($obj->datec);
350
-				$this->date_modification = $this->db->jdate($obj->tms);
351
-			}
352
-			$this->db->free($result);
353
-		}
354
-		else
355
-		{
356
-			dol_print_error($this->db);
357
-		}
358
-	}
359
-
360
-	/**
361
-	 *  Return the number of entries by fiscal year
362
-	 *
363
-	 *	@param	int		$datestart	Date start to scan
364
-	 *	@param	int		$dateend	Date end to scan
365
-	 *	@return	string				Number of entries
366
-	 */
367
-	function getAccountancyEntriesByFiscalYear($datestart, $dateend)
368
-	{
369
-		global $conf;
370
-
371
-		$sql = "SELECT count(DISTINCT piece_num) as nb";
372
-		$sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
373
-		$sql.= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'";
374
-
375
-		$resql=$this->db->query($sql);
376
-		if ($resql)
377
-		{
378
-			$obj = $this->db->fetch_object($resql);
379
-			$nb = $obj->nb;
380
-		}
381
-		else dol_print_error($this->db);
382
-
383
-		return $nb;
384
-	}
385
-
386
-	/**
387
-	 *  Return the number of movements by fiscal year
388
-	 *
389
-	 *	@param	int		$datestart	Date start to scan
390
-	 *	@param	int		$dateend	Date end to scan
391
-	 *	@return	string				Number of movements
392
-	 */
393
-	function getAccountancyMovementsByFiscalYear($datestart, $dateend)
394
-	{
395
-		global $conf;
396
-
397
-		$sql = "SELECT count(rowid) as nb";
398
-		$sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
399
-		$sql.= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'";
400
-
401
-		$resql=$this->db->query($sql);
402
-		if ($resql)
403
-		{
404
-			$obj = $this->db->fetch_object($resql);
405
-			$nb = $obj->nb;
406
-		}
407
-		else dol_print_error($this->db);
408
-
409
-		return $nb;
410
-	}
31
+    /**
32
+     * @var string ID to identify managed object
33
+     */
34
+    public $element='fiscalyear';
35
+
36
+    /**
37
+     * @var string Name of table without prefix where object is stored
38
+     */
39
+    public $table_element='accounting_fiscalyear';
40
+
41
+    /**
42
+     * @var int    Name of subtable line
43
+     */
44
+    public $table_element_line = '';
45
+
46
+    /**
47
+     * @var int Field with ID of parent key if this field has a parent
48
+     */
49
+    public $fk_element = '';
50
+
51
+    /**
52
+     * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
53
+     * @var int
54
+     */
55
+    public $ismultientitymanaged = 1;
56
+
57
+    /**
58
+     * @var int ID
59
+     */
60
+    public $rowid;
61
+
62
+    /**
63
+     * @var string fiscal year label
64
+     */
65
+    public $label;
66
+
67
+    public $date_start;
68
+    public $date_end;
69
+    public $datec;
70
+    public $statut;		// 0=open, 1=closed
71
+
72
+    /**
73
+     * @var int Entity
74
+     */
75
+    public $entity;
76
+
77
+    public $statuts=array();
78
+    public $statuts_short=array();
79
+
80
+    /**
81
+     * Constructor
82
+     *
83
+     * @param	DoliDB		$db		Database handler
84
+     */
85
+    function __construct(DoliDB $db)
86
+    {
87
+        global $langs;
88
+
89
+        $this->db = $db;
90
+
91
+        $this->statuts_short = array(0 => 'Opened', 1 => 'Closed');
92
+        $this->statuts = array(0 => 'Opened', 1 => 'Closed');
93
+    }
94
+
95
+    /**
96
+     *	Create object in database
97
+     *
98
+     *	@param		User	$user   User making creation
99
+     *	@return 	int				<0 if KO, >0 if OK
100
+     */
101
+    function create($user)
102
+    {
103
+        global $conf;
104
+
105
+        $error = 0;
106
+
107
+        $now=dol_now();
108
+
109
+        $this->db->begin();
110
+
111
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear (";
112
+        $sql.= "label";
113
+        $sql.= ", date_start";
114
+        $sql.= ", date_end";
115
+        $sql.= ", statut";
116
+        $sql.= ", entity";
117
+        $sql.= ", datec";
118
+        $sql.= ", fk_user_author";
119
+        $sql.= ") VALUES (";
120
+        $sql.= " '".$this->db->escape($this->label)."'";
121
+        $sql.= ", '".$this->db->idate($this->date_start)."'";
122
+        $sql.= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'":"null");
123
+        $sql.= ", 0";
124
+        $sql.= ", ".$conf->entity;
125
+        $sql.= ", '".$this->db->idate($now)."'";
126
+        $sql.= ", ". $user->id;
127
+        $sql.= ")";
128
+
129
+        dol_syslog(get_class($this)."::create", LOG_DEBUG);
130
+        $result = $this->db->query($sql);
131
+        if ($result)
132
+        {
133
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear");
134
+
135
+            $result=$this->update($user);
136
+            if ($result > 0)
137
+            {
138
+                $this->db->commit();
139
+                return $this->id;
140
+            }
141
+            else
142
+            {
143
+                $this->error=$this->db->lasterror();
144
+                $this->db->rollback();
145
+                return $result;
146
+            }
147
+        }
148
+        else
149
+        {
150
+            $this->error=$this->db->lasterror()." sql=".$sql;
151
+            $this->db->rollback();
152
+            return -1;
153
+        }
154
+    }
155
+
156
+    /**
157
+     *	Update record
158
+     *
159
+     *	@param	User	$user		User making update
160
+     *	@return	int					<0 if KO, >0 if OK
161
+     */
162
+    function update($user)
163
+    {
164
+        global $langs;
165
+
166
+        // Check parameters
167
+        if (empty($this->date_start) && empty($this->date_end))
168
+        {
169
+            $this->error='ErrorBadParameter';
170
+            return -1;
171
+        }
172
+
173
+        $this->db->begin();
174
+
175
+        $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear";
176
+        $sql .= " SET label = '".$this->db->escape($this->label)."'";
177
+        $sql .= ", date_start = '".$this->db->idate($this->date_start)."'";
178
+        $sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null");
179
+        $sql .= ", statut = '".$this->db->escape($this->statut?$this->statut:0)."'";
180
+        $sql .= ", datec = " . ($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null');
181
+        $sql .= ", fk_user_modif = " . $user->id;
182
+        $sql .= " WHERE rowid = ".$this->id;
183
+
184
+        dol_syslog(get_class($this)."::update", LOG_DEBUG);
185
+        $result = $this->db->query($sql);
186
+        if ($result)
187
+        {
188
+            $this->db->commit();
189
+            return 1;
190
+        }
191
+        else
192
+        {
193
+            $this->error=$this->db->lasterror();
194
+            dol_syslog($this->error, LOG_ERR);
195
+            $this->db->rollback();
196
+            return -1;
197
+        }
198
+    }
199
+
200
+    /**
201
+     * Load an object from database
202
+     *
203
+     * @param	int		$id		Id of record to load
204
+     * @return	int				<0 if KO, >0 if OK
205
+     */
206
+    function fetch($id)
207
+    {
208
+        $sql = "SELECT rowid, label, date_start, date_end, statut";
209
+        $sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
210
+        $sql.= " WHERE rowid = ".$id;
211
+
212
+        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
213
+        $result = $this->db->query($sql);
214
+        if ( $result )
215
+        {
216
+            $obj = $this->db->fetch_object($result);
217
+
218
+            $this->id			= $obj->rowid;
219
+            $this->ref			= $obj->rowid;
220
+            $this->date_start	= $this->db->jdate($obj->date_start);
221
+            $this->date_end		= $this->db->jdate($obj->date_end);
222
+            $this->label		= $obj->label;
223
+            $this->statut	    = $obj->statut;
224
+
225
+            return 1;
226
+        }
227
+        else
228
+        {
229
+            $this->error=$this->db->lasterror();
230
+            return -1;
231
+        }
232
+    }
233
+
234
+    /**
235
+     *	Delete record
236
+     *
237
+     *	@param	int		$id		Id of record to delete
238
+     *	@return	int				<0 if KO, >0 if OK
239
+     */
240
+    function delete($id)
241
+    {
242
+        $this->db->begin();
243
+
244
+        $sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".$id;
245
+
246
+        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
247
+        $result = $this->db->query($sql);
248
+        if ($result)
249
+        {
250
+            $this->db->commit();
251
+            return 1;
252
+        }
253
+        else
254
+        {
255
+            $this->error=$this->db->lasterror();
256
+            $this->db->rollback();
257
+            return -1;
258
+        }
259
+    }
260
+
261
+    /**
262
+     * Give a label from a status
263
+     *
264
+     * @param	int		$mode   	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
265
+     * @return  string   		   	Label
266
+     */
267
+    function getLibStatut($mode=0)
268
+    {
269
+        return $this->LibStatut($this->statut,$mode);
270
+    }
271
+
272
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
273
+    /**
274
+     *  Give a label from a status
275
+     *
276
+     *  @param	int		$statut     Id status
277
+     *  @param  int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
278
+     *  @return string      		Label
279
+     */
280
+    function LibStatut($statut,$mode=0)
281
+    {
282
+        // phpcs:enable
283
+        global $langs;
284
+
285
+        if ($mode == 0)
286
+        {
287
+            return $langs->trans($this->statuts[$statut]);
288
+        }
289
+        elseif ($mode == 1)
290
+        {
291
+            return $langs->trans($this->statuts_short[$statut]);
292
+        }
293
+        elseif ($mode == 2)
294
+        {
295
+            if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
296
+            elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]);
297
+        }
298
+        elseif ($mode == 3)
299
+        {
300
+            if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
301
+            elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
302
+        }
303
+        elseif ($mode == 4)
304
+        {
305
+            if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
306
+            elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]);
307
+        }
308
+        elseif ($mode == 5)
309
+        {
310
+            if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
311
+            elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
312
+        }
313
+    }
314
+
315
+    /**
316
+     * Information on record
317
+     *
318
+     * @param	int		$id      Id of record
319
+     * @return	void
320
+     */
321
+    function info($id)
322
+    {
323
+        $sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,';
324
+        $sql.= ' fy.tms';
325
+        $sql.= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy';
326
+        $sql.= ' WHERE fy.rowid = '.$id;
327
+
328
+        dol_syslog(get_class($this)."::fetch info", LOG_DEBUG);
329
+        $result = $this->db->query($sql);
330
+
331
+        if ($result)
332
+        {
333
+            if ($this->db->num_rows($result))
334
+            {
335
+                $obj = $this->db->fetch_object($result);
336
+                $this->id = $obj->rowid;
337
+                if ($obj->fk_user_author)
338
+                {
339
+                    $cuser = new User($this->db);
340
+                    $cuser->fetch($obj->fk_user_author);
341
+                    $this->user_creation = $cuser;
342
+                }
343
+                if ($obj->fk_user_modif)
344
+                {
345
+                    $muser = new User($this->db);
346
+                    $muser->fetch($obj->fk_user_modif);
347
+                    $this->user_modification = $muser;
348
+                }
349
+                $this->date_creation     = $this->db->jdate($obj->datec);
350
+                $this->date_modification = $this->db->jdate($obj->tms);
351
+            }
352
+            $this->db->free($result);
353
+        }
354
+        else
355
+        {
356
+            dol_print_error($this->db);
357
+        }
358
+    }
359
+
360
+    /**
361
+     *  Return the number of entries by fiscal year
362
+     *
363
+     *	@param	int		$datestart	Date start to scan
364
+     *	@param	int		$dateend	Date end to scan
365
+     *	@return	string				Number of entries
366
+     */
367
+    function getAccountancyEntriesByFiscalYear($datestart, $dateend)
368
+    {
369
+        global $conf;
370
+
371
+        $sql = "SELECT count(DISTINCT piece_num) as nb";
372
+        $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
373
+        $sql.= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'";
374
+
375
+        $resql=$this->db->query($sql);
376
+        if ($resql)
377
+        {
378
+            $obj = $this->db->fetch_object($resql);
379
+            $nb = $obj->nb;
380
+        }
381
+        else dol_print_error($this->db);
382
+
383
+        return $nb;
384
+    }
385
+
386
+    /**
387
+     *  Return the number of movements by fiscal year
388
+     *
389
+     *	@param	int		$datestart	Date start to scan
390
+     *	@param	int		$dateend	Date end to scan
391
+     *	@return	string				Number of movements
392
+     */
393
+    function getAccountancyMovementsByFiscalYear($datestart, $dateend)
394
+    {
395
+        global $conf;
396
+
397
+        $sql = "SELECT count(rowid) as nb";
398
+        $sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
399
+        $sql.= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'";
400
+
401
+        $resql=$this->db->query($sql);
402
+        if ($resql)
403
+        {
404
+            $obj = $this->db->fetch_object($resql);
405
+            $nb = $obj->nb;
406
+        }
407
+        else dol_print_error($this->db);
408
+
409
+        return $nb;
410
+    }
411 411
 }
Please login to merge, or discard this patch.
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
  *		\brief      File of class to manage fiscal years
22 22
  */
23 23
 
24
-require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
24
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
25 25
 
26 26
 /**
27 27
  * Class to manage fiscal year
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
 	/**
32 32
 	 * @var string ID to identify managed object
33 33
 	 */
34
-	public $element='fiscalyear';
34
+	public $element = 'fiscalyear';
35 35
 
36 36
 	/**
37 37
 	 * @var string Name of table without prefix where object is stored
38 38
 	 */
39
-	public $table_element='accounting_fiscalyear';
39
+	public $table_element = 'accounting_fiscalyear';
40 40
 
41 41
 	/**
42 42
 	 * @var int    Name of subtable line
@@ -67,15 +67,15 @@  discard block
 block discarded – undo
67 67
 	public $date_start;
68 68
 	public $date_end;
69 69
 	public $datec;
70
-	public $statut;		// 0=open, 1=closed
70
+	public $statut; // 0=open, 1=closed
71 71
 
72 72
 	/**
73 73
 	 * @var int Entity
74 74
 	 */
75 75
 	public $entity;
76 76
 
77
-	public $statuts=array();
78
-	public $statuts_short=array();
77
+	public $statuts = array();
78
+	public $statuts_short = array();
79 79
 
80 80
 	/**
81 81
 	 * Constructor
@@ -104,27 +104,27 @@  discard block
 block discarded – undo
104 104
 
105 105
 		$error = 0;
106 106
 
107
-		$now=dol_now();
107
+		$now = dol_now();
108 108
 
109 109
 		$this->db->begin();
110 110
 
111 111
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear (";
112
-		$sql.= "label";
113
-		$sql.= ", date_start";
114
-		$sql.= ", date_end";
115
-		$sql.= ", statut";
116
-		$sql.= ", entity";
117
-		$sql.= ", datec";
118
-		$sql.= ", fk_user_author";
119
-		$sql.= ") VALUES (";
120
-		$sql.= " '".$this->db->escape($this->label)."'";
121
-		$sql.= ", '".$this->db->idate($this->date_start)."'";
122
-		$sql.= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'":"null");
123
-		$sql.= ", 0";
124
-		$sql.= ", ".$conf->entity;
125
-		$sql.= ", '".$this->db->idate($now)."'";
126
-		$sql.= ", ". $user->id;
127
-		$sql.= ")";
112
+		$sql .= "label";
113
+		$sql .= ", date_start";
114
+		$sql .= ", date_end";
115
+		$sql .= ", statut";
116
+		$sql .= ", entity";
117
+		$sql .= ", datec";
118
+		$sql .= ", fk_user_author";
119
+		$sql .= ") VALUES (";
120
+		$sql .= " '".$this->db->escape($this->label)."'";
121
+		$sql .= ", '".$this->db->idate($this->date_start)."'";
122
+		$sql .= ", ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null");
123
+		$sql .= ", 0";
124
+		$sql .= ", ".$conf->entity;
125
+		$sql .= ", '".$this->db->idate($now)."'";
126
+		$sql .= ", ".$user->id;
127
+		$sql .= ")";
128 128
 
129 129
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
130 130
 		$result = $this->db->query($sql);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 		{
133 133
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear");
134 134
 
135
-			$result=$this->update($user);
135
+			$result = $this->update($user);
136 136
 			if ($result > 0)
137 137
 			{
138 138
 				$this->db->commit();
@@ -140,14 +140,14 @@  discard block
 block discarded – undo
140 140
 			}
141 141
 			else
142 142
 			{
143
-				$this->error=$this->db->lasterror();
143
+				$this->error = $this->db->lasterror();
144 144
 				$this->db->rollback();
145 145
 				return $result;
146 146
 			}
147 147
 		}
148 148
 		else
149 149
 		{
150
-			$this->error=$this->db->lasterror()." sql=".$sql;
150
+			$this->error = $this->db->lasterror()." sql=".$sql;
151 151
 			$this->db->rollback();
152 152
 			return -1;
153 153
 		}
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 		// Check parameters
167 167
 		if (empty($this->date_start) && empty($this->date_end))
168 168
 		{
169
-			$this->error='ErrorBadParameter';
169
+			$this->error = 'ErrorBadParameter';
170 170
 			return -1;
171 171
 		}
172 172
 
@@ -176,9 +176,9 @@  discard block
 block discarded – undo
176 176
 		$sql .= " SET label = '".$this->db->escape($this->label)."'";
177 177
 		$sql .= ", date_start = '".$this->db->idate($this->date_start)."'";
178 178
 		$sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null");
179
-		$sql .= ", statut = '".$this->db->escape($this->statut?$this->statut:0)."'";
180
-		$sql .= ", datec = " . ($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null');
181
-		$sql .= ", fk_user_modif = " . $user->id;
179
+		$sql .= ", statut = '".$this->db->escape($this->statut ? $this->statut : 0)."'";
180
+		$sql .= ", datec = ".($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null');
181
+		$sql .= ", fk_user_modif = ".$user->id;
182 182
 		$sql .= " WHERE rowid = ".$this->id;
183 183
 
184 184
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 		}
191 191
 		else
192 192
 		{
193
-			$this->error=$this->db->lasterror();
193
+			$this->error = $this->db->lasterror();
194 194
 			dol_syslog($this->error, LOG_ERR);
195 195
 			$this->db->rollback();
196 196
 			return -1;
@@ -206,27 +206,27 @@  discard block
 block discarded – undo
206 206
 	function fetch($id)
207 207
 	{
208 208
 		$sql = "SELECT rowid, label, date_start, date_end, statut";
209
-		$sql.= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
210
-		$sql.= " WHERE rowid = ".$id;
209
+		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear";
210
+		$sql .= " WHERE rowid = ".$id;
211 211
 
212 212
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
213 213
 		$result = $this->db->query($sql);
214
-		if ( $result )
214
+		if ($result)
215 215
 		{
216 216
 			$obj = $this->db->fetch_object($result);
217 217
 
218
-			$this->id			= $obj->rowid;
219
-			$this->ref			= $obj->rowid;
218
+			$this->id = $obj->rowid;
219
+			$this->ref = $obj->rowid;
220 220
 			$this->date_start	= $this->db->jdate($obj->date_start);
221
-			$this->date_end		= $this->db->jdate($obj->date_end);
222
-			$this->label		= $obj->label;
221
+			$this->date_end = $this->db->jdate($obj->date_end);
222
+			$this->label = $obj->label;
223 223
 			$this->statut	    = $obj->statut;
224 224
 
225 225
 			return 1;
226 226
 		}
227 227
 		else
228 228
 		{
229
-			$this->error=$this->db->lasterror();
229
+			$this->error = $this->db->lasterror();
230 230
 			return -1;
231 231
 		}
232 232
 	}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 		}
253 253
 		else
254 254
 		{
255
-			$this->error=$this->db->lasterror();
255
+			$this->error = $this->db->lasterror();
256 256
 			$this->db->rollback();
257 257
 			return -1;
258 258
 		}
@@ -264,9 +264,9 @@  discard block
 block discarded – undo
264 264
 	 * @param	int		$mode   	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
265 265
 	 * @return  string   		   	Label
266 266
 	 */
267
-	function getLibStatut($mode=0)
267
+	function getLibStatut($mode = 0)
268 268
 	{
269
-		return $this->LibStatut($this->statut,$mode);
269
+		return $this->LibStatut($this->statut, $mode);
270 270
 	}
271 271
 
272 272
 	// phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
 	 *  @param  int		$mode       0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
278 278
 	 *  @return string      		Label
279 279
 	 */
280
-	function LibStatut($statut,$mode=0)
280
+	function LibStatut($statut, $mode = 0)
281 281
 	{
282 282
 		// phpcs:enable
283 283
 		global $langs;
@@ -292,23 +292,23 @@  discard block
 block discarded – undo
292 292
 		}
293 293
 		elseif ($mode == 2)
294 294
 		{
295
-			if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
296
-			elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]);
295
+			if ($statut == 0) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4').' '.$langs->trans($this->statuts_short[$statut]);
296
+			elseif ($statut == 1) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut8').' '.$langs->trans($this->statuts_short[$statut]);
297 297
 		}
298 298
 		elseif ($mode == 3)
299 299
 		{
300
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
301
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
300
+			if ($statut == 0 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4');
301
+			elseif ($statut == 1 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut8');
302 302
 		}
303 303
 		elseif ($mode == 4)
304 304
 		{
305
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
306
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]);
305
+			if ($statut == 0 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut4').' '.$langs->trans($this->statuts[$statut]);
306
+			elseif ($statut == 1 && !empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]), 'statut8').' '.$langs->trans($this->statuts[$statut]);
307 307
 		}
308 308
 		elseif ($mode == 5)
309 309
 		{
310
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
311
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
310
+			if ($statut == 0 && !empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut4');
311
+			elseif ($statut == 1 && !empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]), 'statut6');
312 312
 		}
313 313
 	}
314 314
 
@@ -321,9 +321,9 @@  discard block
 block discarded – undo
321 321
 	function info($id)
322 322
 	{
323 323
 		$sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,';
324
-		$sql.= ' fy.tms';
325
-		$sql.= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy';
326
-		$sql.= ' WHERE fy.rowid = '.$id;
324
+		$sql .= ' fy.tms';
325
+		$sql .= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy';
326
+		$sql .= ' WHERE fy.rowid = '.$id;
327 327
 
328 328
 		dol_syslog(get_class($this)."::fetch info", LOG_DEBUG);
329 329
 		$result = $this->db->query($sql);
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
 		global $conf;
370 370
 
371 371
 		$sql = "SELECT count(DISTINCT piece_num) as nb";
372
-		$sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
373
-		$sql.= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'";
372
+		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
373
+		$sql .= " WHERE doc_date >= '".$datestart."' and doc_date <= '".$dateend."'";
374 374
 
375
-		$resql=$this->db->query($sql);
375
+		$resql = $this->db->query($sql);
376 376
 		if ($resql)
377 377
 		{
378 378
 			$obj = $this->db->fetch_object($resql);
@@ -395,10 +395,10 @@  discard block
 block discarded – undo
395 395
 		global $conf;
396 396
 
397 397
 		$sql = "SELECT count(rowid) as nb";
398
-		$sql.= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
399
-		$sql.= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'";
398
+		$sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping ";
399
+		$sql .= " WHERE doc_date >= '".$datestart."' AND doc_date <= '".$dateend."'";
400 400
 
401
-		$resql=$this->db->query($sql);
401
+		$resql = $this->db->query($sql);
402 402
 		if ($resql)
403 403
 		{
404 404
 			$obj = $this->db->fetch_object($resql);
Please login to merge, or discard this patch.
Braces   +35 added lines, -32 removed lines patch added patch discarded remove patch
@@ -137,15 +137,13 @@  discard block
 block discarded – undo
137 137
 			{
138 138
 				$this->db->commit();
139 139
 				return $this->id;
140
-			}
141
-			else
140
+			} else
142 141
 			{
143 142
 				$this->error=$this->db->lasterror();
144 143
 				$this->db->rollback();
145 144
 				return $result;
146 145
 			}
147
-		}
148
-		else
146
+		} else
149 147
 		{
150 148
 			$this->error=$this->db->lasterror()." sql=".$sql;
151 149
 			$this->db->rollback();
@@ -187,8 +185,7 @@  discard block
 block discarded – undo
187 185
 		{
188 186
 			$this->db->commit();
189 187
 			return 1;
190
-		}
191
-		else
188
+		} else
192 189
 		{
193 190
 			$this->error=$this->db->lasterror();
194 191
 			dol_syslog($this->error, LOG_ERR);
@@ -223,8 +220,7 @@  discard block
 block discarded – undo
223 220
 			$this->statut	    = $obj->statut;
224 221
 
225 222
 			return 1;
226
-		}
227
-		else
223
+		} else
228 224
 		{
229 225
 			$this->error=$this->db->lasterror();
230 226
 			return -1;
@@ -249,8 +245,7 @@  discard block
 block discarded – undo
249 245
 		{
250 246
 			$this->db->commit();
251 247
 			return 1;
252
-		}
253
-		else
248
+		} else
254 249
 		{
255 250
 			$this->error=$this->db->lasterror();
256 251
 			$this->db->rollback();
@@ -285,30 +280,37 @@  discard block
 block discarded – undo
285 280
 		if ($mode == 0)
286 281
 		{
287 282
 			return $langs->trans($this->statuts[$statut]);
288
-		}
289
-		elseif ($mode == 1)
283
+		} elseif ($mode == 1)
290 284
 		{
291 285
 			return $langs->trans($this->statuts_short[$statut]);
292
-		}
293
-		elseif ($mode == 2)
286
+		} elseif ($mode == 2)
294 287
 		{
295
-			if ($statut==0) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
296
-			elseif ($statut==1) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]);
297
-		}
298
-		elseif ($mode == 3)
288
+			if ($statut==0) {
289
+			    return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts_short[$statut]);
290
+			} elseif ($statut==1) {
291
+			    return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts_short[$statut]);
292
+			}
293
+		} elseif ($mode == 3)
299 294
 		{
300
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
301
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
302
-		}
303
-		elseif ($mode == 4)
295
+			if ($statut==0 && ! empty($this->statuts_short[$statut])) {
296
+			    return img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
297
+			} elseif ($statut==1 && ! empty($this->statuts_short[$statut])) {
298
+			    return img_picto($langs->trans($this->statuts_short[$statut]),'statut8');
299
+			}
300
+		} elseif ($mode == 4)
304 301
 		{
305
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
306
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]);
307
-		}
308
-		elseif ($mode == 5)
302
+			if ($statut==0 && ! empty($this->statuts_short[$statut])) {
303
+			    return img_picto($langs->trans($this->statuts_short[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]);
304
+			} elseif ($statut==1 && ! empty($this->statuts_short[$statut])) {
305
+			    return img_picto($langs->trans($this->statuts_short[$statut]),'statut8').' '.$langs->trans($this->statuts[$statut]);
306
+			}
307
+		} elseif ($mode == 5)
309 308
 		{
310
-			if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
311
-			elseif ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
309
+			if ($statut==0 && ! empty($this->statuts_short[$statut])) {
310
+			    return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4');
311
+			} elseif ($statut==1 && ! empty($this->statuts_short[$statut])) {
312
+			    return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6');
313
+			}
312 314
 		}
313 315
 	}
314 316
 
@@ -350,8 +352,7 @@  discard block
 block discarded – undo
350 352
 				$this->date_modification = $this->db->jdate($obj->tms);
351 353
 			}
352 354
 			$this->db->free($result);
353
-		}
354
-		else
355
+		} else
355 356
 		{
356 357
 			dol_print_error($this->db);
357 358
 		}
@@ -377,8 +378,9 @@  discard block
 block discarded – undo
377 378
 		{
378 379
 			$obj = $this->db->fetch_object($resql);
379 380
 			$nb = $obj->nb;
381
+		} else {
382
+		    dol_print_error($this->db);
380 383
 		}
381
-		else dol_print_error($this->db);
382 384
 
383 385
 		return $nb;
384 386
 	}
@@ -403,8 +405,9 @@  discard block
 block discarded – undo
403 405
 		{
404 406
 			$obj = $this->db->fetch_object($resql);
405 407
 			$nb = $obj->nb;
408
+		} else {
409
+		    dol_print_error($this->db);
406 410
 		}
407
-		else dol_print_error($this->db);
408 411
 
409 412
 		return $nb;
410 413
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/ctypent.class.php 3 patches
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -27,33 +27,33 @@  discard block
 block discarded – undo
27 27
  */
28 28
 class Ctypent // extends CommonObject
29 29
 {
30
-	/**
30
+    /**
31 31
      * @var DoliDB Database handler.
32 32
      */
33 33
     public $db;
34 34
 
35
-	/**
36
-	 * @var string Error code (or message)
37
-	 */
38
-	public $error='';
35
+    /**
36
+     * @var string Error code (or message)
37
+     */
38
+    public $error='';
39 39
 
40
-	/**
41
-	 * @var string[] Error codes (or messages)
42
-	 */
43
-	public $errors = array();
40
+    /**
41
+     * @var string[] Error codes (or messages)
42
+     */
43
+    public $errors = array();
44 44
 
45
-	//var $element='ctypent';			//!< Id that identify managed objects
46
-	//var $table_element='ctypent';	//!< Name of table without prefix where object is stored
45
+    //var $element='ctypent';			//!< Id that identify managed objects
46
+    //var $table_element='ctypent';	//!< Name of table without prefix where object is stored
47 47
 
48 48
     /**
49
-	 * @var int ID
50
-	 */
51
-	public $id;
49
+     * @var int ID
50
+     */
51
+    public $id;
52 52
 
53
-	public $code;
54
-	public $libelle;
55
-	public $active;
56
-	public $module;
53
+    public $code;
54
+    public $libelle;
55
+    public $active;
56
+    public $module;
57 57
 
58 58
 
59 59
 
@@ -78,83 +78,83 @@  discard block
 block discarded – undo
78 78
      */
79 79
     function create($user, $notrigger=0)
80 80
     {
81
-    	global $conf, $langs;
82
-		$error=0;
81
+        global $conf, $langs;
82
+        $error=0;
83 83
 
84
-		// Clean parameters
84
+        // Clean parameters
85 85
 
86
-		if (isset($this->id)) $this->id=trim($this->id);
87
-		if (isset($this->code)) $this->code=trim($this->code);
88
-		if (isset($this->libelle)) $this->libelle=trim($this->libelle);
89
-		if (isset($this->active)) $this->active=trim($this->active);
90
-		if (isset($this->module)) $this->module=trim($this->module);
86
+        if (isset($this->id)) $this->id=trim($this->id);
87
+        if (isset($this->code)) $this->code=trim($this->code);
88
+        if (isset($this->libelle)) $this->libelle=trim($this->libelle);
89
+        if (isset($this->active)) $this->active=trim($this->active);
90
+        if (isset($this->module)) $this->module=trim($this->module);
91 91
 
92 92
 
93 93
 
94
-		// Check parameters
95
-		// Put here code to add control on parameters values
94
+        // Check parameters
95
+        // Put here code to add control on parameters values
96 96
 
97 97
         // Insert request
98
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent(";
98
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent(";
99 99
 
100
-		$sql.= "id,";
101
-		$sql.= "code,";
102
-		$sql.= "libelle,";
103
-		$sql.= "active,";
104
-		$sql.= "module";
100
+        $sql.= "id,";
101
+        $sql.= "code,";
102
+        $sql.= "libelle,";
103
+        $sql.= "active,";
104
+        $sql.= "module";
105 105
 
106 106
 
107 107
         $sql.= ") VALUES (";
108 108
 
109
-		$sql.= " ".(! isset($this->id)?'NULL':"'".$this->db->escape($this->id)."'").",";
110
-		$sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
111
-		$sql.= " ".(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").",";
112
-		$sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->active($this->active)."'").",";
113
-		$sql.= " ".(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'")."";
109
+        $sql.= " ".(! isset($this->id)?'NULL':"'".$this->db->escape($this->id)."'").",";
110
+        $sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
111
+        $sql.= " ".(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").",";
112
+        $sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->active($this->active)."'").",";
113
+        $sql.= " ".(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'")."";
114 114
 
115 115
 
116
-		$sql.= ")";
116
+        $sql.= ")";
117 117
 
118
-		$this->db->begin();
118
+        $this->db->begin();
119 119
 
120
-	   	dol_syslog(get_class($this)."::create", LOG_DEBUG);
120
+            dol_syslog(get_class($this)."::create", LOG_DEBUG);
121 121
         $resql=$this->db->query($sql);
122
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
122
+        if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
123 123
 
124
-		if (! $error)
124
+        if (! $error)
125 125
         {
126 126
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_typent");
127 127
 
128
-			if (! $notrigger)
129
-			{
130
-	            // Uncomment this and change MYOBJECT to your own tag if you
131
-	            // want this action call a trigger.
132
-
133
-	            //// Call triggers
134
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
135
-	            //$interface=new Interfaces($this->db);
136
-	            //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
137
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
138
-	            //// End call triggers
139
-			}
128
+            if (! $notrigger)
129
+            {
130
+                // Uncomment this and change MYOBJECT to your own tag if you
131
+                // want this action call a trigger.
132
+
133
+                //// Call triggers
134
+                //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
135
+                //$interface=new Interfaces($this->db);
136
+                //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf);
137
+                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
138
+                //// End call triggers
139
+            }
140 140
         }
141 141
 
142 142
         // Commit or rollback
143 143
         if ($error)
144
-		{
145
-			foreach($this->errors as $errmsg)
146
-			{
147
-	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
148
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
149
-			}
150
-			$this->db->rollback();
151
-			return -1*$error;
152
-		}
153
-		else
154
-		{
155
-			$this->db->commit();
144
+        {
145
+            foreach($this->errors as $errmsg)
146
+            {
147
+                dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
148
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
149
+            }
150
+            $this->db->rollback();
151
+            return -1*$error;
152
+        }
153
+        else
154
+        {
155
+            $this->db->commit();
156 156
             return $this->id;
157
-		}
157
+        }
158 158
     }
159 159
 
160 160
 
@@ -168,14 +168,14 @@  discard block
 block discarded – undo
168 168
      */
169 169
     function fetch($id,$code='',$label='')
170 170
     {
171
-    	global $langs;
171
+        global $langs;
172 172
         $sql = "SELECT";
173
-		$sql.= " t.id,";
174
-		$sql.= " t.code,";
175
-		$sql.= " t.libelle as label,";
176
-		$sql.= " t.fk_country as country_id,";
177
-		$sql.= " t.active,";
178
-		$sql.= " t.module";
173
+        $sql.= " t.id,";
174
+        $sql.= " t.code,";
175
+        $sql.= " t.libelle as label,";
176
+        $sql.= " t.fk_country as country_id,";
177
+        $sql.= " t.active,";
178
+        $sql.= " t.module";
179 179
         $sql.= " FROM ".MAIN_DB_PREFIX."c_typent as t";
180 180
         if ($id)   $sql.= " WHERE t.id = ".$id;
181 181
         elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
                 $obj = $this->db->fetch_object($resql);
190 190
 
191 191
                 $this->id    = $obj->id;
192
-				$this->code = $obj->code;
193
-				$this->libelle = $obj->label;
194
-				$this->country_id = $obj->country_id;
195
-				$this->active = $obj->active;
196
-				$this->module = $obj->module;
192
+                $this->code = $obj->code;
193
+                $this->libelle = $obj->label;
194
+                $this->country_id = $obj->country_id;
195
+                $this->active = $obj->active;
196
+                $this->module = $obj->module;
197 197
             }
198 198
             $this->db->free($resql);
199 199
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         }
202 202
         else
203 203
         {
204
-      	    $this->error="Error ".$this->db->lasterror();
204
+                $this->error="Error ".$this->db->lasterror();
205 205
             return -1;
206 206
         }
207 207
     }
@@ -216,120 +216,120 @@  discard block
 block discarded – undo
216 216
      */
217 217
     function update($user=null, $notrigger=0)
218 218
     {
219
-    	global $conf, $langs;
220
-		$error=0;
219
+        global $conf, $langs;
220
+        $error=0;
221 221
 
222
-		// Clean parameters
223
-		if (isset($this->code)) $this->code=trim($this->code);
224
-		if (isset($this->libelle)) $this->libelle=trim($this->libelle);
225
-		if (isset($this->active)) $this->active=trim($this->active);
226
-		if (isset($this->module)) $this->module=trim($this->module);
222
+        // Clean parameters
223
+        if (isset($this->code)) $this->code=trim($this->code);
224
+        if (isset($this->libelle)) $this->libelle=trim($this->libelle);
225
+        if (isset($this->active)) $this->active=trim($this->active);
226
+        if (isset($this->module)) $this->module=trim($this->module);
227 227
 
228 228
 
229
-		// Check parameters
230
-		// Put here code to add control on parameters values
229
+        // Check parameters
230
+        // Put here code to add control on parameters values
231 231
 
232 232
         // Update request
233 233
         $sql = "UPDATE ".MAIN_DB_PREFIX."c_typent SET";
234
-		$sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
235
-		$sql.= " libelle=".(isset($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null").",";
236
-		$sql.= " active=".(isset($this->active)?$this->active:"null").",";
237
-		$sql.= " module=".(isset($this->module)?"'".$this->db->escape($this->module)."'":"null")."";
234
+        $sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
235
+        $sql.= " libelle=".(isset($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null").",";
236
+        $sql.= " active=".(isset($this->active)?$this->active:"null").",";
237
+        $sql.= " module=".(isset($this->module)?"'".$this->db->escape($this->module)."'":"null")."";
238 238
         $sql.= " WHERE id=".$this->id;
239 239
 
240
-		$this->db->begin();
240
+        $this->db->begin();
241 241
 
242
-		dol_syslog(get_class($this)."::update", LOG_DEBUG);
242
+        dol_syslog(get_class($this)."::update", LOG_DEBUG);
243 243
         $resql = $this->db->query($sql);
244
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
245
-
246
-		if (! $error)
247
-		{
248
-			if (! $notrigger)
249
-			{
250
-	            // Uncomment this and change MYOBJECT to your own tag if you
251
-	            // want this action call a trigger.
252
-
253
-	            //// Call triggers
254
-	            //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
255
-	            //$interface=new Interfaces($this->db);
256
-	            //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
257
-	            //if ($result < 0) { $error++; $this->errors=$interface->errors; }
258
-	            //// End call triggers
259
-	    	}
260
-		}
244
+        if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
245
+
246
+        if (! $error)
247
+        {
248
+            if (! $notrigger)
249
+            {
250
+                // Uncomment this and change MYOBJECT to your own tag if you
251
+                // want this action call a trigger.
252
+
253
+                //// Call triggers
254
+                //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
255
+                //$interface=new Interfaces($this->db);
256
+                //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
257
+                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
258
+                //// End call triggers
259
+            }
260
+        }
261 261
 
262 262
         // Commit or rollback
263
-		if ($error)
264
-		{
265
-			foreach($this->errors as $errmsg)
266
-			{
267
-	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
268
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
269
-			}
270
-			$this->db->rollback();
271
-			return -1*$error;
272
-		}
273
-		else
274
-		{
275
-			$this->db->commit();
276
-			return 1;
277
-		}
263
+        if ($error)
264
+        {
265
+            foreach($this->errors as $errmsg)
266
+            {
267
+                dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
268
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
269
+            }
270
+            $this->db->rollback();
271
+            return -1*$error;
272
+        }
273
+        else
274
+        {
275
+            $this->db->commit();
276
+            return 1;
277
+        }
278 278
     }
279 279
 
280 280
 
281
- 	/**
282
-	 *  Delete object in database
283
-	 *
284
-     *	@param  User	$user        User that delete
285
-     *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
286
-	 *  @return	int					 <0 if KO, >0 if OK
287
-	 */
288
-	function delete($user, $notrigger=0)
289
-	{
290
-		global $conf, $langs;
291
-		$error=0;
292
-
293
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent";
294
-		$sql.= " WHERE id=".$this->id;
295
-
296
-		$this->db->begin();
297
-
298
-		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
299
-		$resql = $this->db->query($sql);
300
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
301
-
302
-		if (! $error)
303
-		{
304
-			if (! $notrigger)
305
-			{
306
-				// Uncomment this and change MYOBJECT to your own tag if you
307
-		        // want this action call a trigger.
308
-
309
-		        //// Call triggers
310
-		        //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
311
-		        //$interface=new Interfaces($this->db);
312
-		        //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
313
-		        //if ($result < 0) { $error++; $this->errors=$interface->errors; }
314
-		        //// End call triggers
315
-			}
316
-		}
281
+        /**
282
+         *  Delete object in database
283
+         *
284
+         *	@param  User	$user        User that delete
285
+         *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
286
+         *  @return	int					 <0 if KO, >0 if OK
287
+         */
288
+    function delete($user, $notrigger=0)
289
+    {
290
+        global $conf, $langs;
291
+        $error=0;
292
+
293
+        $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent";
294
+        $sql.= " WHERE id=".$this->id;
295
+
296
+        $this->db->begin();
297
+
298
+        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
299
+        $resql = $this->db->query($sql);
300
+        if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
301
+
302
+        if (! $error)
303
+        {
304
+            if (! $notrigger)
305
+            {
306
+                // Uncomment this and change MYOBJECT to your own tag if you
307
+                // want this action call a trigger.
308
+
309
+                //// Call triggers
310
+                //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
311
+                //$interface=new Interfaces($this->db);
312
+                //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
313
+                //if ($result < 0) { $error++; $this->errors=$interface->errors; }
314
+                //// End call triggers
315
+            }
316
+        }
317 317
 
318 318
         // Commit or rollback
319
-		if ($error)
320
-		{
321
-			foreach($this->errors as $errmsg)
322
-			{
323
-	            dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
324
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
325
-			}
326
-			$this->db->rollback();
327
-			return -1*$error;
328
-		}
329
-		else
330
-		{
331
-			$this->db->commit();
332
-			return 1;
333
-		}
334
-	}
319
+        if ($error)
320
+        {
321
+            foreach($this->errors as $errmsg)
322
+            {
323
+                dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
324
+                $this->error.=($this->error?', '.$errmsg:$errmsg);
325
+            }
326
+            $this->db->rollback();
327
+            return -1*$error;
328
+        }
329
+        else
330
+        {
331
+            $this->db->commit();
332
+            return 1;
333
+        }
334
+    }
335 335
 }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 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
 	 * @var string[] Error codes (or messages)
@@ -76,18 +76,18 @@  discard block
 block discarded – undo
76 76
      *  @param      int		$notrigger   0=launch triggers after, 1=disable triggers
77 77
      *  @return     int      		   	 <0 if KO, Id of created object if OK
78 78
      */
79
-    function create($user, $notrigger=0)
79
+    function create($user, $notrigger = 0)
80 80
     {
81 81
     	global $conf, $langs;
82
-		$error=0;
82
+		$error = 0;
83 83
 
84 84
 		// Clean parameters
85 85
 
86
-		if (isset($this->id)) $this->id=trim($this->id);
87
-		if (isset($this->code)) $this->code=trim($this->code);
88
-		if (isset($this->libelle)) $this->libelle=trim($this->libelle);
89
-		if (isset($this->active)) $this->active=trim($this->active);
90
-		if (isset($this->module)) $this->module=trim($this->module);
86
+		if (isset($this->id)) $this->id = trim($this->id);
87
+		if (isset($this->code)) $this->code = trim($this->code);
88
+		if (isset($this->libelle)) $this->libelle = trim($this->libelle);
89
+		if (isset($this->active)) $this->active = trim($this->active);
90
+		if (isset($this->module)) $this->module = trim($this->module);
91 91
 
92 92
 
93 93
 
@@ -97,35 +97,35 @@  discard block
 block discarded – undo
97 97
         // Insert request
98 98
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent(";
99 99
 
100
-		$sql.= "id,";
101
-		$sql.= "code,";
102
-		$sql.= "libelle,";
103
-		$sql.= "active,";
104
-		$sql.= "module";
100
+		$sql .= "id,";
101
+		$sql .= "code,";
102
+		$sql .= "libelle,";
103
+		$sql .= "active,";
104
+		$sql .= "module";
105 105
 
106 106
 
107
-        $sql.= ") VALUES (";
107
+        $sql .= ") VALUES (";
108 108
 
109
-		$sql.= " ".(! isset($this->id)?'NULL':"'".$this->db->escape($this->id)."'").",";
110
-		$sql.= " ".(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").",";
111
-		$sql.= " ".(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").",";
112
-		$sql.= " ".(! isset($this->active)?'NULL':"'".$this->db->active($this->active)."'").",";
113
-		$sql.= " ".(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'")."";
109
+		$sql .= " ".(!isset($this->id) ? 'NULL' : "'".$this->db->escape($this->id)."'").",";
110
+		$sql .= " ".(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").",";
111
+		$sql .= " ".(!isset($this->libelle) ? 'NULL' : "'".$this->db->escape($this->libelle)."'").",";
112
+		$sql .= " ".(!isset($this->active) ? 'NULL' : "'".$this->db->active($this->active)."'").",";
113
+		$sql .= " ".(!isset($this->module) ? 'NULL' : "'".$this->db->escape($this->module)."'")."";
114 114
 
115 115
 
116
-		$sql.= ")";
116
+		$sql .= ")";
117 117
 
118 118
 		$this->db->begin();
119 119
 
120 120
 	   	dol_syslog(get_class($this)."::create", LOG_DEBUG);
121
-        $resql=$this->db->query($sql);
122
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
121
+        $resql = $this->db->query($sql);
122
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
123 123
 
124
-		if (! $error)
124
+		if (!$error)
125 125
         {
126 126
             $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_typent");
127 127
 
128
-			if (! $notrigger)
128
+			if (!$notrigger)
129 129
 			{
130 130
 	            // Uncomment this and change MYOBJECT to your own tag if you
131 131
 	            // want this action call a trigger.
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
         // Commit or rollback
143 143
         if ($error)
144 144
 		{
145
-			foreach($this->errors as $errmsg)
145
+			foreach ($this->errors as $errmsg)
146 146
 			{
147 147
 	            dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
148
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
148
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
149 149
 			}
150 150
 			$this->db->rollback();
151
-			return -1*$error;
151
+			return -1 * $error;
152 152
 		}
153 153
 		else
154 154
 		{
@@ -166,29 +166,29 @@  discard block
 block discarded – undo
166 166
      *  @param		string	$label	Label
167 167
      *  @return     int          	<0 if KO, >0 if OK
168 168
      */
169
-    function fetch($id,$code='',$label='')
169
+    function fetch($id, $code = '', $label = '')
170 170
     {
171 171
     	global $langs;
172 172
         $sql = "SELECT";
173
-		$sql.= " t.id,";
174
-		$sql.= " t.code,";
175
-		$sql.= " t.libelle as label,";
176
-		$sql.= " t.fk_country as country_id,";
177
-		$sql.= " t.active,";
178
-		$sql.= " t.module";
179
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_typent as t";
180
-        if ($id)   $sql.= " WHERE t.id = ".$id;
181
-        elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
182
-        elseif ($label) $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'";
183
-
184
-        $resql=$this->db->query($sql);
173
+		$sql .= " t.id,";
174
+		$sql .= " t.code,";
175
+		$sql .= " t.libelle as label,";
176
+		$sql .= " t.fk_country as country_id,";
177
+		$sql .= " t.active,";
178
+		$sql .= " t.module";
179
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_typent as t";
180
+        if ($id)   $sql .= " WHERE t.id = ".$id;
181
+        elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
182
+        elseif ($label) $sql .= " WHERE t.libelle = '".$this->db->escape($label)."'";
183
+
184
+        $resql = $this->db->query($sql);
185 185
         if ($resql)
186 186
         {
187 187
             if ($this->db->num_rows($resql))
188 188
             {
189 189
                 $obj = $this->db->fetch_object($resql);
190 190
 
191
-                $this->id    = $obj->id;
191
+                $this->id = $obj->id;
192 192
 				$this->code = $obj->code;
193 193
 				$this->libelle = $obj->label;
194 194
 				$this->country_id = $obj->country_id;
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         }
202 202
         else
203 203
         {
204
-      	    $this->error="Error ".$this->db->lasterror();
204
+      	    $this->error = "Error ".$this->db->lasterror();
205 205
             return -1;
206 206
         }
207 207
     }
@@ -214,16 +214,16 @@  discard block
 block discarded – undo
214 214
      *  @param      int		$notrigger	 0=launch triggers after, 1=disable triggers
215 215
      *  @return     int     		   	 <0 if KO, >0 if OK
216 216
      */
217
-    function update($user=null, $notrigger=0)
217
+    function update($user = null, $notrigger = 0)
218 218
     {
219 219
     	global $conf, $langs;
220
-		$error=0;
220
+		$error = 0;
221 221
 
222 222
 		// Clean parameters
223
-		if (isset($this->code)) $this->code=trim($this->code);
224
-		if (isset($this->libelle)) $this->libelle=trim($this->libelle);
225
-		if (isset($this->active)) $this->active=trim($this->active);
226
-		if (isset($this->module)) $this->module=trim($this->module);
223
+		if (isset($this->code)) $this->code = trim($this->code);
224
+		if (isset($this->libelle)) $this->libelle = trim($this->libelle);
225
+		if (isset($this->active)) $this->active = trim($this->active);
226
+		if (isset($this->module)) $this->module = trim($this->module);
227 227
 
228 228
 
229 229
 		// Check parameters
@@ -231,21 +231,21 @@  discard block
 block discarded – undo
231 231
 
232 232
         // Update request
233 233
         $sql = "UPDATE ".MAIN_DB_PREFIX."c_typent SET";
234
-		$sql.= " code=".(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").",";
235
-		$sql.= " libelle=".(isset($this->libelle)?"'".$this->db->escape($this->libelle)."'":"null").",";
236
-		$sql.= " active=".(isset($this->active)?$this->active:"null").",";
237
-		$sql.= " module=".(isset($this->module)?"'".$this->db->escape($this->module)."'":"null")."";
238
-        $sql.= " WHERE id=".$this->id;
234
+		$sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").",";
235
+		$sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").",";
236
+		$sql .= " active=".(isset($this->active) ? $this->active : "null").",";
237
+		$sql .= " module=".(isset($this->module) ? "'".$this->db->escape($this->module)."'" : "null")."";
238
+        $sql .= " WHERE id=".$this->id;
239 239
 
240 240
 		$this->db->begin();
241 241
 
242 242
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
243 243
         $resql = $this->db->query($sql);
244
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
244
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
245 245
 
246
-		if (! $error)
246
+		if (!$error)
247 247
 		{
248
-			if (! $notrigger)
248
+			if (!$notrigger)
249 249
 			{
250 250
 	            // Uncomment this and change MYOBJECT to your own tag if you
251 251
 	            // want this action call a trigger.
@@ -262,13 +262,13 @@  discard block
 block discarded – undo
262 262
         // Commit or rollback
263 263
 		if ($error)
264 264
 		{
265
-			foreach($this->errors as $errmsg)
265
+			foreach ($this->errors as $errmsg)
266 266
 			{
267 267
 	            dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
268
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
268
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
269 269
 			}
270 270
 			$this->db->rollback();
271
-			return -1*$error;
271
+			return -1 * $error;
272 272
 		}
273 273
 		else
274 274
 		{
@@ -285,23 +285,23 @@  discard block
 block discarded – undo
285 285
      *  @param  int		$notrigger	 0=launch triggers after, 1=disable triggers
286 286
 	 *  @return	int					 <0 if KO, >0 if OK
287 287
 	 */
288
-	function delete($user, $notrigger=0)
288
+	function delete($user, $notrigger = 0)
289 289
 	{
290 290
 		global $conf, $langs;
291
-		$error=0;
291
+		$error = 0;
292 292
 
293 293
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent";
294
-		$sql.= " WHERE id=".$this->id;
294
+		$sql .= " WHERE id=".$this->id;
295 295
 
296 296
 		$this->db->begin();
297 297
 
298 298
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
299 299
 		$resql = $this->db->query($sql);
300
-    	if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
300
+    	if (!$resql) { $error++; $this->errors[] = "Error ".$this->db->lasterror(); }
301 301
 
302
-		if (! $error)
302
+		if (!$error)
303 303
 		{
304
-			if (! $notrigger)
304
+			if (!$notrigger)
305 305
 			{
306 306
 				// Uncomment this and change MYOBJECT to your own tag if you
307 307
 		        // want this action call a trigger.
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
         // Commit or rollback
319 319
 		if ($error)
320 320
 		{
321
-			foreach($this->errors as $errmsg)
321
+			foreach ($this->errors as $errmsg)
322 322
 			{
323 323
 	            dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
324
-	            $this->error.=($this->error?', '.$errmsg:$errmsg);
324
+	            $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
325 325
 			}
326 326
 			$this->db->rollback();
327
-			return -1*$error;
327
+			return -1 * $error;
328 328
 		}
329 329
 		else
330 330
 		{
Please login to merge, or discard this patch.
Braces   +38 added lines, -20 removed lines patch added patch discarded remove patch
@@ -83,11 +83,21 @@  discard block
 block discarded – undo
83 83
 
84 84
 		// Clean parameters
85 85
 
86
-		if (isset($this->id)) $this->id=trim($this->id);
87
-		if (isset($this->code)) $this->code=trim($this->code);
88
-		if (isset($this->libelle)) $this->libelle=trim($this->libelle);
89
-		if (isset($this->active)) $this->active=trim($this->active);
90
-		if (isset($this->module)) $this->module=trim($this->module);
86
+		if (isset($this->id)) {
87
+		    $this->id=trim($this->id);
88
+		}
89
+		if (isset($this->code)) {
90
+		    $this->code=trim($this->code);
91
+		}
92
+		if (isset($this->libelle)) {
93
+		    $this->libelle=trim($this->libelle);
94
+		}
95
+		if (isset($this->active)) {
96
+		    $this->active=trim($this->active);
97
+		}
98
+		if (isset($this->module)) {
99
+		    $this->module=trim($this->module);
100
+		}
91 101
 
92 102
 
93 103
 
@@ -149,8 +159,7 @@  discard block
 block discarded – undo
149 159
 			}
150 160
 			$this->db->rollback();
151 161
 			return -1*$error;
152
-		}
153
-		else
162
+		} else
154 163
 		{
155 164
 			$this->db->commit();
156 165
             return $this->id;
@@ -177,9 +186,13 @@  discard block
 block discarded – undo
177 186
 		$sql.= " t.active,";
178 187
 		$sql.= " t.module";
179 188
         $sql.= " FROM ".MAIN_DB_PREFIX."c_typent as t";
180
-        if ($id)   $sql.= " WHERE t.id = ".$id;
181
-        elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
182
-        elseif ($label) $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'";
189
+        if ($id) {
190
+            $sql.= " WHERE t.id = ".$id;
191
+        } elseif ($code) {
192
+            $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
193
+        } elseif ($label) {
194
+            $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'";
195
+        }
183 196
 
184 197
         $resql=$this->db->query($sql);
185 198
         if ($resql)
@@ -198,8 +211,7 @@  discard block
 block discarded – undo
198 211
             $this->db->free($resql);
199 212
 
200 213
             return 1;
201
-        }
202
-        else
214
+        } else
203 215
         {
204 216
       	    $this->error="Error ".$this->db->lasterror();
205 217
             return -1;
@@ -220,10 +232,18 @@  discard block
 block discarded – undo
220 232
 		$error=0;
221 233
 
222 234
 		// Clean parameters
223
-		if (isset($this->code)) $this->code=trim($this->code);
224
-		if (isset($this->libelle)) $this->libelle=trim($this->libelle);
225
-		if (isset($this->active)) $this->active=trim($this->active);
226
-		if (isset($this->module)) $this->module=trim($this->module);
235
+		if (isset($this->code)) {
236
+		    $this->code=trim($this->code);
237
+		}
238
+		if (isset($this->libelle)) {
239
+		    $this->libelle=trim($this->libelle);
240
+		}
241
+		if (isset($this->active)) {
242
+		    $this->active=trim($this->active);
243
+		}
244
+		if (isset($this->module)) {
245
+		    $this->module=trim($this->module);
246
+		}
227 247
 
228 248
 
229 249
 		// Check parameters
@@ -269,8 +289,7 @@  discard block
 block discarded – undo
269 289
 			}
270 290
 			$this->db->rollback();
271 291
 			return -1*$error;
272
-		}
273
-		else
292
+		} else
274 293
 		{
275 294
 			$this->db->commit();
276 295
 			return 1;
@@ -325,8 +344,7 @@  discard block
 block discarded – undo
325 344
 			}
326 345
 			$this->db->rollback();
327 346
 			return -1*$error;
328
-		}
329
-		else
347
+		} else
330 348
 		{
331 349
 			$this->db->commit();
332 350
 			return 1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formbank.class.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  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
     /**
@@ -64,19 +64,19 @@  discard block
 block discarded – undo
64 64
         print Form::selectarray($htmlname, $account->type_lib, $selected);
65 65
     }
66 66
 
67
-	/**
68
-	 * Returns the name of the Iban label. India uses 'IFSC' and the rest of the world 'IBAN' name.
69
-	 *
70
-	 * @param Account $account Account object
71
-	 * @return string
72
-	 */
73
-	public static function getIBANLabel(Account $account)
74
-	{
75
-		if ($account->getCountryCode() == 'IN') {
76
-			return 'IFSC';
77
-		}
67
+    /**
68
+     * Returns the name of the Iban label. India uses 'IFSC' and the rest of the world 'IBAN' name.
69
+     *
70
+     * @param Account $account Account object
71
+     * @return string
72
+     */
73
+    public static function getIBANLabel(Account $account)
74
+    {
75
+        if ($account->getCountryCode() == 'IN') {
76
+            return 'IFSC';
77
+        }
78 78
 
79
-		return 'IBANNumber';
80
-	}
79
+        return 'IBANNumber';
80
+    }
81 81
 }
82 82
 
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 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
     /**
Please login to merge, or discard this patch.