Passed
Push — master ( 8f7a8e...7e4a07 )
by Alxarafe
20:11
created
dolibarr/htdocs/core/class/events.class.php 3 patches
Indentation   +237 added lines, -237 removed lines patch added patch discarded remove patch
@@ -34,62 +34,62 @@  discard block
 block discarded – undo
34 34
  */
35 35
 class Events // extends CommonObject
36 36
 {
37
-	/**
38
-	 * @var string ID to identify managed object
39
-	 */
40
-	public $element='events';
37
+    /**
38
+     * @var string ID to identify managed object
39
+     */
40
+    public $element='events';
41 41
 
42
-	/**
43
-	 * @var string Name of table without prefix where object is stored
44
-	 */
45
-	public $table_element='events';
42
+    /**
43
+     * @var string Name of table without prefix where object is stored
44
+     */
45
+    public $table_element='events';
46 46
 
47
-	/**
48
-	 * @var int ID
49
-	 */
50
-	public $id;
47
+    /**
48
+     * @var int ID
49
+     */
50
+    public $id;
51 51
 
52 52
     /**
53 53
      * @var DoliDB Database handler.
54 54
      */
55 55
     public $db;
56 56
 
57
-	/**
58
-	 * @var string Error code (or message)
59
-	 */
60
-	public $error='';
61
-
62
-	public $tms;
63
-	public $type;
64
-
65
-	/**
66
-	 * @var int Entity
67
-	 */
68
-	public $entity;
69
-
70
-	public $dateevent;
71
-
72
-	/**
73
-	 * @var string description
74
-	 */
75
-	public $description;
76
-
77
-	// List of all Audit/Security events supported by triggers
78
-	public $eventstolog=array(
79
-		array('id'=>'USER_LOGIN',             'test'=>1),
80
-		array('id'=>'USER_LOGIN_FAILED',      'test'=>1),
81
-	    array('id'=>'USER_LOGOUT',            'test'=>1),
82
-		array('id'=>'USER_CREATE',            'test'=>1),
83
-		array('id'=>'USER_MODIFY',            'test'=>1),
84
-		array('id'=>'USER_NEW_PASSWORD',      'test'=>1),
85
-		array('id'=>'USER_ENABLEDISABLE',     'test'=>1),
86
-		array('id'=>'USER_DELETE',            'test'=>1),
87
-	/*    array('id'=>'USER_SETINGROUP',        'test'=>1), deprecated. Replace with USER_MODIFY
57
+    /**
58
+     * @var string Error code (or message)
59
+     */
60
+    public $error='';
61
+
62
+    public $tms;
63
+    public $type;
64
+
65
+    /**
66
+     * @var int Entity
67
+     */
68
+    public $entity;
69
+
70
+    public $dateevent;
71
+
72
+    /**
73
+     * @var string description
74
+     */
75
+    public $description;
76
+
77
+    // List of all Audit/Security events supported by triggers
78
+    public $eventstolog=array(
79
+        array('id'=>'USER_LOGIN',             'test'=>1),
80
+        array('id'=>'USER_LOGIN_FAILED',      'test'=>1),
81
+        array('id'=>'USER_LOGOUT',            'test'=>1),
82
+        array('id'=>'USER_CREATE',            'test'=>1),
83
+        array('id'=>'USER_MODIFY',            'test'=>1),
84
+        array('id'=>'USER_NEW_PASSWORD',      'test'=>1),
85
+        array('id'=>'USER_ENABLEDISABLE',     'test'=>1),
86
+        array('id'=>'USER_DELETE',            'test'=>1),
87
+    /*    array('id'=>'USER_SETINGROUP',        'test'=>1), deprecated. Replace with USER_MODIFY
88 88
 	    array('id'=>'USER_REMOVEFROMGROUP',   'test'=>1), deprecated. Replace with USER_MODIFY */
89
-		array('id'=>'GROUP_CREATE',           'test'=>1),
90
-		array('id'=>'GROUP_MODIFY',           'test'=>1),
91
-		array('id'=>'GROUP_DELETE',           'test'=>1),
92
-	/*	array('id'=>'ACTION_CREATE',          'test'=>$conf->societe->enabled),
89
+        array('id'=>'GROUP_CREATE',           'test'=>1),
90
+        array('id'=>'GROUP_MODIFY',           'test'=>1),
91
+        array('id'=>'GROUP_DELETE',           'test'=>1),
92
+    /*	array('id'=>'ACTION_CREATE',          'test'=>$conf->societe->enabled),
93 93
 		array('id'=>'COMPANY_CREATE',         'test'=>$conf->societe->enabled),
94 94
 		array('id'=>'CONTRACT_VALIDATE',      'test'=>$conf->contrat->enabled),
95 95
 		array('id'=>'PROPAL_VALIDATE',        'test'=>$conf->propal->enabled),
@@ -111,199 +111,199 @@  discard block
 block discarded – undo
111 111
 		array('id'=>'MEMBER_RESILIATE',       'test'=>$conf->adherent->enabled),
112 112
 		array('id'=>'MEMBER_DELETE',          'test'=>$conf->adherent->enabled),
113 113
 	*/
114
-	);
115
-
116
-
117
-	/**
118
-	 *	Constructor
119
-	 *
120
-	 *  @param		DoliDB		$db      Database handler
121
-	 */
122
-	function __construct($db)
123
-	{
124
-		$this->db = $db;
125
-	}
126
-
127
-
128
-	/**
129
-	 *   Create in database
130
-	 *
131
-	 *   @param      User	$user       User that create
132
-	 *   @return     int     		    <0 if KO, >0 if OK
133
-	 */
134
-	function create($user)
135
-	{
136
-		global $conf, $langs;
137
-
138
-		// Clean parameters
139
-		$this->description=trim($this->description);
140
-		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
141
-
142
-		// Check parameters
143
-		if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
144
-
145
-		// Insert request
146
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."events(";
147
-		$sql.= "type,";
148
-		$sql.= "entity,";
149
-		$sql.= "ip,";
150
-		$sql.= "user_agent,";
151
-		$sql.= "dateevent,";
152
-		$sql.= "fk_user,";
153
-		$sql.= "description";
154
-		$sql.= ") VALUES (";
155
-		$sql.= " '".$this->db->escape($this->type)."',";
156
-		$sql.= " ".$conf->entity.",";
157
-		$sql.= " '".$this->db->escape(getUserRemoteIP())."',";
158
-		$sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').",";
159
-		$sql.= " '".$this->db->idate($this->dateevent)."',";
160
-		$sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').",";
161
-		$sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'";
162
-		$sql.= ")";
163
-
164
-		dol_syslog(get_class($this)."::create", LOG_DEBUG);
165
-		$resql=$this->db->query($sql);
166
-		if ($resql)
167
-		{
168
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
169
-			return $this->id;
170
-		}
171
-		else
172
-		{
173
-			$this->error="Error ".$this->db->lasterror();
174
-			return -1;
175
-		}
176
-	}
177
-
178
-
179
-	/**
180
-	 * Update database
181
-	 *
182
-	 * @param	User    $user        	User that modify
183
-	 * @param   int		$notrigger	    0=no, 1=yes (no update trigger)
184
-	 * @return  int         			<0 if KO, >0 if OK
185
-	 */
186
-	function update($user=null, $notrigger=0)
187
-	{
188
-		global $conf, $langs;
189
-
190
-		// Clean parameters
191
-		$this->id=trim($this->id);
192
-		$this->type=trim($this->type);
193
-		$this->description=trim($this->description);
194
-
195
-		// Check parameters
196
-		// Put here code to add control on parameters values
197
-
198
-		// Update request
199
-		$sql = "UPDATE ".MAIN_DB_PREFIX."events SET";
200
-		$sql.= " type='".$this->db->escape($this->type)."',";
201
-		$sql.= " dateevent='".$this->db->idate($this->dateevent)."',";
202
-		$sql.= " description='".$this->db->escape($this->description)."'";
203
-		$sql.= " WHERE rowid=".$this->id;
204
-
205
-		dol_syslog(get_class($this)."::update", LOG_DEBUG);
206
-		$resql = $this->db->query($sql);
207
-		if (! $resql)
208
-		{
209
-			$this->error="Error ".$this->db->lasterror();
210
-			return -1;
211
-		}
212
-		return 1;
213
-	}
214
-
215
-
216
-	/**
217
-	 *  Load object in memory from database
218
-	 *
219
-	 *  @param	int		$id         Id object
220
-	 *  @param  User	$user       User that load
221
-	 *  @return int         		<0 if KO, >0 if OK
222
-	 */
223
-	function fetch($id, $user=null)
224
-	{
225
-		global $langs;
226
-
227
-		$sql = "SELECT";
228
-		$sql.= " t.rowid,";
229
-		$sql.= " t.tms,";
230
-		$sql.= " t.type,";
231
-		$sql.= " t.entity,";
232
-		$sql.= " t.dateevent,";
233
-		$sql.= " t.description,";
234
-		$sql.= " t.ip,";
235
-		$sql.= " t.user_agent";
236
-		$sql.= " FROM ".MAIN_DB_PREFIX."events as t";
237
-		$sql.= " WHERE t.rowid = ".$id;
238
-
239
-		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
240
-		$resql=$this->db->query($sql);
241
-		if ($resql)
242
-		{
243
-			if ($this->db->num_rows($resql))
244
-			{
245
-				$obj = $this->db->fetch_object($resql);
246
-
247
-				$this->id    = $obj->rowid;
248
-				$this->tms = $this->db->jdate($obj->tms);
249
-				$this->type = $obj->type;
250
-				$this->entity = $obj->entity;
251
-				$this->dateevent = $this->db->jdate($obj->dateevent);
252
-				$this->description = $obj->description;
253
-				$this->ip = $obj->ip;
254
-				$this->user_agent = $obj->user_agent;
255
-			}
256
-			$this->db->free($resql);
257
-
258
-			return 1;
259
-		}
260
-		else
261
-		{
262
-			$this->error="Error ".$this->db->lasterror();
263
-			return -1;
264
-		}
265
-	}
266
-
267
-
268
-	/**
269
-	 *  Delete object in database
270
-	 *
271
-	 *	@param	User	$user       User that delete
272
-	 *	@return	int					<0 if KO, >0 if OK
273
-	 */
274
-	function delete($user)
275
-	{
276
-		global $conf, $langs;
277
-
278
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."events";
279
-		$sql.= " WHERE rowid=".$this->id;
280
-
281
-		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
282
-		$resql = $this->db->query($sql);
283
-		if (! $resql)
284
-		{
285
-			$this->error="Error ".$this->db->lasterror();
286
-			return -1;
287
-		}
288
-
289
-		return 1;
290
-	}
291
-
292
-
293
-	/**
114
+    );
115
+
116
+
117
+    /**
118
+     *	Constructor
119
+     *
120
+     *  @param		DoliDB		$db      Database handler
121
+     */
122
+    function __construct($db)
123
+    {
124
+        $this->db = $db;
125
+    }
126
+
127
+
128
+    /**
129
+     *   Create in database
130
+     *
131
+     *   @param      User	$user       User that create
132
+     *   @return     int     		    <0 if KO, >0 if OK
133
+     */
134
+    function create($user)
135
+    {
136
+        global $conf, $langs;
137
+
138
+        // Clean parameters
139
+        $this->description=trim($this->description);
140
+        if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
141
+
142
+        // Check parameters
143
+        if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
144
+
145
+        // Insert request
146
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."events(";
147
+        $sql.= "type,";
148
+        $sql.= "entity,";
149
+        $sql.= "ip,";
150
+        $sql.= "user_agent,";
151
+        $sql.= "dateevent,";
152
+        $sql.= "fk_user,";
153
+        $sql.= "description";
154
+        $sql.= ") VALUES (";
155
+        $sql.= " '".$this->db->escape($this->type)."',";
156
+        $sql.= " ".$conf->entity.",";
157
+        $sql.= " '".$this->db->escape(getUserRemoteIP())."',";
158
+        $sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').",";
159
+        $sql.= " '".$this->db->idate($this->dateevent)."',";
160
+        $sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').",";
161
+        $sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'";
162
+        $sql.= ")";
163
+
164
+        dol_syslog(get_class($this)."::create", LOG_DEBUG);
165
+        $resql=$this->db->query($sql);
166
+        if ($resql)
167
+        {
168
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
169
+            return $this->id;
170
+        }
171
+        else
172
+        {
173
+            $this->error="Error ".$this->db->lasterror();
174
+            return -1;
175
+        }
176
+    }
177
+
178
+
179
+    /**
180
+     * Update database
181
+     *
182
+     * @param	User    $user        	User that modify
183
+     * @param   int		$notrigger	    0=no, 1=yes (no update trigger)
184
+     * @return  int         			<0 if KO, >0 if OK
185
+     */
186
+    function update($user=null, $notrigger=0)
187
+    {
188
+        global $conf, $langs;
189
+
190
+        // Clean parameters
191
+        $this->id=trim($this->id);
192
+        $this->type=trim($this->type);
193
+        $this->description=trim($this->description);
194
+
195
+        // Check parameters
196
+        // Put here code to add control on parameters values
197
+
198
+        // Update request
199
+        $sql = "UPDATE ".MAIN_DB_PREFIX."events SET";
200
+        $sql.= " type='".$this->db->escape($this->type)."',";
201
+        $sql.= " dateevent='".$this->db->idate($this->dateevent)."',";
202
+        $sql.= " description='".$this->db->escape($this->description)."'";
203
+        $sql.= " WHERE rowid=".$this->id;
204
+
205
+        dol_syslog(get_class($this)."::update", LOG_DEBUG);
206
+        $resql = $this->db->query($sql);
207
+        if (! $resql)
208
+        {
209
+            $this->error="Error ".$this->db->lasterror();
210
+            return -1;
211
+        }
212
+        return 1;
213
+    }
214
+
215
+
216
+    /**
217
+     *  Load object in memory from database
218
+     *
219
+     *  @param	int		$id         Id object
220
+     *  @param  User	$user       User that load
221
+     *  @return int         		<0 if KO, >0 if OK
222
+     */
223
+    function fetch($id, $user=null)
224
+    {
225
+        global $langs;
226
+
227
+        $sql = "SELECT";
228
+        $sql.= " t.rowid,";
229
+        $sql.= " t.tms,";
230
+        $sql.= " t.type,";
231
+        $sql.= " t.entity,";
232
+        $sql.= " t.dateevent,";
233
+        $sql.= " t.description,";
234
+        $sql.= " t.ip,";
235
+        $sql.= " t.user_agent";
236
+        $sql.= " FROM ".MAIN_DB_PREFIX."events as t";
237
+        $sql.= " WHERE t.rowid = ".$id;
238
+
239
+        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
240
+        $resql=$this->db->query($sql);
241
+        if ($resql)
242
+        {
243
+            if ($this->db->num_rows($resql))
244
+            {
245
+                $obj = $this->db->fetch_object($resql);
246
+
247
+                $this->id    = $obj->rowid;
248
+                $this->tms = $this->db->jdate($obj->tms);
249
+                $this->type = $obj->type;
250
+                $this->entity = $obj->entity;
251
+                $this->dateevent = $this->db->jdate($obj->dateevent);
252
+                $this->description = $obj->description;
253
+                $this->ip = $obj->ip;
254
+                $this->user_agent = $obj->user_agent;
255
+            }
256
+            $this->db->free($resql);
257
+
258
+            return 1;
259
+        }
260
+        else
261
+        {
262
+            $this->error="Error ".$this->db->lasterror();
263
+            return -1;
264
+        }
265
+    }
266
+
267
+
268
+    /**
269
+     *  Delete object in database
270
+     *
271
+     *	@param	User	$user       User that delete
272
+     *	@return	int					<0 if KO, >0 if OK
273
+     */
274
+    function delete($user)
275
+    {
276
+        global $conf, $langs;
277
+
278
+        $sql = "DELETE FROM ".MAIN_DB_PREFIX."events";
279
+        $sql.= " WHERE rowid=".$this->id;
280
+
281
+        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
282
+        $resql = $this->db->query($sql);
283
+        if (! $resql)
284
+        {
285
+            $this->error="Error ".$this->db->lasterror();
286
+            return -1;
287
+        }
288
+
289
+        return 1;
290
+    }
291
+
292
+
293
+    /**
294 294
      *  Initialise an instance with random values.
295 295
      *  Used to build previews or test instances.
296 296
      *	id must be 0 if object instance is a specimen.
297 297
      *
298 298
      *  @return	void
299
-	 */
300
-	function initAsSpecimen()
301
-	{
302
-		$this->id=0;
303
-
304
-		$this->tms=time();
305
-		$this->type='';
306
-		$this->dateevent=time();
307
-		$this->description='This is a specimen event';
308
-	}
299
+     */
300
+    function initAsSpecimen()
301
+    {
302
+        $this->id=0;
303
+
304
+        $this->tms=time();
305
+        $this->type='';
306
+        $this->dateevent=time();
307
+        $this->description='This is a specimen event';
308
+    }
309 309
 }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 	/**
38 38
 	 * @var string ID to identify managed object
39 39
 	 */
40
-	public $element='events';
40
+	public $element = 'events';
41 41
 
42 42
 	/**
43 43
 	 * @var string Name of table without prefix where object is stored
44 44
 	 */
45
-	public $table_element='events';
45
+	public $table_element = 'events';
46 46
 
47 47
 	/**
48 48
 	 * @var int ID
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	/**
58 58
 	 * @var string Error code (or message)
59 59
 	 */
60
-	public $error='';
60
+	public $error = '';
61 61
 
62 62
 	public $tms;
63 63
 	public $type;
@@ -75,20 +75,20 @@  discard block
 block discarded – undo
75 75
 	public $description;
76 76
 
77 77
 	// List of all Audit/Security events supported by triggers
78
-	public $eventstolog=array(
79
-		array('id'=>'USER_LOGIN',             'test'=>1),
80
-		array('id'=>'USER_LOGIN_FAILED',      'test'=>1),
81
-	    array('id'=>'USER_LOGOUT',            'test'=>1),
82
-		array('id'=>'USER_CREATE',            'test'=>1),
83
-		array('id'=>'USER_MODIFY',            'test'=>1),
84
-		array('id'=>'USER_NEW_PASSWORD',      'test'=>1),
85
-		array('id'=>'USER_ENABLEDISABLE',     'test'=>1),
86
-		array('id'=>'USER_DELETE',            'test'=>1),
78
+	public $eventstolog = array(
79
+		array('id'=>'USER_LOGIN', 'test'=>1),
80
+		array('id'=>'USER_LOGIN_FAILED', 'test'=>1),
81
+	    array('id'=>'USER_LOGOUT', 'test'=>1),
82
+		array('id'=>'USER_CREATE', 'test'=>1),
83
+		array('id'=>'USER_MODIFY', 'test'=>1),
84
+		array('id'=>'USER_NEW_PASSWORD', 'test'=>1),
85
+		array('id'=>'USER_ENABLEDISABLE', 'test'=>1),
86
+		array('id'=>'USER_DELETE', 'test'=>1),
87 87
 	/*    array('id'=>'USER_SETINGROUP',        'test'=>1), deprecated. Replace with USER_MODIFY
88 88
 	    array('id'=>'USER_REMOVEFROMGROUP',   'test'=>1), deprecated. Replace with USER_MODIFY */
89
-		array('id'=>'GROUP_CREATE',           'test'=>1),
90
-		array('id'=>'GROUP_MODIFY',           'test'=>1),
91
-		array('id'=>'GROUP_DELETE',           'test'=>1),
89
+		array('id'=>'GROUP_CREATE', 'test'=>1),
90
+		array('id'=>'GROUP_MODIFY', 'test'=>1),
91
+		array('id'=>'GROUP_DELETE', 'test'=>1),
92 92
 	/*	array('id'=>'ACTION_CREATE',          'test'=>$conf->societe->enabled),
93 93
 		array('id'=>'COMPANY_CREATE',         'test'=>$conf->societe->enabled),
94 94
 		array('id'=>'CONTRACT_VALIDATE',      'test'=>$conf->contrat->enabled),
@@ -136,33 +136,33 @@  discard block
 block discarded – undo
136 136
 		global $conf, $langs;
137 137
 
138 138
 		// Clean parameters
139
-		$this->description=trim($this->description);
140
-		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
139
+		$this->description = trim($this->description);
140
+		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent = $_SERVER['HTTP_USER_AGENT'];
141 141
 
142 142
 		// Check parameters
143
-		if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
143
+		if (empty($this->description)) { $this->error = 'ErrorBadValueForParameterCreateEventDesc'; return -1; }
144 144
 
145 145
 		// Insert request
146 146
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."events(";
147
-		$sql.= "type,";
148
-		$sql.= "entity,";
149
-		$sql.= "ip,";
150
-		$sql.= "user_agent,";
151
-		$sql.= "dateevent,";
152
-		$sql.= "fk_user,";
153
-		$sql.= "description";
154
-		$sql.= ") VALUES (";
155
-		$sql.= " '".$this->db->escape($this->type)."',";
156
-		$sql.= " ".$conf->entity.",";
157
-		$sql.= " '".$this->db->escape(getUserRemoteIP())."',";
158
-		$sql.= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent,250))."'" : 'NULL').",";
159
-		$sql.= " '".$this->db->idate($this->dateevent)."',";
160
-		$sql.= " ".($user->id?"'".$this->db->escape($user->id)."'":'NULL').",";
161
-		$sql.= " '".$this->db->escape(dol_trunc($this->description,250))."'";
162
-		$sql.= ")";
147
+		$sql .= "type,";
148
+		$sql .= "entity,";
149
+		$sql .= "ip,";
150
+		$sql .= "user_agent,";
151
+		$sql .= "dateevent,";
152
+		$sql .= "fk_user,";
153
+		$sql .= "description";
154
+		$sql .= ") VALUES (";
155
+		$sql .= " '".$this->db->escape($this->type)."',";
156
+		$sql .= " ".$conf->entity.",";
157
+		$sql .= " '".$this->db->escape(getUserRemoteIP())."',";
158
+		$sql .= " ".($this->user_agent ? "'".$this->db->escape(dol_trunc($this->user_agent, 250))."'" : 'NULL').",";
159
+		$sql .= " '".$this->db->idate($this->dateevent)."',";
160
+		$sql .= " ".($user->id ? "'".$this->db->escape($user->id)."'" : 'NULL').",";
161
+		$sql .= " '".$this->db->escape(dol_trunc($this->description, 250))."'";
162
+		$sql .= ")";
163 163
 
164 164
 		dol_syslog(get_class($this)."::create", LOG_DEBUG);
165
-		$resql=$this->db->query($sql);
165
+		$resql = $this->db->query($sql);
166 166
 		if ($resql)
167 167
 		{
168 168
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		}
171 171
 		else
172 172
 		{
173
-			$this->error="Error ".$this->db->lasterror();
173
+			$this->error = "Error ".$this->db->lasterror();
174 174
 			return -1;
175 175
 		}
176 176
 	}
@@ -183,30 +183,30 @@  discard block
 block discarded – undo
183 183
 	 * @param   int		$notrigger	    0=no, 1=yes (no update trigger)
184 184
 	 * @return  int         			<0 if KO, >0 if OK
185 185
 	 */
186
-	function update($user=null, $notrigger=0)
186
+	function update($user = null, $notrigger = 0)
187 187
 	{
188 188
 		global $conf, $langs;
189 189
 
190 190
 		// Clean parameters
191
-		$this->id=trim($this->id);
192
-		$this->type=trim($this->type);
193
-		$this->description=trim($this->description);
191
+		$this->id = trim($this->id);
192
+		$this->type = trim($this->type);
193
+		$this->description = trim($this->description);
194 194
 
195 195
 		// Check parameters
196 196
 		// Put here code to add control on parameters values
197 197
 
198 198
 		// Update request
199 199
 		$sql = "UPDATE ".MAIN_DB_PREFIX."events SET";
200
-		$sql.= " type='".$this->db->escape($this->type)."',";
201
-		$sql.= " dateevent='".$this->db->idate($this->dateevent)."',";
202
-		$sql.= " description='".$this->db->escape($this->description)."'";
203
-		$sql.= " WHERE rowid=".$this->id;
200
+		$sql .= " type='".$this->db->escape($this->type)."',";
201
+		$sql .= " dateevent='".$this->db->idate($this->dateevent)."',";
202
+		$sql .= " description='".$this->db->escape($this->description)."'";
203
+		$sql .= " WHERE rowid=".$this->id;
204 204
 
205 205
 		dol_syslog(get_class($this)."::update", LOG_DEBUG);
206 206
 		$resql = $this->db->query($sql);
207
-		if (! $resql)
207
+		if (!$resql)
208 208
 		{
209
-			$this->error="Error ".$this->db->lasterror();
209
+			$this->error = "Error ".$this->db->lasterror();
210 210
 			return -1;
211 211
 		}
212 212
 		return 1;
@@ -220,31 +220,31 @@  discard block
 block discarded – undo
220 220
 	 *  @param  User	$user       User that load
221 221
 	 *  @return int         		<0 if KO, >0 if OK
222 222
 	 */
223
-	function fetch($id, $user=null)
223
+	function fetch($id, $user = null)
224 224
 	{
225 225
 		global $langs;
226 226
 
227 227
 		$sql = "SELECT";
228
-		$sql.= " t.rowid,";
229
-		$sql.= " t.tms,";
230
-		$sql.= " t.type,";
231
-		$sql.= " t.entity,";
232
-		$sql.= " t.dateevent,";
233
-		$sql.= " t.description,";
234
-		$sql.= " t.ip,";
235
-		$sql.= " t.user_agent";
236
-		$sql.= " FROM ".MAIN_DB_PREFIX."events as t";
237
-		$sql.= " WHERE t.rowid = ".$id;
228
+		$sql .= " t.rowid,";
229
+		$sql .= " t.tms,";
230
+		$sql .= " t.type,";
231
+		$sql .= " t.entity,";
232
+		$sql .= " t.dateevent,";
233
+		$sql .= " t.description,";
234
+		$sql .= " t.ip,";
235
+		$sql .= " t.user_agent";
236
+		$sql .= " FROM ".MAIN_DB_PREFIX."events as t";
237
+		$sql .= " WHERE t.rowid = ".$id;
238 238
 
239 239
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
240
-		$resql=$this->db->query($sql);
240
+		$resql = $this->db->query($sql);
241 241
 		if ($resql)
242 242
 		{
243 243
 			if ($this->db->num_rows($resql))
244 244
 			{
245 245
 				$obj = $this->db->fetch_object($resql);
246 246
 
247
-				$this->id    = $obj->rowid;
247
+				$this->id = $obj->rowid;
248 248
 				$this->tms = $this->db->jdate($obj->tms);
249 249
 				$this->type = $obj->type;
250 250
 				$this->entity = $obj->entity;
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 		}
260 260
 		else
261 261
 		{
262
-			$this->error="Error ".$this->db->lasterror();
262
+			$this->error = "Error ".$this->db->lasterror();
263 263
 			return -1;
264 264
 		}
265 265
 	}
@@ -276,13 +276,13 @@  discard block
 block discarded – undo
276 276
 		global $conf, $langs;
277 277
 
278 278
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."events";
279
-		$sql.= " WHERE rowid=".$this->id;
279
+		$sql .= " WHERE rowid=".$this->id;
280 280
 
281 281
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
282 282
 		$resql = $this->db->query($sql);
283
-		if (! $resql)
283
+		if (!$resql)
284 284
 		{
285
-			$this->error="Error ".$this->db->lasterror();
285
+			$this->error = "Error ".$this->db->lasterror();
286 286
 			return -1;
287 287
 		}
288 288
 
@@ -299,11 +299,11 @@  discard block
 block discarded – undo
299 299
 	 */
300 300
 	function initAsSpecimen()
301 301
 	{
302
-		$this->id=0;
302
+		$this->id = 0;
303 303
 
304
-		$this->tms=time();
305
-		$this->type='';
306
-		$this->dateevent=time();
307
-		$this->description='This is a specimen event';
304
+		$this->tms = time();
305
+		$this->type = '';
306
+		$this->dateevent = time();
307
+		$this->description = 'This is a specimen event';
308 308
 	}
309 309
 }
Please login to merge, or discard this patch.
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -137,7 +137,9 @@  discard block
 block discarded – undo
137 137
 
138 138
 		// Clean parameters
139 139
 		$this->description=trim($this->description);
140
-		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
140
+		if (empty($this->user_agent) && !empty($_SERVER['HTTP_USER_AGENT'])) {
141
+		    $this->user_agent=$_SERVER['HTTP_USER_AGENT'];
142
+		}
141 143
 
142 144
 		// Check parameters
143 145
 		if (empty($this->description)) { $this->error='ErrorBadValueForParameterCreateEventDesc'; return -1; }
@@ -167,8 +169,7 @@  discard block
 block discarded – undo
167 169
 		{
168 170
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events");
169 171
 			return $this->id;
170
-		}
171
-		else
172
+		} else
172 173
 		{
173 174
 			$this->error="Error ".$this->db->lasterror();
174 175
 			return -1;
@@ -256,8 +257,7 @@  discard block
 block discarded – undo
256 257
 			$this->db->free($resql);
257 258
 
258 259
 			return 1;
259
-		}
260
-		else
260
+		} else
261 261
 		{
262 262
 			$this->error="Error ".$this->db->lasterror();
263 263
 			return -1;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/ctyperesource.class.php 3 patches
Indentation   +418 added lines, -418 removed lines patch added patch discarded remove patch
@@ -32,436 +32,436 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class Ctyperesource
34 34
 {
35
-	/**
36
-	 * @var string Id to identify managed objects
37
-	 */
38
-	public $element = 'ctyperesource';
35
+    /**
36
+     * @var string Id to identify managed objects
37
+     */
38
+    public $element = 'ctyperesource';
39 39
 
40
-	/**
41
-	 * @var string Name of table without prefix where object is stored
42
-	 */
43
-	public $table_element = 'c_type_resource';
40
+    /**
41
+     * @var string Name of table without prefix where object is stored
42
+     */
43
+    public $table_element = 'c_type_resource';
44 44
 
45
-	/**
46
-	 * @var CtyperesourceLine[] Lines
47
-	 */
48
-	public $lines = array();
45
+    /**
46
+     * @var CtyperesourceLine[] Lines
47
+     */
48
+    public $lines = array();
49 49
 
50
-	public $code;
50
+    public $code;
51 51
 
52
-	/**
52
+    /**
53 53
      * @var string Type resource label
54 54
      */
55 55
     public $label;
56 56
 
57
-	public $active;
57
+    public $active;
58
+
59
+
60
+    /**
61
+     * Constructor
62
+     *
63
+     * @param DoliDb $db Database handler
64
+     */
65
+    public function __construct(DoliDB $db)
66
+    {
67
+        $this->db = $db;
68
+    }
69
+
70
+    /**
71
+     * Create object into database
72
+     *
73
+     * @param  User $user      User that creates
74
+     * @param  bool $notrigger false=launch triggers after, true=disable triggers
75
+     *
76
+     * @return int <0 if KO, Id of created object if OK
77
+     */
78
+    public function create(User $user, $notrigger = false)
79
+    {
80
+        dol_syslog(__METHOD__, LOG_DEBUG);
81
+
82
+        $error = 0;
83
+
84
+        // Clean parameters
85
+
86
+        if (isset($this->code)) {
87
+                $this->code = trim($this->code);
88
+        }
89
+        if (isset($this->label)) {
90
+                $this->label = trim($this->label);
91
+        }
92
+        if (isset($this->active)) {
93
+                $this->active = trim($this->active);
94
+        }
95
+
58 96
 
59 97
 
60
-	/**
61
-	 * Constructor
62
-	 *
63
-	 * @param DoliDb $db Database handler
64
-	 */
65
-	public function __construct(DoliDB $db)
66
-	{
67
-		$this->db = $db;
68
-	}
98
+        // Check parameters
99
+        // Put here code to add control on parameters values
69 100
 
70
-	/**
71
-	 * Create object into database
72
-	 *
73
-	 * @param  User $user      User that creates
74
-	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
75
-	 *
76
-	 * @return int <0 if KO, Id of created object if OK
77
-	 */
78
-	public function create(User $user, $notrigger = false)
79
-	{
80
-		dol_syslog(__METHOD__, LOG_DEBUG);
101
+        // Insert request
102
+        $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
81 103
 
82
-		$error = 0;
104
+        $sql.= 'code,';
105
+        $sql.= 'label';
106
+        $sql.= 'active';
83 107
 
84
-		// Clean parameters
85 108
 
86
-		if (isset($this->code)) {
87
-			 $this->code = trim($this->code);
88
-		}
89
-		if (isset($this->label)) {
90
-			 $this->label = trim($this->label);
91
-		}
92
-		if (isset($this->active)) {
93
-			 $this->active = trim($this->active);
94
-		}
109
+        $sql .= ') VALUES (';
95 110
 
111
+        $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").',';
112
+        $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
113
+        $sql .= ' '.(! isset($this->active)?'NULL':$this->active);
96 114
 
97 115
 
98
-		// Check parameters
99
-		// Put here code to add control on parameters values
116
+        $sql .= ')';
100 117
 
101
-		// Insert request
102
-		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
118
+        $this->db->begin();
103 119
 
104
-		$sql.= 'code,';
105
-		$sql.= 'label';
106
-		$sql.= 'active';
120
+        $resql = $this->db->query($sql);
121
+        if (!$resql) {
122
+            $error ++;
123
+            $this->errors[] = 'Error ' . $this->db->lasterror();
124
+            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
125
+        }
107 126
 
127
+        if (!$error) {
128
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
108 129
 
109
-		$sql .= ') VALUES (';
130
+            // Uncomment this and change MYOBJECT to your own tag if you
131
+            // want this action to call a trigger.
132
+            //if (!$notrigger) {
110 133
 
111
-		$sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").',';
112
-		$sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
113
-		$sql .= ' '.(! isset($this->active)?'NULL':$this->active);
134
+            //  // Call triggers
135
+            //  $result=$this->call_trigger('MYOBJECT_CREATE',$user);
136
+            //  if ($result < 0) $error++;
137
+            //  // End call triggers
138
+            //}
139
+        }
114 140
 
141
+        // Commit or rollback
142
+        if ($error) {
143
+            $this->db->rollback();
115 144
 
116
-		$sql .= ')';
145
+            return - 1 * $error;
146
+        } else {
147
+            $this->db->commit();
117 148
 
118
-		$this->db->begin();
119
-
120
-		$resql = $this->db->query($sql);
121
-		if (!$resql) {
122
-			$error ++;
123
-			$this->errors[] = 'Error ' . $this->db->lasterror();
124
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
125
-		}
126
-
127
-		if (!$error) {
128
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
129
-
130
-			// Uncomment this and change MYOBJECT to your own tag if you
131
-			// want this action to call a trigger.
132
-			//if (!$notrigger) {
133
-
134
-			//  // Call triggers
135
-			//  $result=$this->call_trigger('MYOBJECT_CREATE',$user);
136
-			//  if ($result < 0) $error++;
137
-			//  // End call triggers
138
-			//}
139
-		}
140
-
141
-		// Commit or rollback
142
-		if ($error) {
143
-			$this->db->rollback();
144
-
145
-			return - 1 * $error;
146
-		} else {
147
-			$this->db->commit();
148
-
149
-			return $this->id;
150
-		}
151
-	}
152
-
153
-	/**
154
-	 * Load object in memory from the database
155
-	 *
156
-	 * @param int    $id  Id object
157
-	 * @param string $code code
158
-	 * @param string $label Label
159
-	 *
160
-	 * @return int <0 if KO, 0 if not found, >0 if OK
161
-	 */
162
-	public function fetch($id,$code='',$label='')
163
-	{
164
-		dol_syslog(__METHOD__, LOG_DEBUG);
165
-
166
-		$sql = 'SELECT';
167
-		$sql .= ' t.rowid,';
168
-
169
-		$sql .= " t.code,";
170
-		$sql .= " t.label,";
171
-		$sql .= " t.active";
172
-
173
-
174
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
175
-		if ($id)   $sql.= " WHERE t.id = ".$id;
176
-		elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
177
-		elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
178
-
179
-
180
-		$resql = $this->db->query($sql);
181
-		if ($resql) {
182
-			$numrows = $this->db->num_rows($resql);
183
-			if ($numrows) {
184
-				$obj = $this->db->fetch_object($resql);
185
-
186
-				$this->id = $obj->rowid;
187
-
188
-				$this->code = $obj->code;
189
-				$this->label = $obj->label;
190
-				$this->active = $obj->active;
191
-			}
192
-
193
-			// Retrieve all extrafields for invoice
194
-			// fetch optionals attributes and labels
195
-			// $this->fetch_optionals();
196
-
197
-			// $this->fetch_lines();
198
-
199
-			$this->db->free($resql);
200
-
201
-			if ($numrows) {
202
-				return 1;
203
-			} else {
204
-				return 0;
205
-			}
206
-		} else {
207
-			$this->errors[] = 'Error ' . $this->db->lasterror();
208
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
209
-
210
-			return - 1;
211
-		}
212
-	}
213
-
214
-	/**
215
-	 * Load object in memory from the database
216
-	 *
217
-	 * @param string $sortorder Sort Order
218
-	 * @param string $sortfield Sort field
219
-	 * @param int    $limit     offset limit
220
-	 * @param int    $offset    offset limit
221
-	 * @param array  $filter    filter array
222
-	 * @param string $filtermode filter mode (AND or OR)
223
-	 *
224
-	 * @return int <0 if KO, >0 if OK
225
-	 */
226
-	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
227
-	{
228
-		dol_syslog(__METHOD__, LOG_DEBUG);
229
-
230
-		$sql = 'SELECT';
231
-		$sql .= ' t.rowid,';
232
-
233
-		$sql .= " t.code,";
234
-		$sql .= " t.label,";
235
-		$sql .= " t.active";
236
-
237
-
238
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
239
-
240
-		// Manage filter
241
-		$sqlwhere = array();
242
-		if (count($filter) > 0) {
243
-			foreach ($filter as $key => $value) {
244
-				$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
245
-			}
246
-		}
247
-
248
-		if (count($sqlwhere) > 0) {
249
-			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
250
-		}
251
-		if (!empty($sortfield)) {
252
-			$sql .= $this->db->order($sortfield,$sortorder);
253
-		}
254
-		if (!empty($limit)) {
255
-		 $sql .=  ' ' . $this->db->plimit($limit, $offset);
256
-		}
257
-
258
-		$resql = $this->db->query($sql);
259
-		if ($resql) {
260
-			$num = $this->db->num_rows($resql);
261
-
262
-			while ($obj = $this->db->fetch_object($resql)) {
263
-				$line = new self($this->db);
264
-
265
-				$line->id = $obj->rowid;
266
-
267
-				$line->code = $obj->code;
268
-				$line->label = $obj->label;
269
-				$line->active = $obj->active;
270
-			}
271
-			$this->db->free($resql);
272
-
273
-			return $num;
274
-		} else {
275
-			$this->errors[] = 'Error ' . $this->db->lasterror();
276
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
277
-
278
-			return - 1;
279
-		}
280
-	}
281
-
282
-	/**
283
-	 * Update object into database
284
-	 *
285
-	 * @param  User $user      User that modifies
286
-	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
287
-	 *
288
-	 * @return int <0 if KO, >0 if OK
289
-	 */
290
-	public function update(User $user, $notrigger = false)
291
-	{
292
-		$error = 0;
293
-
294
-		dol_syslog(__METHOD__, LOG_DEBUG);
295
-
296
-		// Clean parameters
297
-
298
-		if (isset($this->code)) {
299
-			 $this->code = trim($this->code);
300
-		}
301
-		if (isset($this->label)) {
302
-			 $this->label = trim($this->label);
303
-		}
304
-		if (isset($this->active)) {
305
-			 $this->active = trim($this->active);
306
-		}
307
-
308
-		// Check parameters
309
-		// Put here code to add a control on parameters values
310
-
311
-		// Update request
312
-		$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
313
-
314
-		$sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").',';
315
-		$sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
316
-		$sql .= ' active = '.(isset($this->active)?$this->active:"null");
317
-
318
-
319
-		$sql .= ' WHERE rowid=' . $this->id;
320
-
321
-		$this->db->begin();
322
-
323
-		$resql = $this->db->query($sql);
324
-		if (!$resql) {
325
-			$error ++;
326
-			$this->errors[] = 'Error ' . $this->db->lasterror();
327
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
328
-		}
329
-
330
-		// Uncomment this and change MYOBJECT to your own tag if you
331
-		// want this action calls a trigger.
332
-		//if (!$error && !$notrigger) {
333
-
334
-		//  // Call triggers
335
-		//  $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
336
-		//  if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
337
-		//  // End call triggers
338
-		//}
339
-
340
-		// Commit or rollback
341
-		if ($error) {
342
-			$this->db->rollback();
343
-
344
-			return - 1 * $error;
345
-		} else {
346
-			$this->db->commit();
347
-
348
-			return 1;
349
-		}
350
-	}
351
-
352
-	/**
353
-	 * Delete object in database
354
-	 *
355
-	 * @param User $user      User that deletes
356
-	 * @param bool $notrigger false=launch triggers after, true=disable triggers
357
-	 *
358
-	 * @return int <0 if KO, >0 if OK
359
-	 */
360
-	public function delete(User $user, $notrigger = false)
361
-	{
362
-		dol_syslog(__METHOD__, LOG_DEBUG);
363
-
364
-		$error = 0;
365
-
366
-		$this->db->begin();
367
-
368
-		// Uncomment this and change MYOBJECT to your own tag if you
369
-		// want this action calls a trigger.
370
-		//if (!$error && !$notrigger) {
371
-
372
-		//  // Call triggers
373
-		//  $result=$this->call_trigger('MYOBJECT_DELETE',$user);
374
-		//  if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
375
-		//  // End call triggers
376
-		//}
377
-
378
-		// If you need to delete child tables to, you can insert them here
379
-
380
-		if (!$error) {
381
-			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
382
-			$sql .= ' WHERE rowid=' . $this->id;
383
-
384
-			$resql = $this->db->query($sql);
385
-			if (!$resql) {
386
-				$error ++;
387
-				$this->errors[] = 'Error ' . $this->db->lasterror();
388
-				dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
389
-			}
390
-		}
391
-
392
-		// Commit or rollback
393
-		if ($error) {
394
-			$this->db->rollback();
395
-
396
-			return - 1 * $error;
397
-		} else {
398
-			$this->db->commit();
399
-
400
-			return 1;
401
-		}
402
-	}
403
-
404
-	/**
405
-	 * Load an object from its id and create a new one in database
406
-	 *
407
-	 * @param int $fromid Id of object to clone
408
-	 *
409
-	 * @return int New id of clone
410
-	 */
411
-	public function createFromClone($fromid)
412
-	{
413
-		dol_syslog(__METHOD__, LOG_DEBUG);
414
-
415
-		global $user;
416
-		$error = 0;
417
-		$object = new Ctyperesource($this->db);
418
-
419
-		$this->db->begin();
420
-
421
-		// Load source object
422
-		$object->fetch($fromid);
423
-		// Reset object
424
-		$object->id = 0;
425
-
426
-		// Clear fields
427
-		// ...
428
-
429
-		// Create clone
430
-		$result = $object->create($user);
431
-
432
-		// Other options
433
-		if ($result < 0) {
434
-			$error ++;
435
-			$this->errors = $object->errors;
436
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
437
-		}
438
-
439
-		// End
440
-		if (!$error) {
441
-			$this->db->commit();
442
-
443
-			return $object->id;
444
-		} else {
445
-			$this->db->rollback();
446
-
447
-			return - 1;
448
-		}
449
-	}
450
-
451
-	/**
452
-	 * Initialise object with example values
453
-	 * Id must be 0 if object instance is a specimen
454
-	 *
455
-	 * @return void
456
-	 */
457
-	public function initAsSpecimen()
458
-	{
459
-		$this->id = 0;
460
-
461
-		$this->code = '';
462
-		$this->label = '';
463
-		$this->active = '';
464
-	}
149
+            return $this->id;
150
+        }
151
+    }
152
+
153
+    /**
154
+     * Load object in memory from the database
155
+     *
156
+     * @param int    $id  Id object
157
+     * @param string $code code
158
+     * @param string $label Label
159
+     *
160
+     * @return int <0 if KO, 0 if not found, >0 if OK
161
+     */
162
+    public function fetch($id,$code='',$label='')
163
+    {
164
+        dol_syslog(__METHOD__, LOG_DEBUG);
165
+
166
+        $sql = 'SELECT';
167
+        $sql .= ' t.rowid,';
168
+
169
+        $sql .= " t.code,";
170
+        $sql .= " t.label,";
171
+        $sql .= " t.active";
172
+
173
+
174
+        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
175
+        if ($id)   $sql.= " WHERE t.id = ".$id;
176
+        elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
177
+        elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
178
+
179
+
180
+        $resql = $this->db->query($sql);
181
+        if ($resql) {
182
+            $numrows = $this->db->num_rows($resql);
183
+            if ($numrows) {
184
+                $obj = $this->db->fetch_object($resql);
185
+
186
+                $this->id = $obj->rowid;
187
+
188
+                $this->code = $obj->code;
189
+                $this->label = $obj->label;
190
+                $this->active = $obj->active;
191
+            }
192
+
193
+            // Retrieve all extrafields for invoice
194
+            // fetch optionals attributes and labels
195
+            // $this->fetch_optionals();
196
+
197
+            // $this->fetch_lines();
198
+
199
+            $this->db->free($resql);
200
+
201
+            if ($numrows) {
202
+                return 1;
203
+            } else {
204
+                return 0;
205
+            }
206
+        } else {
207
+            $this->errors[] = 'Error ' . $this->db->lasterror();
208
+            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
209
+
210
+            return - 1;
211
+        }
212
+    }
213
+
214
+    /**
215
+     * Load object in memory from the database
216
+     *
217
+     * @param string $sortorder Sort Order
218
+     * @param string $sortfield Sort field
219
+     * @param int    $limit     offset limit
220
+     * @param int    $offset    offset limit
221
+     * @param array  $filter    filter array
222
+     * @param string $filtermode filter mode (AND or OR)
223
+     *
224
+     * @return int <0 if KO, >0 if OK
225
+     */
226
+    public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
227
+    {
228
+        dol_syslog(__METHOD__, LOG_DEBUG);
229
+
230
+        $sql = 'SELECT';
231
+        $sql .= ' t.rowid,';
232
+
233
+        $sql .= " t.code,";
234
+        $sql .= " t.label,";
235
+        $sql .= " t.active";
236
+
237
+
238
+        $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
239
+
240
+        // Manage filter
241
+        $sqlwhere = array();
242
+        if (count($filter) > 0) {
243
+            foreach ($filter as $key => $value) {
244
+                $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
245
+            }
246
+        }
247
+
248
+        if (count($sqlwhere) > 0) {
249
+            $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
250
+        }
251
+        if (!empty($sortfield)) {
252
+            $sql .= $this->db->order($sortfield,$sortorder);
253
+        }
254
+        if (!empty($limit)) {
255
+            $sql .=  ' ' . $this->db->plimit($limit, $offset);
256
+        }
257
+
258
+        $resql = $this->db->query($sql);
259
+        if ($resql) {
260
+            $num = $this->db->num_rows($resql);
261
+
262
+            while ($obj = $this->db->fetch_object($resql)) {
263
+                $line = new self($this->db);
264
+
265
+                $line->id = $obj->rowid;
266
+
267
+                $line->code = $obj->code;
268
+                $line->label = $obj->label;
269
+                $line->active = $obj->active;
270
+            }
271
+            $this->db->free($resql);
272
+
273
+            return $num;
274
+        } else {
275
+            $this->errors[] = 'Error ' . $this->db->lasterror();
276
+            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
277
+
278
+            return - 1;
279
+        }
280
+    }
281
+
282
+    /**
283
+     * Update object into database
284
+     *
285
+     * @param  User $user      User that modifies
286
+     * @param  bool $notrigger false=launch triggers after, true=disable triggers
287
+     *
288
+     * @return int <0 if KO, >0 if OK
289
+     */
290
+    public function update(User $user, $notrigger = false)
291
+    {
292
+        $error = 0;
293
+
294
+        dol_syslog(__METHOD__, LOG_DEBUG);
295
+
296
+        // Clean parameters
297
+
298
+        if (isset($this->code)) {
299
+                $this->code = trim($this->code);
300
+        }
301
+        if (isset($this->label)) {
302
+                $this->label = trim($this->label);
303
+        }
304
+        if (isset($this->active)) {
305
+                $this->active = trim($this->active);
306
+        }
307
+
308
+        // Check parameters
309
+        // Put here code to add a control on parameters values
310
+
311
+        // Update request
312
+        $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
313
+
314
+        $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").',';
315
+        $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
316
+        $sql .= ' active = '.(isset($this->active)?$this->active:"null");
317
+
318
+
319
+        $sql .= ' WHERE rowid=' . $this->id;
320
+
321
+        $this->db->begin();
322
+
323
+        $resql = $this->db->query($sql);
324
+        if (!$resql) {
325
+            $error ++;
326
+            $this->errors[] = 'Error ' . $this->db->lasterror();
327
+            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
328
+        }
329
+
330
+        // Uncomment this and change MYOBJECT to your own tag if you
331
+        // want this action calls a trigger.
332
+        //if (!$error && !$notrigger) {
333
+
334
+        //  // Call triggers
335
+        //  $result=$this->call_trigger('MYOBJECT_MODIFY',$user);
336
+        //  if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
337
+        //  // End call triggers
338
+        //}
339
+
340
+        // Commit or rollback
341
+        if ($error) {
342
+            $this->db->rollback();
343
+
344
+            return - 1 * $error;
345
+        } else {
346
+            $this->db->commit();
347
+
348
+            return 1;
349
+        }
350
+    }
351
+
352
+    /**
353
+     * Delete object in database
354
+     *
355
+     * @param User $user      User that deletes
356
+     * @param bool $notrigger false=launch triggers after, true=disable triggers
357
+     *
358
+     * @return int <0 if KO, >0 if OK
359
+     */
360
+    public function delete(User $user, $notrigger = false)
361
+    {
362
+        dol_syslog(__METHOD__, LOG_DEBUG);
363
+
364
+        $error = 0;
365
+
366
+        $this->db->begin();
367
+
368
+        // Uncomment this and change MYOBJECT to your own tag if you
369
+        // want this action calls a trigger.
370
+        //if (!$error && !$notrigger) {
371
+
372
+        //  // Call triggers
373
+        //  $result=$this->call_trigger('MYOBJECT_DELETE',$user);
374
+        //  if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail}
375
+        //  // End call triggers
376
+        //}
377
+
378
+        // If you need to delete child tables to, you can insert them here
379
+
380
+        if (!$error) {
381
+            $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
382
+            $sql .= ' WHERE rowid=' . $this->id;
383
+
384
+            $resql = $this->db->query($sql);
385
+            if (!$resql) {
386
+                $error ++;
387
+                $this->errors[] = 'Error ' . $this->db->lasterror();
388
+                dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
389
+            }
390
+        }
391
+
392
+        // Commit or rollback
393
+        if ($error) {
394
+            $this->db->rollback();
395
+
396
+            return - 1 * $error;
397
+        } else {
398
+            $this->db->commit();
399
+
400
+            return 1;
401
+        }
402
+    }
403
+
404
+    /**
405
+     * Load an object from its id and create a new one in database
406
+     *
407
+     * @param int $fromid Id of object to clone
408
+     *
409
+     * @return int New id of clone
410
+     */
411
+    public function createFromClone($fromid)
412
+    {
413
+        dol_syslog(__METHOD__, LOG_DEBUG);
414
+
415
+        global $user;
416
+        $error = 0;
417
+        $object = new Ctyperesource($this->db);
418
+
419
+        $this->db->begin();
420
+
421
+        // Load source object
422
+        $object->fetch($fromid);
423
+        // Reset object
424
+        $object->id = 0;
425
+
426
+        // Clear fields
427
+        // ...
428
+
429
+        // Create clone
430
+        $result = $object->create($user);
431
+
432
+        // Other options
433
+        if ($result < 0) {
434
+            $error ++;
435
+            $this->errors = $object->errors;
436
+            dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
437
+        }
438
+
439
+        // End
440
+        if (!$error) {
441
+            $this->db->commit();
442
+
443
+            return $object->id;
444
+        } else {
445
+            $this->db->rollback();
446
+
447
+            return - 1;
448
+        }
449
+    }
450
+
451
+    /**
452
+     * Initialise object with example values
453
+     * Id must be 0 if object instance is a specimen
454
+     *
455
+     * @return void
456
+     */
457
+    public function initAsSpecimen()
458
+    {
459
+        $this->id = 0;
460
+
461
+        $this->code = '';
462
+        $this->label = '';
463
+        $this->active = '';
464
+    }
465 465
 }
466 466
 
467 467
 /**
@@ -469,24 +469,24 @@  discard block
 block discarded – undo
469 469
  */
470 470
 class CtyperesourceLine
471 471
 {
472
-	/**
473
-	 * @var int ID
474
-	 */
475
-	public $id;
472
+    /**
473
+     * @var int ID
474
+     */
475
+    public $id;
476 476
 
477
-	/**
478
-	 * @var mixed Sample line property 1
479
-	 */
480
-	public $code;
477
+    /**
478
+     * @var mixed Sample line property 1
479
+     */
480
+    public $code;
481 481
 
482
-	/**
482
+    /**
483 483
      * @var string Type resource line label
484 484
      */
485 485
     public $label;
486 486
 
487
-	public $active;
487
+    public $active;
488 488
 
489
-	/**
490
-	 * @var mixed Sample line property 2
491
-	 */
489
+    /**
490
+     * @var mixed Sample line property 2
491
+     */
492 492
 }
Please login to merge, or discard this patch.
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -99,18 +99,18 @@  discard block
 block discarded – undo
99 99
 		// Put here code to add control on parameters values
100 100
 
101 101
 		// Insert request
102
-		$sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '(';
102
+		$sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'(';
103 103
 
104
-		$sql.= 'code,';
105
-		$sql.= 'label';
106
-		$sql.= 'active';
104
+		$sql .= 'code,';
105
+		$sql .= 'label';
106
+		$sql .= 'active';
107 107
 
108 108
 
109 109
 		$sql .= ') VALUES (';
110 110
 
111
-		$sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").',';
112
-		$sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").',';
113
-		$sql .= ' '.(! isset($this->active)?'NULL':$this->active);
111
+		$sql .= ' '.(!isset($this->code) ? 'NULL' : "'".$this->db->escape($this->code)."'").',';
112
+		$sql .= ' '.(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'").',';
113
+		$sql .= ' '.(!isset($this->active) ? 'NULL' : $this->active);
114 114
 
115 115
 
116 116
 		$sql .= ')';
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 
120 120
 		$resql = $this->db->query($sql);
121 121
 		if (!$resql) {
122
-			$error ++;
123
-			$this->errors[] = 'Error ' . $this->db->lasterror();
124
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
122
+			$error++;
123
+			$this->errors[] = 'Error '.$this->db->lasterror();
124
+			dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
125 125
 		}
126 126
 
127 127
 		if (!$error) {
128
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element);
128
+			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
129 129
 
130 130
 			// Uncomment this and change MYOBJECT to your own tag if you
131 131
 			// want this action to call a trigger.
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		if ($error) {
143 143
 			$this->db->rollback();
144 144
 
145
-			return - 1 * $error;
145
+			return -1 * $error;
146 146
 		} else {
147 147
 			$this->db->commit();
148 148
 
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @return int <0 if KO, 0 if not found, >0 if OK
161 161
 	 */
162
-	public function fetch($id,$code='',$label='')
162
+	public function fetch($id, $code = '', $label = '')
163 163
 	{
164 164
 		dol_syslog(__METHOD__, LOG_DEBUG);
165 165
 
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 		$sql .= " t.active";
172 172
 
173 173
 
174
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
175
-		if ($id)   $sql.= " WHERE t.id = ".$id;
176
-		elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
177
-		elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
174
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
175
+		if ($id)   $sql .= " WHERE t.id = ".$id;
176
+		elseif ($code) $sql .= " WHERE t.code = '".$this->db->escape($code)."'";
177
+		elseif ($label) $sql .= " WHERE t.label = '".$this->db->escape($label)."'";
178 178
 
179 179
 
180 180
 		$resql = $this->db->query($sql);
@@ -204,10 +204,10 @@  discard block
 block discarded – undo
204 204
 				return 0;
205 205
 			}
206 206
 		} else {
207
-			$this->errors[] = 'Error ' . $this->db->lasterror();
208
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
207
+			$this->errors[] = 'Error '.$this->db->lasterror();
208
+			dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
209 209
 
210
-			return - 1;
210
+			return -1;
211 211
 		}
212 212
 	}
213 213
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 	 *
224 224
 	 * @return int <0 if KO, >0 if OK
225 225
 	 */
226
-	public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND')
226
+	public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
227 227
 	{
228 228
 		dol_syslog(__METHOD__, LOG_DEBUG);
229 229
 
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
 		$sql .= " t.active";
236 236
 
237 237
 
238
-		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t';
238
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
239 239
 
240 240
 		// Manage filter
241 241
 		$sqlwhere = array();
242 242
 		if (count($filter) > 0) {
243 243
 			foreach ($filter as $key => $value) {
244
-				$sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
244
+				$sqlwhere [] = $key.' LIKE \'%'.$this->db->escape($value).'%\'';
245 245
 			}
246 246
 		}
247 247
 
248 248
 		if (count($sqlwhere) > 0) {
249
-			$sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere);
249
+			$sql .= ' WHERE '.implode(' '.$filtermode.' ', $sqlwhere);
250 250
 		}
251 251
 		if (!empty($sortfield)) {
252
-			$sql .= $this->db->order($sortfield,$sortorder);
252
+			$sql .= $this->db->order($sortfield, $sortorder);
253 253
 		}
254 254
 		if (!empty($limit)) {
255
-		 $sql .=  ' ' . $this->db->plimit($limit, $offset);
255
+		 $sql .= ' '.$this->db->plimit($limit, $offset);
256 256
 		}
257 257
 
258 258
 		$resql = $this->db->query($sql);
@@ -272,10 +272,10 @@  discard block
 block discarded – undo
272 272
 
273 273
 			return $num;
274 274
 		} else {
275
-			$this->errors[] = 'Error ' . $this->db->lasterror();
276
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
275
+			$this->errors[] = 'Error '.$this->db->lasterror();
276
+			dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
277 277
 
278
-			return - 1;
278
+			return -1;
279 279
 		}
280 280
 	}
281 281
 
@@ -309,22 +309,22 @@  discard block
 block discarded – undo
309 309
 		// Put here code to add a control on parameters values
310 310
 
311 311
 		// Update request
312
-		$sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET';
312
+		$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET';
313 313
 
314
-		$sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").',';
315
-		$sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").',';
316
-		$sql .= ' active = '.(isset($this->active)?$this->active:"null");
314
+		$sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").',';
315
+		$sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").',';
316
+		$sql .= ' active = '.(isset($this->active) ? $this->active : "null");
317 317
 
318 318
 
319
-		$sql .= ' WHERE rowid=' . $this->id;
319
+		$sql .= ' WHERE rowid='.$this->id;
320 320
 
321 321
 		$this->db->begin();
322 322
 
323 323
 		$resql = $this->db->query($sql);
324 324
 		if (!$resql) {
325
-			$error ++;
326
-			$this->errors[] = 'Error ' . $this->db->lasterror();
327
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
325
+			$error++;
326
+			$this->errors[] = 'Error '.$this->db->lasterror();
327
+			dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
328 328
 		}
329 329
 
330 330
 		// Uncomment this and change MYOBJECT to your own tag if you
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
 		if ($error) {
342 342
 			$this->db->rollback();
343 343
 
344
-			return - 1 * $error;
344
+			return -1 * $error;
345 345
 		} else {
346 346
 			$this->db->commit();
347 347
 
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
 		// If you need to delete child tables to, you can insert them here
379 379
 
380 380
 		if (!$error) {
381
-			$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element;
382
-			$sql .= ' WHERE rowid=' . $this->id;
381
+			$sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element;
382
+			$sql .= ' WHERE rowid='.$this->id;
383 383
 
384 384
 			$resql = $this->db->query($sql);
385 385
 			if (!$resql) {
386
-				$error ++;
387
-				$this->errors[] = 'Error ' . $this->db->lasterror();
388
-				dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
386
+				$error++;
387
+				$this->errors[] = 'Error '.$this->db->lasterror();
388
+				dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
389 389
 			}
390 390
 		}
391 391
 
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
 		if ($error) {
394 394
 			$this->db->rollback();
395 395
 
396
-			return - 1 * $error;
396
+			return -1 * $error;
397 397
 		} else {
398 398
 			$this->db->commit();
399 399
 
@@ -431,9 +431,9 @@  discard block
 block discarded – undo
431 431
 
432 432
 		// Other options
433 433
 		if ($result < 0) {
434
-			$error ++;
434
+			$error++;
435 435
 			$this->errors = $object->errors;
436
-			dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR);
436
+			dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
437 437
 		}
438 438
 
439 439
 		// End
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
 		} else {
445 445
 			$this->db->rollback();
446 446
 
447
-			return - 1;
447
+			return -1;
448 448
 		}
449 449
 	}
450 450
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -172,9 +172,13 @@
 block discarded – undo
172 172
 
173 173
 
174 174
 		$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
175
-		if ($id)   $sql.= " WHERE t.id = ".$id;
176
-		elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
177
-		elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
175
+		if ($id) {
176
+		    $sql.= " WHERE t.id = ".$id;
177
+		} elseif ($code) {
178
+		    $sql.= " WHERE t.code = '".$this->db->escape($code)."'";
179
+		} elseif ($label) {
180
+		    $sql.= " WHERE t.label = '".$this->db->escape($label)."'";
181
+		}
178 182
 
179 183
 
180 184
 		$resql = $this->db->query($sql);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formsms.class.php 3 patches
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     function show_form($morecss='titlefield', $showform=1)
104 104
     {
105
-     // phpcs:enable
105
+        // phpcs:enable
106 106
         global $conf, $langs, $user, $form;
107 107
 
108 108
         if (! is_object($form)) $form=new Form($this->db);
@@ -218,13 +218,13 @@  discard block
 block discarded – undo
218 218
                         $classname=ucfirst($classfile);
219 219
                         if (class_exists($classname))
220 220
                         {
221
-                        	$sms = new $classname($this->db);
222
-                        	$resultsender = $sms->SmsSenderList();
221
+                            $sms = new $classname($this->db);
222
+                            $resultsender = $sms->SmsSenderList();
223 223
                         }
224 224
                         else
225 225
                         {
226
-                        	$sms = new stdClass();
227
-                        	$sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
226
+                            $sms = new stdClass();
227
+                            $sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
228 228
                         }
229 229
                     }
230 230
                     catch(Exception $e)
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
                 else
237 237
                 {
238 238
                     dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
239
-	                $resultsender=array();
239
+                    $resultsender=array();
240 240
                     $resultsender[0]->number=$this->fromsms;
241 241
                 }
242 242
 
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
  *       \ingroup    core
23 23
  *       \brief      Fichier de la classe permettant la generation du formulaire html d'envoi de mail unitaire
24 24
  */
25
-require_once DOL_DOCUMENT_ROOT .'/core/class/html.form.class.php';
25
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php';
26 26
 
27 27
 
28 28
 /**
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     public $toname;
46 46
     public $tomail;
47 47
 
48
-    public $withsubstit;			// Show substitution array
48
+    public $withsubstit; // Show substitution array
49 49
     public $withfrom;
50 50
     public $withto;
51 51
     public $withtopic;
@@ -57,18 +57,18 @@  discard block
 block discarded – undo
57 57
     public $withtopicreadonly;
58 58
     public $withcancel;
59 59
 
60
-    public $substit=array();
61
-    public $param=array();
60
+    public $substit = array();
61
+    public $param = array();
62 62
 
63 63
     /**
64 64
      * @var string Error code (or message)
65 65
      */
66
-    public $error='';
66
+    public $error = '';
67 67
 
68 68
     /**
69 69
      * @var string[]	Array of error strings
70 70
      */
71
-    public $errors=array();
71
+    public $errors = array();
72 72
 
73 73
 
74 74
     /**
@@ -80,16 +80,16 @@  discard block
 block discarded – undo
80 80
     {
81 81
         $this->db = $db;
82 82
 
83
-        $this->withfrom=1;
84
-        $this->withto=1;
85
-        $this->withtopic=1;
86
-        $this->withbody=1;
83
+        $this->withfrom = 1;
84
+        $this->withto = 1;
85
+        $this->withtopic = 1;
86
+        $this->withbody = 1;
87 87
 
88
-        $this->withfromreadonly=1;
89
-        $this->withreplytoreadonly=1;
90
-        $this->withtoreadonly=0;
91
-        $this->withtopicreadonly=0;
92
-        $this->withbodyreadonly=0;
88
+        $this->withfromreadonly = 1;
89
+        $this->withreplytoreadonly = 1;
90
+        $this->withtoreadonly = 0;
91
+        $this->withtopicreadonly = 0;
92
+        $this->withbodyreadonly = 0;
93 93
     }
94 94
 
95 95
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -100,17 +100,17 @@  discard block
 block discarded – undo
100 100
      *  @param int $showform Show form tags and submit button (recommanded is to use with value 0)
101 101
      *	@return	void
102 102
      */
103
-    function show_form($morecss='titlefield', $showform=1)
103
+    function show_form($morecss = 'titlefield', $showform = 1)
104 104
     {
105 105
      // phpcs:enable
106 106
         global $conf, $langs, $user, $form;
107 107
 
108
-        if (! is_object($form)) $form=new Form($this->db);
108
+        if (!is_object($form)) $form = new Form($this->db);
109 109
 
110 110
         // Load translation files required by the page
111 111
         $langs->loadLangs(array('other', 'mails', 'sms'));
112 112
 
113
-        $soc=new Societe($this->db);
113
+        $soc = new Societe($this->db);
114 114
         if (!empty($this->withtosocid) && $this->withtosocid > 0)
115 115
         {
116 116
             $soc->fetch($this->withtosocid);
@@ -141,15 +141,15 @@  discard block
 block discarded – undo
141 141
         print "<table class=\"border centpercent\">\n";
142 142
 
143 143
         // Substitution array
144
-        if (! empty($this->withsubstit))		// Unset or set ->withsubstit=0 to disable this.
144
+        if (!empty($this->withsubstit))		// Unset or set ->withsubstit=0 to disable this.
145 145
         {
146 146
             print "<tr><td colspan=\"2\">";
147
-            $help="";
148
-            foreach($this->substit as $key => $val)
147
+            $help = "";
148
+            foreach ($this->substit as $key => $val)
149 149
             {
150
-                $help.=$key.' -> '.$langs->trans($val).'<br>';
150
+                $help .= $key.' -> '.$langs->trans($val).'<br>';
151 151
             }
152
-            print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"),$help);
152
+            print $form->textwithpicto($langs->trans("SmsTestSubstitutionReplacedByGenericValues"), $help);
153 153
             print "</td></tr>\n";
154 154
         }
155 155
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                 if ($this->fromtype == 'user')
165 165
                 {
166 166
                     $langs->load("users");
167
-                    $fuser=new User($this->db);
167
+                    $fuser = new User($this->db);
168 168
                     $fuser->fetch($this->fromid);
169 169
                     print $fuser->getNomUrl(1);
170 170
                     print ' &nbsp; ';
@@ -203,19 +203,19 @@  discard block
 block discarded – undo
203 203
                             $resultsender = $sms->SmsSenderList();
204 204
                         }
205 205
                     }
206
-                    catch(Exception $e)
206
+                    catch (Exception $e)
207 207
                     {
208
-                        dol_print_error('','Error to get list of senders: '.$e->getMessage());
208
+                        dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
209 209
                     }
210 210
                 }
211 211
                 else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
212 212
                 {
213
-                    $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
214
-                    $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
213
+                    $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE);
214
+                    $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
215 215
                     dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
216 216
                     try
217 217
                     {
218
-                        $classname=ucfirst($classfile);
218
+                        $classname = ucfirst($classfile);
219 219
                         if (class_exists($classname))
220 220
                         {
221 221
                         	$sms = new $classname($this->db);
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
                         else
225 225
                         {
226 226
                         	$sms = new stdClass();
227
-                        	$sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
227
+                        	$sms->error = 'The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
228 228
                         }
229 229
                     }
230
-                    catch(Exception $e)
230
+                    catch (Exception $e)
231 231
                     {
232
-                        dol_print_error('','Error to get list of senders: '.$e->getMessage());
232
+                        dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
233 233
                         exit;
234 234
                     }
235 235
                 }
236 236
                 else
237 237
                 {
238 238
                     dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
239
-	                $resultsender=array();
240
-                    $resultsender[0]->number=$this->fromsms;
239
+	                $resultsender = array();
240
+                    $resultsender[0]->number = $this->fromsms;
241 241
                 }
242 242
 
243 243
                 if (is_array($resultsender) && count($resultsender) > 0)
244 244
                 {
245 245
                     print '<select name="fromsms" id="fromsms" class="flat">';
246
-                    foreach($resultsender as $obj)
246
+                    foreach ($resultsender as $obj)
247 247
                     {
248 248
                         print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
249 249
                     }
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
                 else
253 253
                 {
254 254
                     print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
255
-                    if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
255
+                    if (is_object($sms) && !empty($sms->error)) print ' '.$sms->error;
256 256
                     print '</span>';
257 257
                 }
258 258
                 print '</td>';
@@ -265,22 +265,22 @@  discard block
 block discarded – undo
265 265
         {
266 266
             print '<tr><td>';
267 267
             //$moretext=$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients");
268
-            $moretext='';
269
-            print $form->textwithpicto($langs->trans("SmsTo"),$moretext);
268
+            $moretext = '';
269
+            print $form->textwithpicto($langs->trans("SmsTo"), $moretext);
270 270
             print '</td><td>';
271 271
             if ($this->withtoreadonly)
272 272
             {
273
-                print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
273
+                print (!is_array($this->withto) && !is_numeric($this->withto)) ? $this->withto : "";
274 274
             }
275 275
             else
276 276
             {
277
-                print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">";
278
-                if (! empty($this->withtosocid) && $this->withtosocid > 0)
277
+                print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(!is_array($this->withto) && $this->withto != '1' ? (isset($_REQUEST["sendto"]) ?GETPOST("sendto") : $this->withto) : "+")."\">";
278
+                if (!empty($this->withtosocid) && $this->withtosocid > 0)
279 279
                 {
280
-                    $liste=array();
280
+                    $liste = array();
281 281
                     foreach ($soc->thirdparty_and_contact_phone_array() as $key => $value)
282 282
                     {
283
-                        $liste[$key]=$value;
283
+                        $liste[$key] = $value;
284 284
                     }
285 285
                     print " ".$langs->trans("or")." ";
286 286
                     //var_dump($_REQUEST);exit;
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
         // Message
295 295
         if ($this->withbody)
296 296
         {
297
-            $defaultmessage='';
298
-            if ($this->param["models"]=='body')
297
+            $defaultmessage = '';
298
+            if ($this->param["models"] == 'body')
299 299
             {
300
-                $defaultmessage=$this->withbody;
300
+                $defaultmessage = $this->withbody;
301 301
             }
302
-            $defaultmessage=make_substitutions($defaultmessage,$this->substit);
303
-            if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
304
-            $defaultmessage=str_replace('\n',"\n",$defaultmessage);
302
+            $defaultmessage = make_substitutions($defaultmessage, $this->substit);
303
+            if (isset($_POST["message"])) $defaultmessage = $_POST["message"];
304
+            $defaultmessage = str_replace('\n', "\n", $defaultmessage);
305 305
 
306 306
             print "<tr>";
307 307
             print '<td class="tdtop">'.$langs->trans("SmsText")."</td>";
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
             else
315 315
             {
316 316
                 print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
317
-                print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
317
+                print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160 - dol_strlen($defaultmessage)).'</span></div></td>';
318 318
             }
319 319
             print "</td></tr>\n";
320 320
         }
Please login to merge, or discard this patch.
Braces   +31 added lines, -28 removed lines patch added patch discarded remove patch
@@ -105,7 +105,9 @@  discard block
 block discarded – undo
105 105
      // phpcs:enable
106 106
         global $conf, $langs, $user, $form;
107 107
 
108
-        if (! is_object($form)) $form=new Form($this->db);
108
+        if (! is_object($form)) {
109
+            $form=new Form($this->db);
110
+        }
109 111
 
110 112
         // Load translation files required by the page
111 113
         $langs->loadLangs(array('other', 'mails', 'sms'));
@@ -131,7 +133,9 @@  discard block
 block discarded – undo
131 133
 }
132 134
 </script>';
133 135
 
134
-        if ($showform) print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
136
+        if ($showform) {
137
+            print "<form method=\"POST\" name=\"smsform\" enctype=\"multipart/form-data\" action=\"".$this->param["returnurl"]."\">\n";
138
+        }
135 139
 
136 140
         print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
137 141
         foreach ($this->param as $key=>$value)
@@ -141,9 +145,11 @@  discard block
 block discarded – undo
141 145
         print "<table class=\"border centpercent\">\n";
142 146
 
143 147
         // Substitution array
144
-        if (! empty($this->withsubstit))		// Unset or set ->withsubstit=0 to disable this.
148
+        if (! empty($this->withsubstit)) {
149
+            // Unset or set ->withsubstit=0 to disable this.
145 150
         {
146 151
             print "<tr><td colspan=\"2\">";
152
+        }
147 153
             $help="";
148 154
             foreach($this->substit as $key => $val)
149 155
             {
@@ -172,8 +178,7 @@  discard block
 block discarded – undo
172 178
                 if ($this->fromsms)
173 179
                 {
174 180
                     print $this->fromsms;
175
-                }
176
-                else
181
+                } else
177 182
                 {
178 183
                     if ($this->fromtype)
179 184
                     {
@@ -183,34 +188,34 @@  discard block
 block discarded – undo
183 188
                 }
184 189
                 print "</td></tr>\n";
185 190
                 print "</td></tr>\n";
186
-            }
187
-            else
191
+            } else
188 192
             {
189 193
                 print '<tr><td class="'.$morecss.'">'.$langs->trans("SmsFrom")."</td><td>";
190 194
                 //print '<input type="text" name="fromname" size="30" value="'.$this->fromsms.'">';
191
-                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')        // For backward compatibility        @deprecated
195
+                if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') {
196
+                    // For backward compatibility        @deprecated
192 197
                 {
193 198
                     dol_include_once('/ovh/class/ovhsms.class.php');
199
+                }
194 200
                     try
195 201
                     {
196 202
                         $sms = new OvhSms($this->db);
197 203
                         if (empty($conf->global->OVHSMS_ACCOUNT))
198 204
                         {
199 205
                             $resultsender = 'ErrorOVHSMS_ACCOUNT not defined';
200
-                        }
201
-                        else
206
+                        } else
202 207
                         {
203 208
                             $resultsender = $sms->SmsSenderList();
204 209
                         }
205
-                    }
206
-                    catch(Exception $e)
210
+                    } catch(Exception $e)
207 211
                     {
208 212
                         dol_print_error('','Error to get list of senders: '.$e->getMessage());
209 213
                     }
210
-                }
211
-                else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
214
+                } else if (!empty($conf->global->MAIN_SMS_SENDMODE)) {
215
+                    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
212 216
                 {
213 217
                     $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
218
+                }
214 219
                     $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
215 220
                     dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
216 221
                     try
@@ -220,20 +225,17 @@  discard block
 block discarded – undo
220 225
                         {
221 226
                         	$sms = new $classname($this->db);
222 227
                         	$resultsender = $sms->SmsSenderList();
223
-                        }
224
-                        else
228
+                        } else
225 229
                         {
226 230
                         	$sms = new stdClass();
227 231
                         	$sms->error='The SMS manager "'.$classfile.'" defined into SMS setup MAIN_SMS_SENDMODE is not found';
228 232
                         }
229
-                    }
230
-                    catch(Exception $e)
233
+                    } catch(Exception $e)
231 234
                     {
232 235
                         dol_print_error('','Error to get list of senders: '.$e->getMessage());
233 236
                         exit;
234 237
                     }
235
-                }
236
-                else
238
+                } else
237 239
                 {
238 240
                     dol_syslog("Warning: The SMS sending method has not been defined into MAIN_SMS_SENDMODE", LOG_WARNING);
239 241
 	                $resultsender=array();
@@ -248,11 +250,12 @@  discard block
 block discarded – undo
248 250
                         print '<option value="'.$obj->number.'">'.$obj->number.'</option>';
249 251
                     }
250 252
                     print '</select>';
251
-                }
252
-                else
253
+                } else
253 254
                 {
254 255
                     print '<span class="error">'.$langs->trans("SmsNoPossibleSenderFound");
255
-                    if (is_object($sms) && ! empty($sms->error)) print ' '.$sms->error;
256
+                    if (is_object($sms) && ! empty($sms->error)) {
257
+                        print ' '.$sms->error;
258
+                    }
256 259
                     print '</span>';
257 260
                 }
258 261
                 print '</td>';
@@ -271,8 +274,7 @@  discard block
 block discarded – undo
271 274
             if ($this->withtoreadonly)
272 275
             {
273 276
                 print (! is_array($this->withto) && ! is_numeric($this->withto))?$this->withto:"";
274
-            }
275
-            else
277
+            } else
276 278
             {
277 279
                 print "<input size=\"16\" id=\"sendto\" name=\"sendto\" value=\"".dol_escape_htmltag(! is_array($this->withto) && $this->withto != '1'? (isset($_REQUEST["sendto"])?GETPOST("sendto"):$this->withto):"+")."\">";
278 280
                 if (! empty($this->withtosocid) && $this->withtosocid > 0)
@@ -300,7 +302,9 @@  discard block
 block discarded – undo
300 302
                 $defaultmessage=$this->withbody;
301 303
             }
302 304
             $defaultmessage=make_substitutions($defaultmessage,$this->substit);
303
-            if (isset($_POST["message"])) $defaultmessage=$_POST["message"];
305
+            if (isset($_POST["message"])) {
306
+                $defaultmessage=$_POST["message"];
307
+            }
304 308
             $defaultmessage=str_replace('\n',"\n",$defaultmessage);
305 309
 
306 310
             print "<tr>";
@@ -310,8 +314,7 @@  discard block
 block discarded – undo
310 314
             {
311 315
                 print nl2br($defaultmessage);
312 316
                 print '<input type="hidden" name="message" value="'.dol_escape_htmltag($defaultmessage).'">';
313
-            }
314
-            else
317
+            } else
315 318
             {
316 319
                 print '<textarea class="quatrevingtpercent" name="message" id="message" rows="'.ROWS_4.'" onkeyup="limitChars(this, 160, \'charlimitinfospan\')">'.$defaultmessage.'</textarea>';
317 320
                 print '<div id="charlimitinfo">'.$langs->trans("SmsInfoCharRemain").': <span id="charlimitinfospan">'.(160-dol_strlen($defaultmessage)).'</span></div></td>';
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/rssparser.class.php 3 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -32,9 +32,9 @@  discard block
 block discarded – undo
32 32
     public $db;
33 33
 
34 34
     /**
35
-	 * @var string Error code (or message)
36
-	 */
37
-	public $error='';
35
+     * @var string Error code (or message)
36
+     */
37
+    public $error='';
38 38
 
39 39
     private $_format='';
40 40
     private $_urlRSS;
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
      */
62 62
     public function __construct($db)
63 63
     {
64
-    	$this->db = $db;
64
+        $this->db = $db;
65 65
     }
66 66
 
67 67
     /**
@@ -252,28 +252,28 @@  discard block
 block discarded – undo
252 252
 
253 253
         if ($str !== false)
254 254
         {
255
-	        // Convert $str into xml
256
-	        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
257
-	        {
258
-	            //print 'xx'.LIBXML_NOCDATA;
259
-	            libxml_use_internal_errors(false);
260
-	            $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
261
-	        }
262
-	        else
263
-	        {
264
-	            $xmlparser=xml_parser_create('');
265
-	            if (!is_resource($xmlparser)) {
266
-	                $this->error="ErrorFailedToCreateParser"; return -1;
267
-	            }
268
-
269
-	            xml_set_object($xmlparser, $this);
270
-	            xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element');
271
-	            xml_set_character_data_handler($xmlparser, 'feed_cdata');
272
-	            $status = xml_parse($xmlparser, $str);
273
-	            xml_parser_free($xmlparser);
274
-	            $rss=$this;
275
-	            //var_dump($rss->_format);exit;
276
-	        }
255
+            // Convert $str into xml
256
+            if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
257
+            {
258
+                //print 'xx'.LIBXML_NOCDATA;
259
+                libxml_use_internal_errors(false);
260
+                $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
261
+            }
262
+            else
263
+            {
264
+                $xmlparser=xml_parser_create('');
265
+                if (!is_resource($xmlparser)) {
266
+                    $this->error="ErrorFailedToCreateParser"; return -1;
267
+                }
268
+
269
+                xml_set_object($xmlparser, $this);
270
+                xml_set_element_handler($xmlparser, 'feed_start_element', 'feed_end_element');
271
+                xml_set_character_data_handler($xmlparser, 'feed_cdata');
272
+                $status = xml_parse($xmlparser, $str);
273
+                xml_parser_free($xmlparser);
274
+                $rss=$this;
275
+                //var_dump($rss->_format);exit;
276
+            }
277 277
         }
278 278
 
279 279
         // If $rss loaded
@@ -287,16 +287,16 @@  discard block
 block discarded – undo
287 287
                 $fp = fopen($newpathofdestfile, 'w');
288 288
                 if ($fp)
289 289
                 {
290
-                	fwrite($fp, $str);
291
-                	fclose($fp);
292
-                	if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
293
-                	@chmod($newpathofdestfile, octdec($newmask));
290
+                    fwrite($fp, $str);
291
+                    fclose($fp);
292
+                    if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
293
+                    @chmod($newpathofdestfile, octdec($newmask));
294 294
 
295
-	                $this->_lastfetchdate=$nowgmt;
295
+                    $this->_lastfetchdate=$nowgmt;
296 296
                 }
297 297
                 else
298 298
                 {
299
-                	print 'Error, failed to open file '.$newpathofdestfile.' for write';
299
+                    print 'Error, failed to open file '.$newpathofdestfile.' for write';
300 300
                 }
301 301
             }
302 302
 
@@ -435,13 +435,13 @@  discard block
 block discarded – undo
435 435
 
436 436
                     // Add record to result array
437 437
                     $this->_rssarray[$i] = array(
438
-    					'link'=>$itemLink,
439
-    					'title'=>$itemTitle,
440
-    					'description'=>$itemDescription,
441
-    					'pubDate'=>$itemPubDate,
442
-    					'category'=>$itemCategory,
443
-    				    'id'=>$itemId,
444
-    				    'author'=>$itemAuthor);
438
+                        'link'=>$itemLink,
439
+                        'title'=>$itemTitle,
440
+                        'description'=>$itemDescription,
441
+                        'pubDate'=>$itemPubDate,
442
+                        'category'=>$itemCategory,
443
+                        'id'=>$itemId,
444
+                        'author'=>$itemAuthor);
445 445
                     //var_dump($this->_rssarray);
446 446
 
447 447
                     $i++;
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,9 +34,9 @@  discard block
 block discarded – undo
34 34
     /**
35 35
 	 * @var string Error code (or message)
36 36
 	 */
37
-	public $error='';
37
+	public $error = '';
38 38
 
39
-    private $_format='';
39
+    private $_format = '';
40 40
     private $_urlRSS;
41 41
     private $_language;
42 42
     private $_generator;
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
     private $_link;
47 47
     private $_title;
48 48
     private $_description;
49
-    private $_lastfetchdate;    // Last successful fetch
50
-    private $_rssarray=array();
49
+    private $_lastfetchdate; // Last successful fetch
50
+    private $_rssarray = array();
51 51
 
52 52
     // For parsing with xmlparser
53 53
     var $stack               = array(); // parser stack
@@ -184,40 +184,40 @@  discard block
 block discarded – undo
184 184
      * 	@param	string	$cachedir	Directory where to save cache file
185 185
      *	@return	int					<0 if KO, >0 if OK
186 186
      */
187
-    public function parser($urlRSS, $maxNb=0, $cachedelay=60, $cachedir='')
187
+    public function parser($urlRSS, $maxNb = 0, $cachedelay = 60, $cachedir = '')
188 188
     {
189 189
         global $conf;
190 190
 
191 191
         include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
192 192
 
193
-        $rss='';
194
-        $str='';    // This will contain content of feed
193
+        $rss = '';
194
+        $str = ''; // This will contain content of feed
195 195
 
196 196
         // Check parameters
197
-        if (! dol_is_url($urlRSS))
197
+        if (!dol_is_url($urlRSS))
198 198
         {
199
-            $this->error="ErrorBadUrl";
199
+            $this->error = "ErrorBadUrl";
200 200
             return -1;
201 201
         }
202 202
 
203 203
         $this->_urlRSS = $urlRSS;
204
-        $newpathofdestfile=$cachedir.'/'.dol_hash($this->_urlRSS,3);	// Force md5 hash (does not contains special chars)
205
-        $newmask='0644';
204
+        $newpathofdestfile = $cachedir.'/'.dol_hash($this->_urlRSS, 3); // Force md5 hash (does not contains special chars)
205
+        $newmask = '0644';
206 206
 
207 207
         //dol_syslog("RssPArser::parser parse url=".$urlRSS." => cache file=".$newpathofdestfile);
208 208
         $nowgmt = dol_now();
209 209
 
210 210
         // Search into cache
211
-        $foundintocache=0;
211
+        $foundintocache = 0;
212 212
         if ($cachedelay > 0 && $cachedir)
213 213
         {
214
-            $filedate=dol_filemtime($newpathofdestfile);
214
+            $filedate = dol_filemtime($newpathofdestfile);
215 215
             if ($filedate >= ($nowgmt - $cachedelay))
216 216
             {
217 217
                 //dol_syslog("RssParser::parser cache file ".$newpathofdestfile." is not older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we use it.");
218
-                $foundintocache=1;
218
+                $foundintocache = 1;
219 219
 
220
-                $this->_lastfetchdate=$filedate;
220
+                $this->_lastfetchdate = $filedate;
221 221
             }
222 222
             else
223 223
             {
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
         else
234 234
         {
235 235
             try {
236
-                ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
236
+                ini_set("user_agent", "Dolibarr ERP-CRM RSS reader");
237 237
                 ini_set("max_execution_time", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
238 238
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
239 239
 
240 240
                 $opts = array('http'=>array('method'=>"GET"));
241
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
242
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
241
+                if (!empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout'] = $conf->global->MAIN_USE_CONNECT_TIMEOUT;
242
+                if (!empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy'] = 'tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
243 243
                 //var_dump($opts);exit;
244 244
                 $context = stream_context_create($opts);
245 245
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         if ($str !== false)
254 254
         {
255 255
 	        // Convert $str into xml
256
-	        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
256
+	        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
257 257
 	        {
258 258
 	            //print 'xx'.LIBXML_NOCDATA;
259 259
 	            libxml_use_internal_errors(false);
@@ -261,9 +261,9 @@  discard block
 block discarded – undo
261 261
 	        }
262 262
 	        else
263 263
 	        {
264
-	            $xmlparser=xml_parser_create('');
264
+	            $xmlparser = xml_parser_create('');
265 265
 	            if (!is_resource($xmlparser)) {
266
-	                $this->error="ErrorFailedToCreateParser"; return -1;
266
+	                $this->error = "ErrorFailedToCreateParser"; return -1;
267 267
 	            }
268 268
 
269 269
 	            xml_set_object($xmlparser, $this);
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	            xml_set_character_data_handler($xmlparser, 'feed_cdata');
272 272
 	            $status = xml_parse($xmlparser, $str);
273 273
 	            xml_parser_free($xmlparser);
274
-	            $rss=$this;
274
+	            $rss = $this;
275 275
 	            //var_dump($rss->_format);exit;
276 276
 	        }
277 277
         }
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
             if (empty($foundintocache) && $cachedir)
284 284
             {
285 285
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
286
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
286
+                if (!dol_is_dir($cachedir)) dol_mkdir($cachedir);
287 287
                 $fp = fopen($newpathofdestfile, 'w');
288 288
                 if ($fp)
289 289
                 {
290 290
                 	fwrite($fp, $str);
291 291
                 	fclose($fp);
292
-                	if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
292
+                	if (!empty($conf->global->MAIN_UMASK)) $newmask = $conf->global->MAIN_UMASK;
293 293
                 	@chmod($newpathofdestfile, octdec($newmask));
294 294
 
295
-	                $this->_lastfetchdate=$nowgmt;
295
+	                $this->_lastfetchdate = $nowgmt;
296 296
                 }
297 297
                 else
298 298
                 {
@@ -300,21 +300,21 @@  discard block
 block discarded – undo
300 300
                 }
301 301
             }
302 302
 
303
-            unset($str);    // Free memory
303
+            unset($str); // Free memory
304 304
 
305 305
             if (empty($rss->_format))    // If format not detected automatically
306 306
             {
307
-                $rss->_format='rss';
308
-                if (empty($rss->channel)) $rss->_format='atom';
307
+                $rss->_format = 'rss';
308
+                if (empty($rss->channel)) $rss->_format = 'atom';
309 309
             }
310 310
 
311
-            $items=array();
311
+            $items = array();
312 312
 
313 313
             // Save description entries
314 314
             if ($rss->_format == 'rss')
315 315
             {
316 316
                 //var_dump($rss);
317
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
317
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
318 318
                 {
319 319
                     if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
320 320
                     if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
@@ -338,14 +338,14 @@  discard block
 block discarded – undo
338 338
                     if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
339 339
                 }
340 340
 
341
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
342
-                else $items=$rss->items;                                                              // With xmlparse
341
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items = $rss->channel->item; // With simplexml
342
+                else $items = $rss->items; // With xmlparse
343 343
                 //var_dump($items);exit;
344 344
             }
345 345
             else if ($rss->_format == 'atom')
346 346
             {
347 347
                 //var_dump($rss);
348
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
348
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
349 349
                 {
350 350
                     if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
351 351
                     if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
                     if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
365 365
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
366 366
                 }
367
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
368
-                    $tmprss=xml2php($rss); $items=$tmprss['entry'];
367
+                if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
368
+                    $tmprss = xml2php($rss); $items = $tmprss['entry'];
369 369
                 } // With simplexml
370
-                else $items=$rss->items;                                                              // With xmlparse
370
+                else $items = $rss->items; // With xmlparse
371 371
                 //var_dump($items);exit;
372 372
             }
373 373
 
@@ -376,12 +376,12 @@  discard block
 block discarded – undo
376 376
             // Loop on each record
377 377
             if (is_array($items))
378 378
             {
379
-                foreach($items as $item)
379
+                foreach ($items as $item)
380 380
                 {
381 381
                     //var_dump($item);exit;
382 382
                     if ($rss->_format == 'rss')
383 383
                     {
384
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
384
+                        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
385 385
                         {
386 386
                             $itemLink = (string) $item->link;
387 387
                             $itemTitle = (string) $item->title;
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
                         }
402 402
 
403 403
                         // Loop on each category
404
-                        $itemCategory=array();
404
+                        $itemCategory = array();
405 405
                         if (is_array($item->category))
406 406
                         {
407 407
                             foreach ($item->category as $cat)
@@ -412,14 +412,14 @@  discard block
 block discarded – undo
412 412
                     }
413 413
                     else if ($rss->_format == 'atom')
414 414
                     {
415
-                        if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
415
+                        if (!empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
416 416
                         {
417 417
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
418 418
                             $itemTitle = (string) $item['title'];
419 419
                             $itemDescription = (string) $item['summary'];
420 420
                             $itemPubDate = (string) $item['created'];
421 421
                             $itemId = (string) $item['id'];
422
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
422
+                            $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
423 423
                         }
424 424
                         else
425 425
                         {
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
                             $itemDescription = (string) $item['summary'];
429 429
                             $itemPubDate = (string) $item['created'];
430 430
                             $itemId = (string) $item['id'];
431
-                            $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
431
+                            $itemAuthor = (string) ($item['author'] ? $item['author'] : $item['author_name']);
432 432
                         }
433 433
                     }
434 434
                     else print 'ErrorBadFeedFormat';
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 
447 447
                     $i++;
448 448
 
449
-                    if ($i > $maxNb)    break;    // We get all records we want
449
+                    if ($i > $maxNb)    break; // We get all records we want
450 450
                 }
451 451
             }
452 452
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
         }
455 455
         else
456 456
         {
457
-            $this->error='ErrorFailedToLoadRSSFile';
457
+            $this->error = 'ErrorFailedToLoadRSSFile';
458 458
             return -1;
459 459
         }
460 460
     }
@@ -482,7 +482,7 @@  discard block
 block discarded – undo
482 482
         {
483 483
             list($ns, $el) = explode(':', $element, 2);
484 484
         }
485
-        if ( $ns and $ns != 'rdf' )
485
+        if ($ns and $ns != 'rdf')
486 486
         {
487 487
             $this->current_namespace = $ns;
488 488
         }
@@ -490,15 +490,15 @@  discard block
 block discarded – undo
490 490
         // if feed type isn't set, then this is first element of feed identify feed from root element
491 491
         if (empty($this->_format))
492 492
         {
493
-            if ( $el == 'rdf' ) {
493
+            if ($el == 'rdf') {
494 494
                 $this->_format = 'rss';
495 495
                 $this->feed_version = '1.0';
496 496
             }
497
-            elseif ( $el == 'rss' ) {
497
+            elseif ($el == 'rss') {
498 498
                 $this->_format = 'rss';
499 499
                 $this->feed_version = $attrs['version'];
500 500
             }
501
-            elseif ( $el == 'feed' ) {
501
+            elseif ($el == 'feed') {
502 502
                 $this->_format = 'atom';
503 503
                 $this->feed_version = $attrs['version'];
504 504
                 $this->inchannel = true;
@@ -506,14 +506,14 @@  discard block
 block discarded – undo
506 506
             return;
507 507
         }
508 508
 
509
-        if ( $el == 'channel' )
509
+        if ($el == 'channel')
510 510
         {
511 511
             $this->inchannel = true;
512 512
         }
513
-        elseif ($el == 'item' or $el == 'entry' )
513
+        elseif ($el == 'item' or $el == 'entry')
514 514
         {
515 515
             $this->initem = true;
516
-            if ( isset($attrs['rdf:about']) ) {
516
+            if (isset($attrs['rdf:about'])) {
517 517
                 $this->current_item['about'] = $attrs['rdf:about'];
518 518
             }
519 519
         }
@@ -537,10 +537,10 @@  discard block
 block discarded – undo
537 537
         }
538 538
 
539 539
         // handle atom content constructs
540
-        elseif ( $this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
540
+        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS))
541 541
         {
542 542
             // avoid clashing w/ RSS mod_content
543
-            if ($el == 'content' ) {
543
+            if ($el == 'content') {
544 544
                 $el = 'atom_content';
545 545
             }
546 546
 
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
         }
549 549
 
550 550
         // if inside an Atom content construct (e.g. content or summary) field treat tags as text
551
-        elseif ($this->_format == 'atom' and $this->incontent )
551
+        elseif ($this->_format == 'atom' and $this->incontent)
552 552
         {
553 553
             // if tags are inlined, then flatten
554 554
             $attrs_str = join(' ', array_map('map_attrs', array_keys($attrs), array_values($attrs)));
@@ -562,14 +562,14 @@  discard block
 block discarded – undo
562 562
         // Magpie treats link elements of type rel='alternate'
563 563
         // as being equivalent to RSS's simple link element.
564 564
         //
565
-        elseif ($this->_format == 'atom' and $el == 'link' )
565
+        elseif ($this->_format == 'atom' and $el == 'link')
566 566
         {
567
-            if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
567
+            if (isset($attrs['rel']) && $attrs['rel'] == 'alternate')
568 568
             {
569 569
                 $link_el = 'link';
570 570
             }
571 571
             else {
572
-                $link_el = 'link_' . $attrs['rel'];
572
+                $link_el = 'link_'.$attrs['rel'];
573 573
             }
574 574
 
575 575
             $this->append($link_el, $attrs['href']);
@@ -622,26 +622,26 @@  discard block
 block discarded – undo
622 622
             $this->current_item = array();
623 623
             $this->initem = false;
624 624
         }
625
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
625
+        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput')
626 626
         {
627 627
             $this->intextinput = false;
628 628
         }
629
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
629
+        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image')
630 630
         {
631 631
             $this->inimage = false;
632 632
         }
633
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
633
+        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS))
634 634
         {
635 635
             $this->incontent = false;
636 636
         }
637
-        elseif ($el == 'channel' or $el == 'feed' )
637
+        elseif ($el == 'channel' or $el == 'feed')
638 638
         {
639 639
             $this->inchannel = false;
640 640
         }
641
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
641
+        elseif ($this->_format == 'atom' and $this->incontent) {
642 642
             // balance tags properly
643 643
             // note:  i don't think this is actually neccessary
644
-            if ( $this->stack[0] == $el )
644
+            if ($this->stack[0] == $el)
645 645
             {
646 646
                 $this->append_content("</$el>");
647 647
             }
@@ -666,10 +666,10 @@  discard block
 block discarded – undo
666 666
      *  @param	string	$str2		Str2
667 667
      *  @return	string				String cancatenated
668 668
      */
669
-    function concat(&$str1, $str2="")
669
+    function concat(&$str1, $str2 = "")
670 670
     {
671
-        if (!isset($str1) ) {
672
-            $str1="";
671
+        if (!isset($str1)) {
672
+            $str1 = "";
673 673
         }
674 674
         $str1 .= $str2;
675 675
     }
@@ -684,11 +684,11 @@  discard block
 block discarded – undo
684 684
     function append_content($text)
685 685
     {
686 686
         // phpcs:enable
687
-        if ( $this->initem ) {
688
-            $this->concat($this->current_item[ $this->incontent ], $text);
687
+        if ($this->initem) {
688
+            $this->concat($this->current_item[$this->incontent], $text);
689 689
         }
690
-        elseif ( $this->inchannel ) {
691
-            $this->concat($this->channel[ $this->incontent ], $text);
690
+        elseif ($this->inchannel) {
691
+            $this->concat($this->channel[$this->incontent], $text);
692 692
         }
693 693
     }
694 694
 
@@ -704,33 +704,33 @@  discard block
 block discarded – undo
704 704
         if (!$el) {
705 705
             return;
706 706
         }
707
-        if ( $this->current_namespace )
707
+        if ($this->current_namespace)
708 708
         {
709
-            if ( $this->initem ) {
710
-                $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
709
+            if ($this->initem) {
710
+                $this->concat($this->current_item[$this->current_namespace][$el], $text);
711 711
             }
712 712
             elseif ($this->inchannel) {
713
-                $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
713
+                $this->concat($this->channel[$this->current_namespace][$el], $text);
714 714
             }
715 715
             elseif ($this->intextinput) {
716
-                $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
716
+                $this->concat($this->textinput[$this->current_namespace][$el], $text);
717 717
             }
718 718
             elseif ($this->inimage) {
719
-                $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
719
+                $this->concat($this->image[$this->current_namespace][$el], $text);
720 720
             }
721 721
         }
722 722
         else {
723
-            if ( $this->initem ) {
724
-                $this->concat($this->current_item[ $el ], $text);
723
+            if ($this->initem) {
724
+                $this->concat($this->current_item[$el], $text);
725 725
             }
726 726
             elseif ($this->intextinput) {
727
-                $this->concat($this->textinput[ $el ], $text);
727
+                $this->concat($this->textinput[$el], $text);
728 728
             }
729 729
             elseif ($this->inimage) {
730
-                $this->concat($this->image[ $el ], $text);
730
+                $this->concat($this->image[$el], $text);
731 731
             }
732 732
             elseif ($this->inchannel) {
733
-                $this->concat($this->channel[ $el ], $text);
733
+                $this->concat($this->channel[$el], $text);
734 734
             }
735 735
         }
736 736
     }
@@ -748,18 +748,18 @@  discard block
 block discarded – undo
748 748
     $fils = 0;
749 749
     $tab = false;
750 750
     $array = array();
751
-    foreach($xml->children() as $key => $value)
751
+    foreach ($xml->children() as $key => $value)
752 752
     {
753 753
         $child = xml2php($value);
754 754
 
755 755
         //To deal with the attributes
756
-        foreach($value->attributes() as $ak=>$av)
756
+        foreach ($value->attributes() as $ak=>$av)
757 757
         {
758 758
             $child[$ak] = (string) $av;
759 759
         }
760 760
 
761 761
         //Let see if the new child is not in the array
762
-        if ($tab === false && in_array($key,array_keys($array)))
762
+        if ($tab === false && in_array($key, array_keys($array)))
763 763
         {
764 764
             //If this element is already in the array we will create an indexed array
765 765
             $tmp = $array[$key];
@@ -768,7 +768,7 @@  discard block
 block discarded – undo
768 768
             $array[$key][] = $child;
769 769
             $tab = true;
770 770
         }
771
-        elseif($tab === true)
771
+        elseif ($tab === true)
772 772
         {
773 773
             //Add an element in an existing array
774 774
             $array[$key][] = $child;
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
     }
784 784
 
785 785
 
786
-    if ($fils==0)
786
+    if ($fils == 0)
787 787
     {
788 788
         return (string) $xml;
789 789
     }
Please login to merge, or discard this patch.
Braces   +148 added lines, -107 removed lines patch added patch discarded remove patch
@@ -218,19 +218,19 @@  discard block
 block discarded – undo
218 218
                 $foundintocache=1;
219 219
 
220 220
                 $this->_lastfetchdate=$filedate;
221
-            }
222
-            else
221
+            } else
223 222
             {
224 223
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is not found or older than now - cachedelay (".$nowgmt." - ".$cachedelay.") so we can't use it.");
225 224
             }
226 225
         }
227 226
 
228 227
         // Load file into $str
229
-        if ($foundintocache)    // Cache file found and is not too old
228
+        if ($foundintocache) {
229
+            // Cache file found and is not too old
230 230
         {
231 231
             $str = file_get_contents($newpathofdestfile);
232 232
         }
233
-        else
233
+        } else
234 234
         {
235 235
             try {
236 236
                 ini_set("user_agent","Dolibarr ERP-CRM RSS reader");
@@ -238,14 +238,17 @@  discard block
 block discarded – undo
238 238
                 ini_set("default_socket_timeout", $conf->global->MAIN_USE_RESPONSE_TIMEOUT);
239 239
 
240 240
                 $opts = array('http'=>array('method'=>"GET"));
241
-                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
242
-                if (! empty($conf->global->MAIN_PROXY_USE))           $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
241
+                if (! empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)) {
242
+                    $opts['http']['timeout']=$conf->global->MAIN_USE_CONNECT_TIMEOUT;
243
+                }
244
+                if (! empty($conf->global->MAIN_PROXY_USE)) {
245
+                    $opts['http']['proxy']='tcp://'.$conf->global->MAIN_PROXY_HOST.':'.$conf->global->MAIN_PROXY_PORT;
246
+                }
243 247
                 //var_dump($opts);exit;
244 248
                 $context = stream_context_create($opts);
245 249
 
246 250
                 $str = file_get_contents($this->_urlRSS, false, $context);
247
-            }
248
-            catch (Exception $e) {
251
+            } catch (Exception $e) {
249 252
                 print 'Error retrieving URL '.$this->urlRSS.' - '.$e->getMessage();
250 253
             }
251 254
         }
@@ -258,8 +261,7 @@  discard block
 block discarded – undo
258 261
 	            //print 'xx'.LIBXML_NOCDATA;
259 262
 	            libxml_use_internal_errors(false);
260 263
 	            $rss = simplexml_load_string($str, "SimpleXMLElement", LIBXML_NOCDATA);
261
-	        }
262
-	        else
264
+	        } else
263 265
 	        {
264 266
 	            $xmlparser=xml_parser_create('');
265 267
 	            if (!is_resource($xmlparser)) {
@@ -283,18 +285,21 @@  discard block
 block discarded – undo
283 285
             if (empty($foundintocache) && $cachedir)
284 286
             {
285 287
                 dol_syslog(get_class($this)."::parser cache file ".$newpathofdestfile." is saved onto disk.");
286
-                if (! dol_is_dir($cachedir)) dol_mkdir($cachedir);
288
+                if (! dol_is_dir($cachedir)) {
289
+                    dol_mkdir($cachedir);
290
+                }
287 291
                 $fp = fopen($newpathofdestfile, 'w');
288 292
                 if ($fp)
289 293
                 {
290 294
                 	fwrite($fp, $str);
291 295
                 	fclose($fp);
292
-                	if (! empty($conf->global->MAIN_UMASK)) $newmask=$conf->global->MAIN_UMASK;
296
+                	if (! empty($conf->global->MAIN_UMASK)) {
297
+                	    $newmask=$conf->global->MAIN_UMASK;
298
+                	}
293 299
                 	@chmod($newpathofdestfile, octdec($newmask));
294 300
 
295 301
 	                $this->_lastfetchdate=$nowgmt;
296
-                }
297
-                else
302
+                } else
298 303
                 {
299 304
                 	print 'Error, failed to open file '.$newpathofdestfile.' for write';
300 305
                 }
@@ -302,10 +307,14 @@  discard block
 block discarded – undo
302 307
 
303 308
             unset($str);    // Free memory
304 309
 
305
-            if (empty($rss->_format))    // If format not detected automatically
310
+            if (empty($rss->_format)) {
311
+                // If format not detected automatically
306 312
             {
307 313
                 $rss->_format='rss';
308
-                if (empty($rss->channel)) $rss->_format='atom';
314
+            }
315
+                if (empty($rss->channel)) {
316
+                    $rss->_format='atom';
317
+                }
309 318
             }
310 319
 
311 320
             $items=array();
@@ -316,58 +325,114 @@  discard block
 block discarded – undo
316 325
                 //var_dump($rss);
317 326
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
318 327
                 {
319
-                    if (!empty($rss->channel->language))      $this->_language = (string) $rss->channel->language;
320
-                    if (!empty($rss->channel->generator))     $this->_generator = (string) $rss->channel->generator;
321
-                    if (!empty($rss->channel->copyright))     $this->_copyright = (string) $rss->channel->copyright;
322
-                    if (!empty($rss->channel->lastbuilddate)) $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
323
-                    if (!empty($rss->channel->image->url[0])) $this->_imageurl = (string) $rss->channel->image->url[0];
324
-                    if (!empty($rss->channel->link))		  $this->_link = (string) $rss->channel->link;
325
-                    if (!empty($rss->channel->title))         $this->_title = (string) $rss->channel->title;
326
-                    if (!empty($rss->channel->description))	  $this->_description = (string) $rss->channel->description;
327
-                }
328
-                else
328
+                    if (!empty($rss->channel->language)) {
329
+                        $this->_language = (string) $rss->channel->language;
330
+                    }
331
+                    if (!empty($rss->channel->generator)) {
332
+                        $this->_generator = (string) $rss->channel->generator;
333
+                    }
334
+                    if (!empty($rss->channel->copyright)) {
335
+                        $this->_copyright = (string) $rss->channel->copyright;
336
+                    }
337
+                    if (!empty($rss->channel->lastbuilddate)) {
338
+                        $this->_lastbuilddate = (string) $rss->channel->lastbuilddate;
339
+                    }
340
+                    if (!empty($rss->channel->image->url[0])) {
341
+                        $this->_imageurl = (string) $rss->channel->image->url[0];
342
+                    }
343
+                    if (!empty($rss->channel->link)) {
344
+                        $this->_link = (string) $rss->channel->link;
345
+                    }
346
+                    if (!empty($rss->channel->title)) {
347
+                        $this->_title = (string) $rss->channel->title;
348
+                    }
349
+                    if (!empty($rss->channel->description)) {
350
+                        $this->_description = (string) $rss->channel->description;
351
+                    }
352
+                } else
329 353
                 {
330 354
                     //var_dump($rss->channel);
331
-                    if (!empty($rss->channel['language']))      $this->_language = (string) $rss->channel['language'];
332
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
333
-                    if (!empty($rss->channel['copyright']))     $this->_copyright = (string) $rss->channel['copyright'];
334
-                    if (!empty($rss->channel['lastbuilddate'])) $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
335
-                    if (!empty($rss->image['url']))             $this->_imageurl = (string) $rss->image['url'];
336
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
337
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
338
-                    if (!empty($rss->channel['description']))   $this->_description = (string) $rss->channel['description'];
355
+                    if (!empty($rss->channel['language'])) {
356
+                        $this->_language = (string) $rss->channel['language'];
357
+                    }
358
+                    if (!empty($rss->channel['generator'])) {
359
+                        $this->_generator = (string) $rss->channel['generator'];
360
+                    }
361
+                    if (!empty($rss->channel['copyright'])) {
362
+                        $this->_copyright = (string) $rss->channel['copyright'];
363
+                    }
364
+                    if (!empty($rss->channel['lastbuilddate'])) {
365
+                        $this->_lastbuilddate = (string) $rss->channel['lastbuilddate'];
366
+                    }
367
+                    if (!empty($rss->image['url'])) {
368
+                        $this->_imageurl = (string) $rss->image['url'];
369
+                    }
370
+                    if (!empty($rss->channel['link'])) {
371
+                        $this->_link = (string) $rss->channel['link'];
372
+                    }
373
+                    if (!empty($rss->channel['title'])) {
374
+                        $this->_title = (string) $rss->channel['title'];
375
+                    }
376
+                    if (!empty($rss->channel['description'])) {
377
+                        $this->_description = (string) $rss->channel['description'];
378
+                    }
339 379
                 }
340 380
 
341
-                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) $items=$rss->channel->item;    // With simplexml
342
-                else $items=$rss->items;                                                              // With xmlparse
381
+                if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML)) {
382
+                    $items=$rss->channel->item;
383
+                }
384
+                // With simplexml
385
+                else {
386
+                    $items=$rss->items;
387
+                }
388
+                // With xmlparse
343 389
                 //var_dump($items);exit;
344
-            }
345
-            else if ($rss->_format == 'atom')
390
+            } else if ($rss->_format == 'atom')
346 391
             {
347 392
                 //var_dump($rss);
348 393
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
349 394
                 {
350
-                    if (!empty($rss->generator))     $this->_generator = (string) $rss->generator;
351
-                    if (!empty($rss->lastbuilddate)) $this->_lastbuilddate = (string) $rss->modified;
352
-                    if (!empty($rss->link->href))    $this->_link = (string) $rss->link->href;
353
-                    if (!empty($rss->title))         $this->_title = (string) $rss->title;
354
-                    if (!empty($rss->description))	 $this->_description = (string) $rss->description;
355
-                }
356
-                else
395
+                    if (!empty($rss->generator)) {
396
+                        $this->_generator = (string) $rss->generator;
397
+                    }
398
+                    if (!empty($rss->lastbuilddate)) {
399
+                        $this->_lastbuilddate = (string) $rss->modified;
400
+                    }
401
+                    if (!empty($rss->link->href)) {
402
+                        $this->_link = (string) $rss->link->href;
403
+                    }
404
+                    if (!empty($rss->title)) {
405
+                        $this->_title = (string) $rss->title;
406
+                    }
407
+                    if (!empty($rss->description)) {
408
+                        $this->_description = (string) $rss->description;
409
+                    }
410
+                } else
357 411
                 {
358 412
                     //if (!empty($rss->channel['rss_language']))      $this->_language = (string) $rss->channel['rss_language'];
359
-                    if (!empty($rss->channel['generator']))     $this->_generator = (string) $rss->channel['generator'];
413
+                    if (!empty($rss->channel['generator'])) {
414
+                        $this->_generator = (string) $rss->channel['generator'];
415
+                    }
360 416
                     //if (!empty($rss->channel['rss_copyright']))     $this->_copyright = (string) $rss->channel['rss_copyright'];
361
-                    if (!empty($rss->channel['modified'])) $this->_lastbuilddate = (string) $rss->channel['modified'];
417
+                    if (!empty($rss->channel['modified'])) {
418
+                        $this->_lastbuilddate = (string) $rss->channel['modified'];
419
+                    }
362 420
                     //if (!empty($rss->image['rss_url']))             $this->_imageurl = (string) $rss->image['rss_url'];
363
-                    if (!empty($rss->channel['link']))		    $this->_link = (string) $rss->channel['link'];
364
-                    if (!empty($rss->channel['title']))         $this->_title = (string) $rss->channel['title'];
421
+                    if (!empty($rss->channel['link'])) {
422
+                        $this->_link = (string) $rss->channel['link'];
423
+                    }
424
+                    if (!empty($rss->channel['title'])) {
425
+                        $this->_title = (string) $rss->channel['title'];
426
+                    }
365 427
                     //if (!empty($rss->channel['rss_description']))   $this->_description = (string) $rss->channel['rss_description'];
366 428
                 }
367 429
                 if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))  {
368 430
                     $tmprss=xml2php($rss); $items=$tmprss['entry'];
369 431
                 } // With simplexml
370
-                else $items=$rss->items;                                                              // With xmlparse
432
+                else {
433
+                    $items=$rss->items;
434
+                }
435
+                // With xmlparse
371 436
                 //var_dump($items);exit;
372 437
             }
373 438
 
@@ -389,8 +454,7 @@  discard block
 block discarded – undo
389 454
                             $itemPubDate = (string) $item->pubDate;
390 455
                             $itemId = '';
391 456
                             $itemAuthor = '';
392
-                        }
393
-                        else
457
+                        } else
394 458
                         {
395 459
                             $itemLink = (string) $item['link'];
396 460
                             $itemTitle = (string) $item['title'];
@@ -409,8 +473,7 @@  discard block
 block discarded – undo
409 473
                                 $itemCategory[] = (string) $cat;
410 474
                             }
411 475
                         }
412
-                    }
413
-                    else if ($rss->_format == 'atom')
476
+                    } else if ($rss->_format == 'atom')
414 477
                     {
415 478
                         if (! empty($conf->global->EXTERNALRSS_USE_SIMPLEXML))
416 479
                         {
@@ -420,8 +483,7 @@  discard block
 block discarded – undo
420 483
                             $itemPubDate = (string) $item['created'];
421 484
                             $itemId = (string) $item['id'];
422 485
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
423
-                        }
424
-                        else
486
+                        } else
425 487
                         {
426 488
                             $itemLink = (isset($item['link']['href']) ? (string) $item['link']['href'] : '');
427 489
                             $itemTitle = (string) $item['title'];
@@ -430,8 +492,9 @@  discard block
 block discarded – undo
430 492
                             $itemId = (string) $item['id'];
431 493
                             $itemAuthor = (string) ($item['author']?$item['author']:$item['author_name']);
432 494
                         }
495
+                    } else {
496
+                        print 'ErrorBadFeedFormat';
433 497
                     }
434
-                    else print 'ErrorBadFeedFormat';
435 498
 
436 499
                     // Add record to result array
437 500
                     $this->_rssarray[$i] = array(
@@ -446,13 +509,15 @@  discard block
 block discarded – undo
446 509
 
447 510
                     $i++;
448 511
 
449
-                    if ($i > $maxNb)    break;    // We get all records we want
512
+                    if ($i > $maxNb) {
513
+                        break;
514
+                    }
515
+                    // We get all records we want
450 516
                 }
451 517
             }
452 518
 
453 519
             return 1;
454
-        }
455
-        else
520
+        } else
456 521
         {
457 522
             $this->error='ErrorFailedToLoadRSSFile';
458 523
             return -1;
@@ -493,12 +558,10 @@  discard block
 block discarded – undo
493 558
             if ( $el == 'rdf' ) {
494 559
                 $this->_format = 'rss';
495 560
                 $this->feed_version = '1.0';
496
-            }
497
-            elseif ( $el == 'rss' ) {
561
+            } elseif ( $el == 'rss' ) {
498 562
                 $this->_format = 'rss';
499 563
                 $this->feed_version = $attrs['version'];
500
-            }
501
-            elseif ( $el == 'feed' ) {
564
+            } elseif ( $el == 'feed' ) {
502 565
                 $this->_format = 'atom';
503 566
                 $this->feed_version = $attrs['version'];
504 567
                 $this->inchannel = true;
@@ -509,8 +572,7 @@  discard block
 block discarded – undo
509 572
         if ( $el == 'channel' )
510 573
         {
511 574
             $this->inchannel = true;
512
-        }
513
-        elseif ($el == 'item' or $el == 'entry' )
575
+        } elseif ($el == 'item' or $el == 'entry' )
514 576
         {
515 577
             $this->initem = true;
516 578
             if ( isset($attrs['rdf:about']) ) {
@@ -526,9 +588,7 @@  discard block
 block discarded – undo
526 588
         $el == 'textinput' )
527 589
         {
528 590
             $this->intextinput = true;
529
-        }
530
-
531
-        elseif (
591
+        } elseif (
532 592
         $this->_format == 'rss' and
533 593
         $this->current_namespace == '' and
534 594
         $el == 'image' )
@@ -567,8 +627,7 @@  discard block
 block discarded – undo
567 627
             if ( isset($attrs['rel']) && $attrs['rel'] == 'alternate' )
568 628
             {
569 629
                 $link_el = 'link';
570
-            }
571
-            else {
630
+            } else {
572 631
                 $link_el = 'link_' . $attrs['rel'];
573 632
             }
574 633
 
@@ -595,8 +654,7 @@  discard block
 block discarded – undo
595 654
         if ($this->_format == 'atom' and $this->incontent)
596 655
         {
597 656
             $this->append_content($text);
598
-        }
599
-        else
657
+        } else
600 658
         {
601 659
             $current_el = join('_', array_reverse($this->stack));
602 660
             $this->append($current_el, $text);
@@ -621,37 +679,30 @@  discard block
 block discarded – undo
621 679
             $this->items[] = $this->current_item;
622 680
             $this->current_item = array();
623 681
             $this->initem = false;
624
-        }
625
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
682
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'textinput' )
626 683
         {
627 684
             $this->intextinput = false;
628
-        }
629
-        elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
685
+        } elseif ($this->_format == 'rss' and $this->current_namespace == '' and $el == 'image' )
630 686
         {
631 687
             $this->inimage = false;
632
-        }
633
-        elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
688
+        } elseif ($this->_format == 'atom' and in_array($el, $this->_CONTENT_CONSTRUCTS) )
634 689
         {
635 690
             $this->incontent = false;
636
-        }
637
-        elseif ($el == 'channel' or $el == 'feed' )
691
+        } elseif ($el == 'channel' or $el == 'feed' )
638 692
         {
639 693
             $this->inchannel = false;
640
-        }
641
-        elseif ($this->_format == 'atom' and $this->incontent  ) {
694
+        } elseif ($this->_format == 'atom' and $this->incontent  ) {
642 695
             // balance tags properly
643 696
             // note:  i don't think this is actually neccessary
644 697
             if ( $this->stack[0] == $el )
645 698
             {
646 699
                 $this->append_content("</$el>");
647
-            }
648
-            else {
700
+            } else {
649 701
                 $this->append_content("<$el />");
650 702
             }
651 703
 
652 704
             array_shift($this->stack);
653
-        }
654
-        else {
705
+        } else {
655 706
             array_shift($this->stack);
656 707
         }
657 708
 
@@ -686,8 +737,7 @@  discard block
 block discarded – undo
686 737
         // phpcs:enable
687 738
         if ( $this->initem ) {
688 739
             $this->concat($this->current_item[ $this->incontent ], $text);
689
-        }
690
-        elseif ( $this->inchannel ) {
740
+        } elseif ( $this->inchannel ) {
691 741
             $this->concat($this->channel[ $this->incontent ], $text);
692 742
         }
693 743
     }
@@ -708,28 +758,21 @@  discard block
 block discarded – undo
708 758
         {
709 759
             if ( $this->initem ) {
710 760
                 $this->concat($this->current_item[ $this->current_namespace ][ $el ], $text);
711
-            }
712
-            elseif ($this->inchannel) {
761
+            } elseif ($this->inchannel) {
713 762
                 $this->concat($this->channel[ $this->current_namespace][ $el ], $text);
714
-            }
715
-            elseif ($this->intextinput) {
763
+            } elseif ($this->intextinput) {
716 764
                 $this->concat($this->textinput[ $this->current_namespace][ $el ], $text);
717
-            }
718
-            elseif ($this->inimage) {
765
+            } elseif ($this->inimage) {
719 766
                 $this->concat($this->image[ $this->current_namespace ][ $el ], $text);
720 767
             }
721
-        }
722
-        else {
768
+        } else {
723 769
             if ( $this->initem ) {
724 770
                 $this->concat($this->current_item[ $el ], $text);
725
-            }
726
-            elseif ($this->intextinput) {
771
+            } elseif ($this->intextinput) {
727 772
                 $this->concat($this->textinput[ $el ], $text);
728
-            }
729
-            elseif ($this->inimage) {
773
+            } elseif ($this->inimage) {
730 774
                 $this->concat($this->image[ $el ], $text);
731
-            }
732
-            elseif ($this->inchannel) {
775
+            } elseif ($this->inchannel) {
733 776
                 $this->concat($this->channel[ $el ], $text);
734 777
             }
735 778
         }
@@ -767,13 +810,11 @@  discard block
 block discarded – undo
767 810
             $array[$key][] = $tmp;
768 811
             $array[$key][] = $child;
769 812
             $tab = true;
770
-        }
771
-        elseif($tab === true)
813
+        } elseif($tab === true)
772 814
         {
773 815
             //Add an element in an existing array
774 816
             $array[$key][] = $child;
775
-        }
776
-        else
817
+        } else
777 818
         {
778 819
             //Add a simple element
779 820
             $array[$key] = $child;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/genericobject.class.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  *	\ingroup    core
21 21
  *	\brief      File of class of generic business class
22 22
  */
23
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
23
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
24 24
 
25 25
 
26 26
 /**
@@ -36,6 +36,6 @@  discard block
 block discarded – undo
36 36
      */
37 37
     function __construct($db)
38 38
     {
39
-        $this->db=$db;
39
+        $this->db = $db;
40 40
     }
41 41
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/menu.class.php 3 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,11 +31,11 @@  discard block
 block discarded – undo
31 31
     var $liste;
32 32
 
33 33
     /**
34
-	 *	Constructor
34
+     *	Constructor
35 35
      */
36 36
     function __construct()
37 37
     {
38
-      	$this->liste = array();
38
+            $this->liste = array();
39 39
     }
40 40
 
41 41
     /**
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      */
68 68
     function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
69 69
     {
70
-    	$this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
70
+        $this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
71 71
     }
72 72
 
73 73
     /**
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -65,9 +65,9 @@  discard block
 block discarded – undo
65 65
      * @param	string	$prefix		Prefix to title (image or picto)
66 66
      * @return	void
67 67
      */
68
-    function add($url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
68
+    function add($url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
69 69
     {
70
-    	$this->liste[]=array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
70
+    	$this->liste[] = array('url'=>$url, 'titre'=>$titre, 'level'=>$level, 'enabled'=>$enabled, 'target'=>$target, 'mainmenu'=>$mainmenu, 'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix);
71 71
     }
72 72
 
73 73
     /**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
      * @param	string	$prefix		Prefix to title (image or picto)
89 89
      * @return	void
90 90
      */
91
-    function insert($idafter, $url, $titre, $level=0, $enabled=1, $target='',$mainmenu='',$leftmenu='',$position=0, $id='', $idsel='', $classname='', $prefix='')
91
+    function insert($idafter, $url, $titre, $level = 0, $enabled = 1, $target = '', $mainmenu = '', $leftmenu = '', $position = 0, $id = '', $idsel = '', $classname = '', $prefix = '')
92 92
     {
93
-        $array_start = array_slice($this->liste,0,($idafter+1));
94
-        $array_new   = array(0=>array('url'=>$url,'titre'=>$titre,'level'=>$level,'enabled'=>$enabled,'target'=>$target,'mainmenu'=>$mainmenu,'leftmenu'=>$leftmenu,'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix));
95
-        $array_end   = array_slice($this->liste,($idafter+1));
96
-        $this->liste=array_merge($array_start,$array_new,$array_end);
93
+        $array_start = array_slice($this->liste, 0, ($idafter + 1));
94
+        $array_new   = array(0=>array('url'=>$url, 'titre'=>$titre, 'level'=>$level, 'enabled'=>$enabled, 'target'=>$target, 'mainmenu'=>$mainmenu, 'leftmenu'=>$leftmenu, 'position'=>$position, 'id'=>$id, 'idsel'=>$idsel, 'classname'=>$classname, 'prefix'=>$prefix));
95
+        $array_end   = array_slice($this->liste, ($idafter + 1));
96
+        $this->liste = array_merge($array_start, $array_new, $array_end);
97 97
     }
98 98
 
99 99
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
      */
118 118
     function getNbOfVisibleMenuEntries()
119 119
     {
120
-        $nb=0;
121
-        foreach($this->liste as $val)
120
+        $nb = 0;
121
+        foreach ($this->liste as $val)
122 122
         {
123
-            if (! empty($val['enabled'])) $nb++;
123
+            if (!empty($val['enabled'])) $nb++;
124 124
         }
125 125
         return $nb;
126 126
     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -120,7 +120,9 @@
 block discarded – undo
120 120
         $nb=0;
121 121
         foreach($this->liste as $val)
122 122
         {
123
-            if (! empty($val['enabled'])) $nb++;
123
+            if (! empty($val['enabled'])) {
124
+                $nb++;
125
+            }
124 126
         }
125 127
         return $nb;
126 128
     }
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/CMailFile.class.php 3 patches
Indentation   +1425 added lines, -1425 removed lines patch added patch discarded remove patch
@@ -36,323 +36,323 @@  discard block
 block discarded – undo
36 36
  */
37 37
 class CMailFile
38 38
 {
39
-	public $sendcontext;
40
-	public $sendmode;
41
-	public $sendsetup;
42
-
43
-	var $subject;      	// Topic:       Subject of email
44
-	var $addr_from;    	// From:		Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to).
45
-	// Sender:      Who send the email ("Sender" has sent emails on behalf of "From").
46
-	//              Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain.
47
-	// Return-Path: Email where to send bounds.
48
-	var $reply_to;		// Reply-To:	Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined)
49
-	var $errors_to;		// Errors-To:	Email where to send errors.
50
-	var $addr_to;
51
-	var $addr_cc;
52
-	var $addr_bcc;
53
-	var $trackid;
54
-
55
-	var $mixed_boundary;
56
-	var $related_boundary;
57
-	var $alternative_boundary;
58
-	var $deliveryreceipt;
59
-
60
-	var $eol;
61
-	var $eol2;
62
-
63
-	/**
64
-	 * @var string Error code (or message)
65
-	 */
66
-	public $error='';
67
-
68
-	var $smtps;			// Contains SMTPs object (if this method is used)
69
-	var $phpmailer;		// Contains PHPMailer object (if this method is used)
70
-
71
-	/**
72
-	 * @var string CSS
73
-	 */
74
-	public $css;
75
-	//! Defined css style for body background
76
-	var $styleCSS;
77
-	//! Defined background directly in body tag
78
-	var $bodyCSS;
79
-
80
-	var $headers;
81
-	var $message;
82
-
83
-	// Image
84
-	var $html;
85
-	var $image_boundary;
86
-	var $atleastoneimage=0;    // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
87
-	var $html_images=array();
88
-	var $images_encoded=array();
89
-	var $image_types = array(
39
+    public $sendcontext;
40
+    public $sendmode;
41
+    public $sendsetup;
42
+
43
+    var $subject;      	// Topic:       Subject of email
44
+    var $addr_from;    	// From:		Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to).
45
+    // Sender:      Who send the email ("Sender" has sent emails on behalf of "From").
46
+    //              Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain.
47
+    // Return-Path: Email where to send bounds.
48
+    var $reply_to;		// Reply-To:	Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined)
49
+    var $errors_to;		// Errors-To:	Email where to send errors.
50
+    var $addr_to;
51
+    var $addr_cc;
52
+    var $addr_bcc;
53
+    var $trackid;
54
+
55
+    var $mixed_boundary;
56
+    var $related_boundary;
57
+    var $alternative_boundary;
58
+    var $deliveryreceipt;
59
+
60
+    var $eol;
61
+    var $eol2;
62
+
63
+    /**
64
+     * @var string Error code (or message)
65
+     */
66
+    public $error='';
67
+
68
+    var $smtps;			// Contains SMTPs object (if this method is used)
69
+    var $phpmailer;		// Contains PHPMailer object (if this method is used)
70
+
71
+    /**
72
+     * @var string CSS
73
+     */
74
+    public $css;
75
+    //! Defined css style for body background
76
+    var $styleCSS;
77
+    //! Defined background directly in body tag
78
+    var $bodyCSS;
79
+
80
+    var $headers;
81
+    var $message;
82
+
83
+    // Image
84
+    var $html;
85
+    var $image_boundary;
86
+    var $atleastoneimage=0;    // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
87
+    var $html_images=array();
88
+    var $images_encoded=array();
89
+    var $image_types = array(
90 90
         'gif'  => 'image/gif',
91
-		'jpg'  => 'image/jpeg',
92
-		'jpeg' => 'image/jpeg',
93
-		'jpe'  => 'image/jpeg',
94
-		'bmp'  => 'image/bmp',
95
-		'png'  => 'image/png',
96
-		'tif'  => 'image/tiff',
91
+        'jpg'  => 'image/jpeg',
92
+        'jpeg' => 'image/jpeg',
93
+        'jpe'  => 'image/jpeg',
94
+        'bmp'  => 'image/bmp',
95
+        'png'  => 'image/png',
96
+        'tif'  => 'image/tiff',
97 97
         'tiff' => 'image/tiff',
98 98
     );
99 99
 
100 100
 
101
-	/**
102
-	 *	CMailFile
103
-	 *
104
-	 *	@param 	string	$subject             Topic/Subject of mail
105
-	 *	@param 	string	$to                  Recipients emails (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]"). Note: the keyword '__SUPERVISOREMAIL__' is not allowed here and must be replaced by caller.
106
-	 *	@param 	string	$from                Sender email      (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]")
107
-	 *	@param 	string	$msg                 Message
108
-	 *	@param 	array	$filename_list       List of files to attach (full path of filename on file system)
109
-	 *	@param 	array	$mimetype_list       List of MIME type of attached files
110
-	 *	@param 	array	$mimefilename_list   List of attached file name in message
111
-	 *	@param 	string	$addr_cc             Email cc
112
-	 *	@param 	string	$addr_bcc            Email bcc (Note: This is autocompleted with MAIN_MAIL_AUTOCOPY_TO if defined)
113
-	 *	@param 	int		$deliveryreceipt     Ask a delivery receipt
114
-	 *	@param 	int		$msgishtml           1=String IS already html, 0=String IS NOT html, -1=Unknown make autodetection (with fast mode, not reliable)
115
-	 *	@param 	string	$errors_to      	 Email for errors-to
116
-	 *	@param	string	$css                 Css option
117
-	 *	@param	string	$trackid             Tracking string (contains type and id of related element)
118
-	 *  @param  string  $moreinheader        More in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'phpmail' and 'smtps' for the moment)
119
-	 *  @param  string  $sendcontext      	 'standard', 'emailing', ... (used to define with sending mode and parameters to use)
120
-	 *  @param	string	$replyto			 Reply-to email (will be set to same value than From by default if not provided)
121
-	 */
122
-	function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='')
123
-	{
124
-		global $conf, $dolibarr_main_data_root;
125
-
126
-		$this->sendcontext = $sendcontext;
127
-
128
-		if (empty($replyto)) $replyto=$from;
129
-
130
-		// Define this->sendmode
131
-		$this->sendmode = '';
132
-		if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
133
-		{
134
-			$this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING;
135
-		}
136
-		if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE;
137
-		if (empty($this->sendmode)) $this->sendmode='mail';
138
-
139
-		// We define end of line (RFC 821).
140
-		$this->eol="\r\n";
141
-		// We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n).
142
-		$this->eol2="\r\n";
143
-		if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
144
-		{
145
-			$this->eol="\n";
146
-			$this->eol2="\n";
147
-			$moreinheader = str_replace("\r\n","\n",$moreinheader);
148
-		}
149
-
150
-		// On defini mixed_boundary
151
-		$this->mixed_boundary = "multipart_x." . time() . ".x_boundary";
152
-
153
-		// On defini related_boundary
154
-		$this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);	// Force md5 hash (does not contains special chars)
155
-
156
-		// On defini alternative_boundary
157
-		$this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);	// Force md5 hash (does not contains special chars)
158
-
159
-		dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG);
160
-		dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG);
161
-
162
-		if (empty($subject))
163
-		{
164
-			dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject");
165
-			$this->error='ErrorSubjectIsRequired';
166
-			return;
167
-		}
168
-		if (empty($msg))
169
-		{
170
-		    dol_syslog("CMailFile::CMailfile: Try to send an email with empty body");
171
-		    $msg='.';     // Avoid empty message (with empty message conten show a multipart structure)
172
-		}
173
-
174
-		// Detect if message is HTML (use fast method)
175
-		if ($msgishtml == -1)
176
-		{
177
-			$this->msgishtml = 0;
178
-			if (dol_textishtml($msg)) $this->msgishtml = 1;
179
-		}
180
-		else
181
-		{
182
-			$this->msgishtml = $msgishtml;
183
-		}
184
-
185
-		global $dolibarr_main_url_root;
186
-
187
-		// Define $urlwithroot
188
-		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
189
-		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
190
-		//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
191
-
192
-		// Replace relative /viewimage to absolute path
193
-		$msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
194
-
195
-		if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html.
196
-
197
-		// Detect images
198
-		if ($this->msgishtml)
199
-		{
200
-			$this->html = $msg;
201
-
202
-			if (! empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
203
-			{
204
-				$findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias');
205
-			}
206
-
207
-			// Define if there is at least one file
208
-			if ($findimg)
209
-			{
210
-				foreach ($this->html_images as $i => $val)
211
-				{
212
-					if ($this->html_images[$i])
213
-					{
214
-						$this->atleastoneimage=1;
215
-						dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG);
216
-					}
217
-				}
218
-			}
219
-		}
220
-
221
-		// Define if there is at least one file
222
-		if (is_array($filename_list))
223
-		{
224
-			foreach ($filename_list as $i => $val)
225
-			{
226
-				if ($filename_list[$i])
227
-				{
228
-					$this->atleastonefile=1;
229
-					dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG);
230
-				}
231
-			}
232
-		}
233
-
234
-		// Add autocopy to (Note: Adding bcc for specific modules are also done from pages)
235
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
236
-
237
-		// Action according to choosed sending method
238
-		if ($this->sendmode == 'mail')
239
-		{
240
-			// Use mail php function (default PHP method)
241
-			// ------------------------------------------
242
-
243
-			$smtp_headers = "";
244
-			$mime_headers = "";
245
-			$text_body = "";
246
-			$files_encoded = "";
247
-
248
-			// Define smtp_headers
249
-			$this->subject = $subject;
250
-			$this->addr_from = $from;
251
-			$this->reply_to = $replyto;
252
-			$this->errors_to = $errors_to;
253
-			$this->addr_to = $to;
254
-			$this->addr_cc = $addr_cc;
255
-			$this->addr_bcc = $addr_bcc;
256
-			$this->deliveryreceipt = $deliveryreceipt;
257
-			$this->trackid = $trackid;
258
-
259
-			$smtp_headers = $this->write_smtpheaders();
260
-			if (! empty($moreinheader)) $smtp_headers.=$moreinheader;   // $moreinheader contains the \r\n
261
-
262
-			// Define mime_headers
263
-			$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
264
-
265
-			if (! empty($this->html))
266
-			{
267
-				if (!empty($css))
268
-				{
269
-					$this->css = $css;
270
-					$this->buildCSS();    // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
271
-				}
272
-
273
-				$msg = $this->html;
274
-			}
275
-
276
-			// Define body in text_body
277
-			$text_body = $this->write_body($msg);
278
-
279
-			// Add attachments to text_encoded
280
-			if ($this->atleastonefile)
281
-			{
282
-				$files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list);
283
-			}
284
-
285
-			// We now define $this->headers and $this->message
286
-			$this->headers = $smtp_headers . $mime_headers;
287
-			// On nettoie le header pour qu'il ne se termine pas par un retour chariot.
288
-			// Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees
289
-			// comme des injections mail par les serveurs de messagerie.
290
-			$this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers);
291
-
292
-			//$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol;
293
-			$this->message = 'This is a message with multiple parts in MIME format.'.$this->eol;
294
-			$this->message.= $text_body . $files_encoded;
295
-			$this->message.= "--" . $this->mixed_boundary . "--" . $this->eol;
296
-		}
297
-		else if ($this->sendmode == 'smtps')
298
-		{
299
-			// Use SMTPS library
300
-			// ------------------------------------------
301
-
302
-			require_once DOL_DOCUMENT_ROOT.'/core/class/smtps.class.php';
303
-			$smtps = new SMTPs();
304
-			$smtps->setCharSet($conf->file->character_set_client);
305
-
306
-			$smtps->setSubject($this->encodetorfc2822($subject));
307
-			$smtps->setTO($this->getValidAddress($to,0,1));
308
-			$smtps->setFrom($this->getValidAddress($from,0,1));
309
-			$smtps->setTrackId($trackid);
310
-			$smtps->setReplyTo($this->getValidAddress($replyto,0,1));
311
-
312
-			if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
313
-
314
-			if (! empty($this->html))
315
-			{
316
-				if (!empty($css))
317
-				{
318
-					$this->css = $css;
319
-					$this->buildCSS();
320
-				}
321
-				$msg = $this->html;
322
-				$msg = $this->checkIfHTML($msg);
323
-			}
324
-
325
-			if ($this->msgishtml) $smtps->setBodyContent($msg,'html');
326
-			else $smtps->setBodyContent($msg,'plain');
327
-
328
-			if ($this->atleastoneimage)
329
-			{
330
-				foreach ($this->images_encoded as $img)
331
-				{
332
-					$smtps->setImageInline($img['image_encoded'],$img['name'],$img['content_type'],$img['cid']);
333
-				}
334
-			}
335
-
336
-			if ($this->atleastonefile)
337
-			{
338
-				foreach ($filename_list as $i => $val)
339
-				{
340
-					$content=file_get_contents($filename_list[$i]);
341
-					$smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]);
342
-				}
343
-			}
344
-
345
-			$smtps->setCC($addr_cc);
346
-			$smtps->setBCC($addr_bcc);
347
-			$smtps->setErrorsTo($errors_to);
348
-			$smtps->setDeliveryReceipt($deliveryreceipt);
349
-
350
-			$this->smtps=$smtps;
351
-		}
352
-		else if ($this->sendmode == 'swiftmailer')
353
-		{
354
-			// Use Swift Mailer library
355
-			// ------------------------------------------
101
+    /**
102
+     *	CMailFile
103
+     *
104
+     *	@param 	string	$subject             Topic/Subject of mail
105
+     *	@param 	string	$to                  Recipients emails (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]"). Note: the keyword '__SUPERVISOREMAIL__' is not allowed here and must be replaced by caller.
106
+     *	@param 	string	$from                Sender email      (RFC 2822: "Name firstname <email>[, ...]" or "email[, ...]" or "<email>[, ...]")
107
+     *	@param 	string	$msg                 Message
108
+     *	@param 	array	$filename_list       List of files to attach (full path of filename on file system)
109
+     *	@param 	array	$mimetype_list       List of MIME type of attached files
110
+     *	@param 	array	$mimefilename_list   List of attached file name in message
111
+     *	@param 	string	$addr_cc             Email cc
112
+     *	@param 	string	$addr_bcc            Email bcc (Note: This is autocompleted with MAIN_MAIL_AUTOCOPY_TO if defined)
113
+     *	@param 	int		$deliveryreceipt     Ask a delivery receipt
114
+     *	@param 	int		$msgishtml           1=String IS already html, 0=String IS NOT html, -1=Unknown make autodetection (with fast mode, not reliable)
115
+     *	@param 	string	$errors_to      	 Email for errors-to
116
+     *	@param	string	$css                 Css option
117
+     *	@param	string	$trackid             Tracking string (contains type and id of related element)
118
+     *  @param  string  $moreinheader        More in header. $moreinheader must contains the "\r\n" (TODO not supported for other MAIL_SEND_MODE different than 'phpmail' and 'smtps' for the moment)
119
+     *  @param  string  $sendcontext      	 'standard', 'emailing', ... (used to define with sending mode and parameters to use)
120
+     *  @param	string	$replyto			 Reply-to email (will be set to same value than From by default if not provided)
121
+     */
122
+    function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='')
123
+    {
124
+        global $conf, $dolibarr_main_data_root;
125
+
126
+        $this->sendcontext = $sendcontext;
127
+
128
+        if (empty($replyto)) $replyto=$from;
129
+
130
+        // Define this->sendmode
131
+        $this->sendmode = '';
132
+        if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
133
+        {
134
+            $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING;
135
+        }
136
+        if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE;
137
+        if (empty($this->sendmode)) $this->sendmode='mail';
138
+
139
+        // We define end of line (RFC 821).
140
+        $this->eol="\r\n";
141
+        // We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n).
142
+        $this->eol2="\r\n";
143
+        if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
144
+        {
145
+            $this->eol="\n";
146
+            $this->eol2="\n";
147
+            $moreinheader = str_replace("\r\n","\n",$moreinheader);
148
+        }
149
+
150
+        // On defini mixed_boundary
151
+        $this->mixed_boundary = "multipart_x." . time() . ".x_boundary";
152
+
153
+        // On defini related_boundary
154
+        $this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);	// Force md5 hash (does not contains special chars)
155
+
156
+        // On defini alternative_boundary
157
+        $this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);	// Force md5 hash (does not contains special chars)
158
+
159
+        dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG);
160
+        dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG);
161
+
162
+        if (empty($subject))
163
+        {
164
+            dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject");
165
+            $this->error='ErrorSubjectIsRequired';
166
+            return;
167
+        }
168
+        if (empty($msg))
169
+        {
170
+            dol_syslog("CMailFile::CMailfile: Try to send an email with empty body");
171
+            $msg='.';     // Avoid empty message (with empty message conten show a multipart structure)
172
+        }
173
+
174
+        // Detect if message is HTML (use fast method)
175
+        if ($msgishtml == -1)
176
+        {
177
+            $this->msgishtml = 0;
178
+            if (dol_textishtml($msg)) $this->msgishtml = 1;
179
+        }
180
+        else
181
+        {
182
+            $this->msgishtml = $msgishtml;
183
+        }
184
+
185
+        global $dolibarr_main_url_root;
186
+
187
+        // Define $urlwithroot
188
+        $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
189
+        $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
190
+        //$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
191
+
192
+        // Replace relative /viewimage to absolute path
193
+        $msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
194
+
195
+        if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html.
196
+
197
+        // Detect images
198
+        if ($this->msgishtml)
199
+        {
200
+            $this->html = $msg;
201
+
202
+            if (! empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
203
+            {
204
+                $findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias');
205
+            }
206
+
207
+            // Define if there is at least one file
208
+            if ($findimg)
209
+            {
210
+                foreach ($this->html_images as $i => $val)
211
+                {
212
+                    if ($this->html_images[$i])
213
+                    {
214
+                        $this->atleastoneimage=1;
215
+                        dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG);
216
+                    }
217
+                }
218
+            }
219
+        }
220
+
221
+        // Define if there is at least one file
222
+        if (is_array($filename_list))
223
+        {
224
+            foreach ($filename_list as $i => $val)
225
+            {
226
+                if ($filename_list[$i])
227
+                {
228
+                    $this->atleastonefile=1;
229
+                    dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG);
230
+                }
231
+            }
232
+        }
233
+
234
+        // Add autocopy to (Note: Adding bcc for specific modules are also done from pages)
235
+        if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
236
+
237
+        // Action according to choosed sending method
238
+        if ($this->sendmode == 'mail')
239
+        {
240
+            // Use mail php function (default PHP method)
241
+            // ------------------------------------------
242
+
243
+            $smtp_headers = "";
244
+            $mime_headers = "";
245
+            $text_body = "";
246
+            $files_encoded = "";
247
+
248
+            // Define smtp_headers
249
+            $this->subject = $subject;
250
+            $this->addr_from = $from;
251
+            $this->reply_to = $replyto;
252
+            $this->errors_to = $errors_to;
253
+            $this->addr_to = $to;
254
+            $this->addr_cc = $addr_cc;
255
+            $this->addr_bcc = $addr_bcc;
256
+            $this->deliveryreceipt = $deliveryreceipt;
257
+            $this->trackid = $trackid;
258
+
259
+            $smtp_headers = $this->write_smtpheaders();
260
+            if (! empty($moreinheader)) $smtp_headers.=$moreinheader;   // $moreinheader contains the \r\n
261
+
262
+            // Define mime_headers
263
+            $mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
264
+
265
+            if (! empty($this->html))
266
+            {
267
+                if (!empty($css))
268
+                {
269
+                    $this->css = $css;
270
+                    $this->buildCSS();    // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
271
+                }
272
+
273
+                $msg = $this->html;
274
+            }
275
+
276
+            // Define body in text_body
277
+            $text_body = $this->write_body($msg);
278
+
279
+            // Add attachments to text_encoded
280
+            if ($this->atleastonefile)
281
+            {
282
+                $files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list);
283
+            }
284
+
285
+            // We now define $this->headers and $this->message
286
+            $this->headers = $smtp_headers . $mime_headers;
287
+            // On nettoie le header pour qu'il ne se termine pas par un retour chariot.
288
+            // Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees
289
+            // comme des injections mail par les serveurs de messagerie.
290
+            $this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers);
291
+
292
+            //$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol;
293
+            $this->message = 'This is a message with multiple parts in MIME format.'.$this->eol;
294
+            $this->message.= $text_body . $files_encoded;
295
+            $this->message.= "--" . $this->mixed_boundary . "--" . $this->eol;
296
+        }
297
+        else if ($this->sendmode == 'smtps')
298
+        {
299
+            // Use SMTPS library
300
+            // ------------------------------------------
301
+
302
+            require_once DOL_DOCUMENT_ROOT.'/core/class/smtps.class.php';
303
+            $smtps = new SMTPs();
304
+            $smtps->setCharSet($conf->file->character_set_client);
305
+
306
+            $smtps->setSubject($this->encodetorfc2822($subject));
307
+            $smtps->setTO($this->getValidAddress($to,0,1));
308
+            $smtps->setFrom($this->getValidAddress($from,0,1));
309
+            $smtps->setTrackId($trackid);
310
+            $smtps->setReplyTo($this->getValidAddress($replyto,0,1));
311
+
312
+            if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
313
+
314
+            if (! empty($this->html))
315
+            {
316
+                if (!empty($css))
317
+                {
318
+                    $this->css = $css;
319
+                    $this->buildCSS();
320
+                }
321
+                $msg = $this->html;
322
+                $msg = $this->checkIfHTML($msg);
323
+            }
324
+
325
+            if ($this->msgishtml) $smtps->setBodyContent($msg,'html');
326
+            else $smtps->setBodyContent($msg,'plain');
327
+
328
+            if ($this->atleastoneimage)
329
+            {
330
+                foreach ($this->images_encoded as $img)
331
+                {
332
+                    $smtps->setImageInline($img['image_encoded'],$img['name'],$img['content_type'],$img['cid']);
333
+                }
334
+            }
335
+
336
+            if ($this->atleastonefile)
337
+            {
338
+                foreach ($filename_list as $i => $val)
339
+                {
340
+                    $content=file_get_contents($filename_list[$i]);
341
+                    $smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]);
342
+                }
343
+            }
344
+
345
+            $smtps->setCC($addr_cc);
346
+            $smtps->setBCC($addr_bcc);
347
+            $smtps->setErrorsTo($errors_to);
348
+            $smtps->setDeliveryReceipt($deliveryreceipt);
349
+
350
+            $this->smtps=$smtps;
351
+        }
352
+        else if ($this->sendmode == 'swiftmailer')
353
+        {
354
+            // Use Swift Mailer library
355
+            // ------------------------------------------
356 356
 
357 357
             $host = dol_getprefix('email');
358 358
 
@@ -361,419 +361,419 @@  discard block
 block discarded – undo
361 361
             require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/InvalidEmail.php';
362 362
             require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Exception/NoDomainPart.php';
363 363
             require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailParser.php';
364
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php';
365
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php';
366
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php';
367
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/LocalTooLong.php';
368
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php';
369
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/DomainPart.php';
370
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php';
371
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/EmailValidation.php';
372
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php';
364
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailLexer.php';
365
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/EmailValidator.php';
366
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/Warning.php';
367
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Warning/LocalTooLong.php';
368
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/Parser.php';
369
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/DomainPart.php';
370
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Parser/LocalPart.php';
371
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/EmailValidation.php';
372
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/egulias/email-validator/EmailValidator/Validation/RFCValidation.php';
373 373
 
374 374
             require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/InputByteStream.php';
375
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signer.php';
376
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php';
377
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php';
378
-			//require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/SignedMessage.php';
379
-			require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
380
-			// Create the message
381
-			//$this->message = Swift_Message::newInstance();
382
-			$this->message = new Swift_Message();
375
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signer.php';
376
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/HeaderSigner.php';
377
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/Signers/DKIMSigner.php';
378
+            //require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/classes/Swift/SignedMessage.php';
379
+            require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
380
+            // Create the message
381
+            //$this->message = Swift_Message::newInstance();
382
+            $this->message = new Swift_Message();
383 383
             //$this->message = new Swift_SignedMessage();
384 384
             // Adding a trackid header to a message
385
-			$headers = $this->message->getHeaders();
386
-			$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
387
-			$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
388
-			$msgid = $headers->get('Message-ID');
389
-			$msgid->setId($headerID);
390
-			$headers->addIdHeader('References', $headerID);
391
-			// TODO if (! empty($moreinheader)) ...
392
-
393
-			// Give the message a subject
394
-			try {
395
-				$result = $this->message->setSubject($subject);
396
-			} catch (Exception $e) {
397
-				$this->errors[] =  $e->getMessage();
398
-			}
399
-
400
-			// Set the From address with an associative array
401
-			//$this->message->setFrom(array('[email protected]' => 'John Doe'));
402
-			if (! empty($from)) {
385
+            $headers = $this->message->getHeaders();
386
+            $headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
387
+            $headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
388
+            $msgid = $headers->get('Message-ID');
389
+            $msgid->setId($headerID);
390
+            $headers->addIdHeader('References', $headerID);
391
+            // TODO if (! empty($moreinheader)) ...
392
+
393
+            // Give the message a subject
394
+            try {
395
+                $result = $this->message->setSubject($subject);
396
+            } catch (Exception $e) {
397
+                $this->errors[] =  $e->getMessage();
398
+            }
399
+
400
+            // Set the From address with an associative array
401
+            //$this->message->setFrom(array('[email protected]' => 'John Doe'));
402
+            if (! empty($from)) {
403 403
                 try {
404
-                	$result = $this->message->setFrom($this->getArrayAddress($from));
404
+                    $result = $this->message->setFrom($this->getArrayAddress($from));
405 405
                 } catch (Exception $e) {
406 406
                     $this->errors[] = $e->getMessage();
407 407
                 }
408 408
             }
409 409
 
410
-			// Set the To addresses with an associative array
411
-			if (! empty($to)) {
410
+            // Set the To addresses with an associative array
411
+            if (! empty($to)) {
412 412
                 try {
413
-                	$result = $this->message->setTo($this->getArrayAddress($to));
413
+                    $result = $this->message->setTo($this->getArrayAddress($to));
414 414
                 } catch (Exception $e) {
415 415
                     $this->errors[] = $e->getMessage();
416 416
                 }
417 417
             }
418 418
 
419
-			if (! empty($replyto)) {
419
+            if (! empty($replyto)) {
420 420
                 try {
421
-                	$result = $this->message->SetReplyTo($this->getArrayAddress($replyto));
421
+                    $result = $this->message->SetReplyTo($this->getArrayAddress($replyto));
422 422
                 } catch (Exception $e) {
423 423
                     $this->errors[] = $e->getMessage();
424 424
                 }
425 425
             }
426 426
 
427
-			try {
428
-				$result = $this->message->setCharSet($conf->file->character_set_client);
429
-			} catch (Exception $e) {
430
-				$this->errors[] =  $e->getMessage();
431
-			}
432
-
433
-			if (! empty($this->html))
434
-			{
435
-				if (!empty($css))
436
-				{
437
-					$this->css = $css;
438
-					$this->buildCSS();
439
-				}
440
-				$msg = $this->html;
441
-				$msg = $this->checkIfHTML($msg);
442
-			}
443
-
444
-			if ($this->atleastoneimage)
445
-			{
446
-				foreach ($this->images_encoded as $img)
447
-				{
448
-					//$img['fullpath'],$img['image_encoded'],$img['name'],$img['content_type'],$img['cid']
449
-					$attachment = Swift_Image::fromPath($img['fullpath'], $img['content_type']);
450
-					// embed image
451
-					$imgcid = $this->message->embed($attachment);
452
-					// replace cid by the one created by swiftmail in html message
453
-					$msg = str_replace("cid:".$img['cid'], $imgcid, $msg);
454
-				}
455
-			}
456
-
457
-			if ($this->msgishtml) {
458
-				$this->message->setBody($msg,'text/html');
459
-				// And optionally an alternative body
460
-				$this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain');
461
-			} else {
462
-				$this->message->setBody($msg,'text/plain');
463
-				// And optionally an alternative body
464
-				$this->message->addPart($msg, 'text/html');
465
-			}
466
-
467
-			if ($this->atleastonefile)
468
-			{
469
-				foreach ($filename_list as $i => $val)
470
-				{
471
-					//$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]));
472
-					$attachment = Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]);
473
-					$this->message->attach($attachment);
474
-				}
475
-			}
476
-
477
-			if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
-			if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
479
-			//if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to);
480
-			if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from));
481
-		}
482
-		else
483
-		{
484
-			// Send mail method not correctly defined
485
-			// --------------------------------------
486
-			$this->error = 'Bad value for sendmode';
487
-		}
488
-	}
489
-
490
-
491
-	/**
492
-	 * Send mail that was prepared by constructor.
493
-	 *
494
-	 * @return    boolean     True if mail sent, false otherwise
495
-	 */
496
-	function sendfile()
497
-	{
498
-		global $conf,$db,$langs;
499
-
500
-		$errorlevel=error_reporting();
501
-		//error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
502
-
503
-		$res=false;
504
-
505
-		if (empty($conf->global->MAIN_DISABLE_ALL_MAILS) || !empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
506
-		{
507
-			require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
508
-			$hookmanager = new HookManager($db);
509
-			$hookmanager->initHooks(array('mail'));
510
-
511
-			$parameters=array(); $action='';
512
-			$reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
513
-			if ($reshook < 0)
514
-			{
515
-				$this->error = "Error in hook maildao sendMail " . $reshook;
516
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
517
-
518
-				return $reshook;
519
-			}
520
-			if ($reshook == 1)	// Hook replace standard code
521
-			{
522
-				return true;
523
-			}
524
-
525
-			// Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL
526
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10;
527
-			$tmparray1 = explode(',', $this->addr_to);
528
-			if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)
529
-			{
530
-				$this->error = 'Too much recipients in to:';
531
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
532
-				return false;
533
-			}
534
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10;
535
-			$tmparray2 = explode(',', $this->addr_cc);
536
-			if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)
537
-			{
538
-				$this->error = 'Too much recipients in cc:';
539
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
540
-				return false;
541
-			}
542
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10;
543
-			$tmparray3 = explode(',', $this->addr_bcc);
544
-			if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)
545
-			{
546
-				$this->error = 'Too much recipients in bcc:';
547
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
548
-				return false;
549
-			}
550
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10;
551
-			if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
552
-			{
553
-				$this->error = 'Too much recipients in to:, cc:, bcc:';
554
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
555
-				return false;
556
-			}
557
-
558
-			$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
559
-			$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
560
-			$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
561
-			$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
562
-			$keyfortls       ='MAIN_MAIL_EMAIL_TLS';
563
-			$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
564
-			if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
565
-			{
566
-				$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
567
-				$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
568
-				$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
569
-				$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
570
-				$keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
571
-				$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
572
-			}
573
-
574
-			if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
575
-			{
576
-				$this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO;
577
-				$this->addr_cc = '';
578
-				$this->addr_bcc = '';
579
-			}
580
-
581
-			// Action according to choosed sending method
582
-			if ($this->sendmode == 'mail')
583
-			{
584
-				// Use mail php function (default PHP method)
585
-				// ------------------------------------------
586
-				dol_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG);
587
-				dol_syslog("CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG);
588
-				//dol_syslog("CMailFile::sendfile message=\n".$message);
589
-
590
-				// If Windows, sendmail_from must be defined
591
-				if (isset($_SERVER["WINDIR"]))
592
-				{
593
-					if (empty($this->addr_from)) $this->addr_from = '[email protected]';
594
-					@ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2));
595
-				}
596
-
597
-				// Force parameters
598
-				if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver);
599
-				if (! empty($conf->global->$keyforsmtpport))   ini_set('smtp_port',$conf->global->$keyforsmtpport);
600
-
601
-				$res=true;
602
-				if ($res && ! $this->subject)
603
-				{
604
-					$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
605
-					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
606
-					$res=false;
607
-				}
608
-				$dest=$this->getValidAddress($this->addr_to,2);
609
-				if ($res && ! $dest)
610
-				{
611
-					$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
612
-					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
613
-					$res=false;
614
-				}
615
-
616
-				if ($res)
617
-				{
618
-					$additionnalparam = '';	// By default
619
-					if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
620
-					{
621
-						// le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA
622
-						// Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie.
623
-						// Having this variable defined may create problems with some sendmail (option -f refused)
624
-						// Having this variable not defined may create problems with some other sendmail (option -f required)
625
-						$additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') );
626
-					}
627
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
628
-					{
629
-						$additionnalparam .= ($additionnalparam?' ':'').'-ba';
630
-					}
631
-
632
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params
633
-
634
-					dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
635
-
636
-					$this->message=stripslashes($this->message);
637
-
638
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
639
-
640
-					if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
641
-					else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers);
642
-
643
-					if (! $res)
644
-					{
645
-						$langs->load("errors");
646
-						$this->error="Failed to send mail with php mail";
647
-						$linuxlike=1;
648
-						if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
649
-						if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
650
-						if (! $linuxlike)
651
-						{
652
-							$this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port');	// This values are value used only for non linuxlike systems
653
-						}
654
-						$this->error.=".<br>";
655
-						$this->error.=$langs->trans("ErrorPhpMailDelivery");
656
-						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
657
-					}
658
-					else
659
-					{
660
-						dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
661
-					}
662
-				}
663
-
664
-				if (isset($_SERVER["WINDIR"]))
665
-				{
666
-					@ini_restore('sendmail_from');
667
-				}
668
-
669
-				// Restore parameters
670
-				if (! empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
-				if (! empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
672
-			}
673
-			else if ($this->sendmode == 'smtps')
674
-			{
675
-				if (! is_object($this->smtps))
676
-				{
677
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors.";
678
-					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
679
-					return false;
680
-				}
681
-
682
-				// Use SMTPS library
683
-				// ------------------------------------------
684
-				$this->smtps->setTransportType(0);	// Only this method is coded in SMTPs library
685
-
686
-				// Clean parameters
687
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
688
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
689
-
690
-				// If we use SSL/TLS
691
-				$server=$conf->global->$keyforsmtpserver;
692
-				$secure='';
693
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
694
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
695
-				$server=($secure?$secure.'://':'').$server;
696
-
697
-				$port=$conf->global->$keyforsmtpport;
698
-
699
-				$this->smtps->setHost($server);
700
-				$this->smtps->setPort($port); // 25, 465...;
701
-
702
-				$loginid=''; $loginpass='';
703
-				if (! empty($conf->global->$keyforsmtpid))
704
-				{
705
-					$loginid = $conf->global->$keyforsmtpid;
706
-					$this->smtps->setID($loginid);
707
-				}
708
-				if (! empty($conf->global->$keyforsmtppw))
709
-				{
710
-					$loginpass = $conf->global->$keyforsmtppw;
711
-					$this->smtps->setPW($loginpass);
712
-				}
713
-
714
-				$res=true;
715
-				$from=$this->smtps->getFrom('org');
716
-				if ($res && ! $from)
717
-				{
718
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
719
-					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
720
-					$res=false;
721
-				}
722
-				$dest=$this->smtps->getTo();
723
-				if ($res && ! $dest)
724
-				{
725
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
726
-					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
727
-					$res=false;
728
-				}
729
-
730
-				if ($res)
731
-				{
732
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
733
-
734
-					$result=$this->smtps->sendMsg();
735
-					//print $result;
736
-
737
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
738
-
739
-					$result=$this->smtps->getErrors();
740
-					if (empty($this->error) && empty($result))
741
-					{
742
-						dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
743
-						$res=true;
744
-					}
745
-					else
746
-					{
747
-						if (empty($this->error)) $this->error=$result;
748
-						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
749
-						$res=false;
750
-					}
751
-				}
752
-			}
753
-			else if ($this->sendmode == 'swiftmailer')
754
-			{
755
-				// Use Swift Mailer library
756
-				// ------------------------------------------
757
-				require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
758
-
759
-				// Clean parameters
760
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
761
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
762
-
763
-				// If we use SSL/TLS
764
-				$server = $conf->global->$keyforsmtpserver;
765
-				$secure = '';
766
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
767
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
768
-
769
-				$this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
770
-
771
-				if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
-				if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
773
-				//$smtps->_msgReplyTo  = '[email protected]';
774
-
775
-				// Create the Mailer using your created Transport
776
-				$this->mailer = new Swift_Mailer($this->transport);
427
+            try {
428
+                $result = $this->message->setCharSet($conf->file->character_set_client);
429
+            } catch (Exception $e) {
430
+                $this->errors[] =  $e->getMessage();
431
+            }
432
+
433
+            if (! empty($this->html))
434
+            {
435
+                if (!empty($css))
436
+                {
437
+                    $this->css = $css;
438
+                    $this->buildCSS();
439
+                }
440
+                $msg = $this->html;
441
+                $msg = $this->checkIfHTML($msg);
442
+            }
443
+
444
+            if ($this->atleastoneimage)
445
+            {
446
+                foreach ($this->images_encoded as $img)
447
+                {
448
+                    //$img['fullpath'],$img['image_encoded'],$img['name'],$img['content_type'],$img['cid']
449
+                    $attachment = Swift_Image::fromPath($img['fullpath'], $img['content_type']);
450
+                    // embed image
451
+                    $imgcid = $this->message->embed($attachment);
452
+                    // replace cid by the one created by swiftmail in html message
453
+                    $msg = str_replace("cid:".$img['cid'], $imgcid, $msg);
454
+                }
455
+            }
456
+
457
+            if ($this->msgishtml) {
458
+                $this->message->setBody($msg,'text/html');
459
+                // And optionally an alternative body
460
+                $this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain');
461
+            } else {
462
+                $this->message->setBody($msg,'text/plain');
463
+                // And optionally an alternative body
464
+                $this->message->addPart($msg, 'text/html');
465
+            }
466
+
467
+            if ($this->atleastonefile)
468
+            {
469
+                foreach ($filename_list as $i => $val)
470
+                {
471
+                    //$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]));
472
+                    $attachment = Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]);
473
+                    $this->message->attach($attachment);
474
+                }
475
+            }
476
+
477
+            if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
+            if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
479
+            //if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to);
480
+            if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from));
481
+        }
482
+        else
483
+        {
484
+            // Send mail method not correctly defined
485
+            // --------------------------------------
486
+            $this->error = 'Bad value for sendmode';
487
+        }
488
+    }
489
+
490
+
491
+    /**
492
+     * Send mail that was prepared by constructor.
493
+     *
494
+     * @return    boolean     True if mail sent, false otherwise
495
+     */
496
+    function sendfile()
497
+    {
498
+        global $conf,$db,$langs;
499
+
500
+        $errorlevel=error_reporting();
501
+        //error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
502
+
503
+        $res=false;
504
+
505
+        if (empty($conf->global->MAIN_DISABLE_ALL_MAILS) || !empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
506
+        {
507
+            require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
508
+            $hookmanager = new HookManager($db);
509
+            $hookmanager->initHooks(array('mail'));
510
+
511
+            $parameters=array(); $action='';
512
+            $reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
513
+            if ($reshook < 0)
514
+            {
515
+                $this->error = "Error in hook maildao sendMail " . $reshook;
516
+                dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
517
+
518
+                return $reshook;
519
+            }
520
+            if ($reshook == 1)	// Hook replace standard code
521
+            {
522
+                return true;
523
+            }
524
+
525
+            // Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL
526
+            if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10;
527
+            $tmparray1 = explode(',', $this->addr_to);
528
+            if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)
529
+            {
530
+                $this->error = 'Too much recipients in to:';
531
+                dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
532
+                return false;
533
+            }
534
+            if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10;
535
+            $tmparray2 = explode(',', $this->addr_cc);
536
+            if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)
537
+            {
538
+                $this->error = 'Too much recipients in cc:';
539
+                dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
540
+                return false;
541
+            }
542
+            if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10;
543
+            $tmparray3 = explode(',', $this->addr_bcc);
544
+            if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)
545
+            {
546
+                $this->error = 'Too much recipients in bcc:';
547
+                dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
548
+                return false;
549
+            }
550
+            if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10;
551
+            if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
552
+            {
553
+                $this->error = 'Too much recipients in to:, cc:, bcc:';
554
+                dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
555
+                return false;
556
+            }
557
+
558
+            $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
559
+            $keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
560
+            $keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
561
+            $keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
562
+            $keyfortls       ='MAIN_MAIL_EMAIL_TLS';
563
+            $keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
564
+            if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
565
+            {
566
+                $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
567
+                $keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
568
+                $keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
569
+                $keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
570
+                $keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
571
+                $keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
572
+            }
573
+
574
+            if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
575
+            {
576
+                $this->addr_to = $conf->global->MAIN_MAIL_FORCE_SENDTO;
577
+                $this->addr_cc = '';
578
+                $this->addr_bcc = '';
579
+            }
580
+
581
+            // Action according to choosed sending method
582
+            if ($this->sendmode == 'mail')
583
+            {
584
+                // Use mail php function (default PHP method)
585
+                // ------------------------------------------
586
+                dol_syslog("CMailFile::sendfile addr_to=".$this->addr_to.", subject=".$this->subject, LOG_DEBUG);
587
+                dol_syslog("CMailFile::sendfile header=\n".$this->headers, LOG_DEBUG);
588
+                //dol_syslog("CMailFile::sendfile message=\n".$message);
589
+
590
+                // If Windows, sendmail_from must be defined
591
+                if (isset($_SERVER["WINDIR"]))
592
+                {
593
+                    if (empty($this->addr_from)) $this->addr_from = '[email protected]';
594
+                    @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2));
595
+                }
596
+
597
+                // Force parameters
598
+                if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver);
599
+                if (! empty($conf->global->$keyforsmtpport))   ini_set('smtp_port',$conf->global->$keyforsmtpport);
600
+
601
+                $res=true;
602
+                if ($res && ! $this->subject)
603
+                {
604
+                    $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
605
+                    dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
606
+                    $res=false;
607
+                }
608
+                $dest=$this->getValidAddress($this->addr_to,2);
609
+                if ($res && ! $dest)
610
+                {
611
+                    $this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
612
+                    dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
613
+                    $res=false;
614
+                }
615
+
616
+                if ($res)
617
+                {
618
+                    $additionnalparam = '';	// By default
619
+                    if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
620
+                    {
621
+                        // le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA
622
+                        // Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie.
623
+                        // Having this variable defined may create problems with some sendmail (option -f refused)
624
+                        // Having this variable not defined may create problems with some other sendmail (option -f required)
625
+                        $additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') );
626
+                    }
627
+                    if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
628
+                    {
629
+                        $additionnalparam .= ($additionnalparam?' ':'').'-ba';
630
+                    }
631
+
632
+                    if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params
633
+
634
+                    dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
635
+
636
+                    $this->message=stripslashes($this->message);
637
+
638
+                    if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
639
+
640
+                    if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
641
+                    else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers);
642
+
643
+                    if (! $res)
644
+                    {
645
+                        $langs->load("errors");
646
+                        $this->error="Failed to send mail with php mail";
647
+                        $linuxlike=1;
648
+                        if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
649
+                        if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
650
+                        if (! $linuxlike)
651
+                        {
652
+                            $this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port');	// This values are value used only for non linuxlike systems
653
+                        }
654
+                        $this->error.=".<br>";
655
+                        $this->error.=$langs->trans("ErrorPhpMailDelivery");
656
+                        dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
657
+                    }
658
+                    else
659
+                    {
660
+                        dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
661
+                    }
662
+                }
663
+
664
+                if (isset($_SERVER["WINDIR"]))
665
+                {
666
+                    @ini_restore('sendmail_from');
667
+                }
668
+
669
+                // Restore parameters
670
+                if (! empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
+                if (! empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
672
+            }
673
+            else if ($this->sendmode == 'smtps')
674
+            {
675
+                if (! is_object($this->smtps))
676
+                {
677
+                    $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors.";
678
+                    dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
679
+                    return false;
680
+                }
681
+
682
+                // Use SMTPS library
683
+                // ------------------------------------------
684
+                $this->smtps->setTransportType(0);	// Only this method is coded in SMTPs library
685
+
686
+                // Clean parameters
687
+                if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
688
+                if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
689
+
690
+                // If we use SSL/TLS
691
+                $server=$conf->global->$keyforsmtpserver;
692
+                $secure='';
693
+                if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
694
+                if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
695
+                $server=($secure?$secure.'://':'').$server;
696
+
697
+                $port=$conf->global->$keyforsmtpport;
698
+
699
+                $this->smtps->setHost($server);
700
+                $this->smtps->setPort($port); // 25, 465...;
701
+
702
+                $loginid=''; $loginpass='';
703
+                if (! empty($conf->global->$keyforsmtpid))
704
+                {
705
+                    $loginid = $conf->global->$keyforsmtpid;
706
+                    $this->smtps->setID($loginid);
707
+                }
708
+                if (! empty($conf->global->$keyforsmtppw))
709
+                {
710
+                    $loginpass = $conf->global->$keyforsmtppw;
711
+                    $this->smtps->setPW($loginpass);
712
+                }
713
+
714
+                $res=true;
715
+                $from=$this->smtps->getFrom('org');
716
+                if ($res && ! $from)
717
+                {
718
+                    $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
719
+                    dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
720
+                    $res=false;
721
+                }
722
+                $dest=$this->smtps->getTo();
723
+                if ($res && ! $dest)
724
+                {
725
+                    $this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
726
+                    dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
727
+                    $res=false;
728
+                }
729
+
730
+                if ($res)
731
+                {
732
+                    if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
733
+
734
+                    $result=$this->smtps->sendMsg();
735
+                    //print $result;
736
+
737
+                    if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
738
+
739
+                    $result=$this->smtps->getErrors();
740
+                    if (empty($this->error) && empty($result))
741
+                    {
742
+                        dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
743
+                        $res=true;
744
+                    }
745
+                    else
746
+                    {
747
+                        if (empty($this->error)) $this->error=$result;
748
+                        dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
749
+                        $res=false;
750
+                    }
751
+                }
752
+            }
753
+            else if ($this->sendmode == 'swiftmailer')
754
+            {
755
+                // Use Swift Mailer library
756
+                // ------------------------------------------
757
+                require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
758
+
759
+                // Clean parameters
760
+                if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
761
+                if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
762
+
763
+                // If we use SSL/TLS
764
+                $server = $conf->global->$keyforsmtpserver;
765
+                $secure = '';
766
+                if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
767
+                if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
768
+
769
+                $this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
770
+
771
+                if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
+                if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
773
+                //$smtps->_msgReplyTo  = '[email protected]';
774
+
775
+                // Create the Mailer using your created Transport
776
+                $this->mailer = new Swift_Mailer($this->transport);
777 777
 
778 778
                 // DKIM SIGN
779 779
                 if ($conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED) {
@@ -785,770 +785,770 @@  discard block
 block discarded – undo
785 785
                 }
786 786
 
787 787
                 if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
788
-					// To use the ArrayLogger
789
-					$this->logger = new Swift_Plugins_Loggers_ArrayLogger();
790
-					// Or to use the Echo Logger
791
-					//$this->logger = new Swift_Plugins_Loggers_EchoLogger();
792
-					$this->mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($this->logger));
793
-				}
794
-				// send mail
795
-				try {
796
-					$result = $this->mailer->send($this->message);
797
-				} catch (Exception $e) {
798
-					$this->error =  $e->getMessage();
799
-				}
800
-				if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
801
-
802
-				$res = true;
803
-				if (! empty($this->error) || ! $result) {
804
-					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
805
-					$res=false;
806
-				}
807
-				else
808
-				{
809
-					dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
810
-				}
811
-			}
812
-			else
813
-			{
814
-				// Send mail method not correctly defined
815
-				// --------------------------------------
816
-
817
-				return 'Bad value for sendmode';
818
-			}
819
-
820
-			$parameters=array(); $action='';
821
-			$reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
822
-			if ($reshook < 0)
823
-			{
824
-				$this->error = "Error in hook maildao sendMailAfter " . $reshook;
825
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
826
-
827
-				return $reshook;
828
-			}
829
-		}
830
-		else
831
-		{
832
-			$this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
833
-			dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING);
834
-		}
835
-
836
-		error_reporting($errorlevel);              // Reactive niveau erreur origine
837
-
838
-		return $res;
839
-	}
840
-
841
-	/**
842
-	 * Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word
843
-	 *
844
-	 * @param string $stringtoencode String to encode
845
-	 * @return string                string encoded
846
-	 */
847
-	static function encodetorfc2822($stringtoencode)
848
-	{
849
-		global $conf;
850
-		return '=?'.$conf->file->character_set_client.'?B?'.base64_encode($stringtoencode).'?=';
851
-	}
788
+                    // To use the ArrayLogger
789
+                    $this->logger = new Swift_Plugins_Loggers_ArrayLogger();
790
+                    // Or to use the Echo Logger
791
+                    //$this->logger = new Swift_Plugins_Loggers_EchoLogger();
792
+                    $this->mailer->registerPlugin(new Swift_Plugins_LoggerPlugin($this->logger));
793
+                }
794
+                // send mail
795
+                try {
796
+                    $result = $this->mailer->send($this->message);
797
+                } catch (Exception $e) {
798
+                    $this->error =  $e->getMessage();
799
+                }
800
+                if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
801
+
802
+                $res = true;
803
+                if (! empty($this->error) || ! $result) {
804
+                    dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
805
+                    $res=false;
806
+                }
807
+                else
808
+                {
809
+                    dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
810
+                }
811
+            }
812
+            else
813
+            {
814
+                // Send mail method not correctly defined
815
+                // --------------------------------------
816
+
817
+                return 'Bad value for sendmode';
818
+            }
819
+
820
+            $parameters=array(); $action='';
821
+            $reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
822
+            if ($reshook < 0)
823
+            {
824
+                $this->error = "Error in hook maildao sendMailAfter " . $reshook;
825
+                dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
826
+
827
+                return $reshook;
828
+            }
829
+        }
830
+        else
831
+        {
832
+            $this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
833
+            dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING);
834
+        }
835
+
836
+        error_reporting($errorlevel);              // Reactive niveau erreur origine
837
+
838
+        return $res;
839
+    }
840
+
841
+    /**
842
+     * Encode subject according to RFC 2822 - http://en.wikipedia.org/wiki/MIME#Encoded-Word
843
+     *
844
+     * @param string $stringtoencode String to encode
845
+     * @return string                string encoded
846
+     */
847
+    static function encodetorfc2822($stringtoencode)
848
+    {
849
+        global $conf;
850
+        return '=?'.$conf->file->character_set_client.'?B?'.base64_encode($stringtoencode).'?=';
851
+    }
852 852
 
853 853
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
854
-	/**
855
-	 * Read a file on disk and return encoded content for emails (mode = 'mail')
856
-	 *
857
-	 * @param	string	$sourcefile		Path to file to encode
858
-	 * @return 	int					    <0 if KO, encoded string if OK
859
-	 */
860
-	function _encode_file($sourcefile)
861
-	{
854
+    /**
855
+     * Read a file on disk and return encoded content for emails (mode = 'mail')
856
+     *
857
+     * @param	string	$sourcefile		Path to file to encode
858
+     * @return 	int					    <0 if KO, encoded string if OK
859
+     */
860
+    function _encode_file($sourcefile)
861
+    {
862 862
         // phpcs:enable
863
-		$newsourcefile=dol_osencode($sourcefile);
864
-
865
-		if (is_readable($newsourcefile))
866
-		{
867
-			$contents = file_get_contents($newsourcefile);	// Need PHP 4.3
868
-			$encoded = chunk_split(base64_encode($contents), 76, $this->eol);    // 76 max is defined into http://tools.ietf.org/html/rfc2047
869
-			return $encoded;
870
-		}
871
-		else
872
-		{
873
-			$this->error="Error: Can't read file '".$sourcefile."' into _encode_file";
874
-			dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR);
875
-			return -1;
876
-		}
877
-	}
863
+        $newsourcefile=dol_osencode($sourcefile);
864
+
865
+        if (is_readable($newsourcefile))
866
+        {
867
+            $contents = file_get_contents($newsourcefile);	// Need PHP 4.3
868
+            $encoded = chunk_split(base64_encode($contents), 76, $this->eol);    // 76 max is defined into http://tools.ietf.org/html/rfc2047
869
+            return $encoded;
870
+        }
871
+        else
872
+        {
873
+            $this->error="Error: Can't read file '".$sourcefile."' into _encode_file";
874
+            dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR);
875
+            return -1;
876
+        }
877
+    }
878 878
 
879 879
 
880 880
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
881
-	/**
882
-	 *  Write content of a SMTP request into a dump file (mode = all)
883
-	 *  Used for debugging.
884
-	 *  Note that to see full SMTP protocol, you can use tcpdump -w /tmp/smtp -s 2000 port 25"
885
-	 *
886
-	 *  @return	void
887
-	 */
888
-	function dump_mail()
889
-	{
881
+    /**
882
+     *  Write content of a SMTP request into a dump file (mode = all)
883
+     *  Used for debugging.
884
+     *  Note that to see full SMTP protocol, you can use tcpdump -w /tmp/smtp -s 2000 port 25"
885
+     *
886
+     *  @return	void
887
+     */
888
+    function dump_mail()
889
+    {
890 890
         // phpcs:enable
891
-		global $conf,$dolibarr_main_data_root;
892
-
893
-		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
894
-		{
895
-			$outputfile=$dolibarr_main_data_root."/dolibarr_mail.log";
896
-			$fp = fopen($outputfile,"w");
897
-
898
-			if ($this->sendmode == 'mail')
899
-			{
900
-				fputs($fp, $this->headers);
901
-				fputs($fp, $this->eol);			// This eol is added by the mail function, so we add it in log
902
-				fputs($fp, $this->message);
903
-			}
904
-			elseif ($this->sendmode == 'smtps')
905
-			{
906
-				fputs($fp, $this->smtps->log);	// this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
907
-			}
908
-			elseif ($this->sendmode == 'swiftmailer')
909
-			{
910
-				fputs($fp, $this->logger->dump());	// this->logger is filled only if MAIN_MAIL_DEBUG was set to on
911
-			}
912
-
913
-			fclose($fp);
914
-			if (! empty($conf->global->MAIN_UMASK))
915
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
916
-		}
917
-	}
918
-
919
-
920
-	/**
921
-	 * Correct an uncomplete html string
922
-	 *
923
-	 * @param	string	$msg	String
924
-	 * @return	string			Completed string
925
-	 */
926
-	function checkIfHTML($msg)
927
-	{
928
-		if (!preg_match('/^[\s\t]*<html/i',$msg))
929
-		{
930
-			$out = "<html><head><title></title>";
931
-			if (!empty($this->styleCSS)) $out.= $this->styleCSS;
932
-			$out.= "</head><body";
933
-			if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
934
-			$out.= ">";
935
-			$out.= $msg;
936
-			$out.= "</body></html>";
937
-		}
938
-		else
939
-		{
940
-			$out = $msg;
941
-		}
942
-
943
-		return $out;
944
-	}
945
-
946
-	/**
947
-	 * Build a css style (mode = all) into this->styleCSS and this->bodyCSS
948
-	 *
949
-	 * @return string
950
-	 */
951
-	function buildCSS()
952
-	{
953
-		if (! empty($this->css))
954
-		{
955
-			// Style CSS
956
-			$this->styleCSS = '<style type="text/css">';
957
-			$this->styleCSS.= 'body {';
958
-
959
-			if ($this->css['bgcolor'])
960
-			{
961
-				$this->styleCSS.= '  background-color: '.$this->css['bgcolor'].';';
962
-				$this->bodyCSS.= ' bgcolor="'.$this->css['bgcolor'].'"';
963
-			}
964
-			if ($this->css['bgimage'])
965
-			{
966
-				// TODO recuperer cid
967
-				$this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
968
-			}
969
-			$this->styleCSS.= '}';
970
-			$this->styleCSS.= '</style>';
971
-		}
972
-	}
891
+        global $conf,$dolibarr_main_data_root;
892
+
893
+        if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
894
+        {
895
+            $outputfile=$dolibarr_main_data_root."/dolibarr_mail.log";
896
+            $fp = fopen($outputfile,"w");
897
+
898
+            if ($this->sendmode == 'mail')
899
+            {
900
+                fputs($fp, $this->headers);
901
+                fputs($fp, $this->eol);			// This eol is added by the mail function, so we add it in log
902
+                fputs($fp, $this->message);
903
+            }
904
+            elseif ($this->sendmode == 'smtps')
905
+            {
906
+                fputs($fp, $this->smtps->log);	// this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
907
+            }
908
+            elseif ($this->sendmode == 'swiftmailer')
909
+            {
910
+                fputs($fp, $this->logger->dump());	// this->logger is filled only if MAIN_MAIL_DEBUG was set to on
911
+            }
912
+
913
+            fclose($fp);
914
+            if (! empty($conf->global->MAIN_UMASK))
915
+                @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
916
+        }
917
+    }
918
+
919
+
920
+    /**
921
+     * Correct an uncomplete html string
922
+     *
923
+     * @param	string	$msg	String
924
+     * @return	string			Completed string
925
+     */
926
+    function checkIfHTML($msg)
927
+    {
928
+        if (!preg_match('/^[\s\t]*<html/i',$msg))
929
+        {
930
+            $out = "<html><head><title></title>";
931
+            if (!empty($this->styleCSS)) $out.= $this->styleCSS;
932
+            $out.= "</head><body";
933
+            if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
934
+            $out.= ">";
935
+            $out.= $msg;
936
+            $out.= "</body></html>";
937
+        }
938
+        else
939
+        {
940
+            $out = $msg;
941
+        }
942
+
943
+        return $out;
944
+    }
945
+
946
+    /**
947
+     * Build a css style (mode = all) into this->styleCSS and this->bodyCSS
948
+     *
949
+     * @return string
950
+     */
951
+    function buildCSS()
952
+    {
953
+        if (! empty($this->css))
954
+        {
955
+            // Style CSS
956
+            $this->styleCSS = '<style type="text/css">';
957
+            $this->styleCSS.= 'body {';
958
+
959
+            if ($this->css['bgcolor'])
960
+            {
961
+                $this->styleCSS.= '  background-color: '.$this->css['bgcolor'].';';
962
+                $this->bodyCSS.= ' bgcolor="'.$this->css['bgcolor'].'"';
963
+            }
964
+            if ($this->css['bgimage'])
965
+            {
966
+                // TODO recuperer cid
967
+                $this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
968
+            }
969
+            $this->styleCSS.= '}';
970
+            $this->styleCSS.= '</style>';
971
+        }
972
+    }
973 973
 
974 974
 
975 975
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
976
-	/**
977
-	 * Create SMTP headers (mode = 'mail')
978
-	 *
979
-	 * @return	string headers
980
-	 */
981
-	function write_smtpheaders()
982
-	{
976
+    /**
977
+     * Create SMTP headers (mode = 'mail')
978
+     *
979
+     * @return	string headers
980
+     */
981
+    function write_smtpheaders()
982
+    {
983 983
         // phpcs:enable
984
-		global $conf;
985
-		$out = "";
984
+        global $conf;
985
+        $out = "";
986 986
 
987
-		$host = dol_getprefix('email');
987
+        $host = dol_getprefix('email');
988 988
 
989
-		// Sender
990
-		//$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2;
991
-		$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol2;
992
-		if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
993
-		{
994
-			$out.= "To: ".$this->getValidAddress($this->addr_to,0,1).$this->eol2;
995
-		}
996
-		// Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that.
997
-		$out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2;
998
-		if (isset($this->reply_to)  && $this->reply_to)  $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2;
999
-		if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2;
989
+        // Sender
990
+        //$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2;
991
+        $out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol2;
992
+        if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
993
+        {
994
+            $out.= "To: ".$this->getValidAddress($this->addr_to,0,1).$this->eol2;
995
+        }
996
+        // Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that.
997
+        $out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2;
998
+        if (isset($this->reply_to)  && $this->reply_to)  $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2;
999
+        if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2;
1000 1000
 
1001
-		// Receiver
1002
-		if (isset($this->addr_cc)   && $this->addr_cc)   $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2;
1003
-		if (isset($this->addr_bcc)  && $this->addr_bcc)  $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2;    // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1001
+        // Receiver
1002
+        if (isset($this->addr_cc)   && $this->addr_cc)   $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2;
1003
+        if (isset($this->addr_bcc)  && $this->addr_bcc)  $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2;    // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1004 1004
 
1005
-		// Delivery receipt
1006
-		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2;
1005
+        // Delivery receipt
1006
+        if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2;
1007 1007
 
1008
-		//$out.= "X-Priority: 3".$this->eol2;
1008
+        //$out.= "X-Priority: 3".$this->eol2;
1009 1009
 
1010
-		$out.= 'Date: ' . date("r") . $this->eol2;
1010
+        $out.= 'Date: ' . date("r") . $this->eol2;
1011 1011
 
1012
-		$trackid = $this->trackid;
1013
-		if ($trackid)
1014
-		{
1015
-			// References is kept in response and Message-ID is returned into In-Reply-To:
1016
-			$out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;	// Uppercase seems replaced by phpmail
1017
-			$out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;
1018
-			$out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2;
1019
-		}
1020
-		else
1021
-		{
1022
-			$out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
1023
-		}
1012
+        $trackid = $this->trackid;
1013
+        if ($trackid)
1014
+        {
1015
+            // References is kept in response and Message-ID is returned into In-Reply-To:
1016
+            $out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;	// Uppercase seems replaced by phpmail
1017
+            $out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;
1018
+            $out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2;
1019
+        }
1020
+        else
1021
+        {
1022
+            $out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
1023
+        }
1024 1024
 
1025
-		if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2;
1026
-		$out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2;
1027
-		$out.= "Mime-Version: 1.0".$this->eol2;
1025
+        if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2;
1026
+        $out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2;
1027
+        $out.= "Mime-Version: 1.0".$this->eol2;
1028 1028
 
1029
-		//$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
1029
+        //$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
1030 1030
 
1031
-		$out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
1032
-		$out.= "Content-Transfer-Encoding: 8bit".$this->eol2;		// TODO Seems to be ignored. Header is 7bit once received.
1031
+        $out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
1032
+        $out.= "Content-Transfer-Encoding: 8bit".$this->eol2;		// TODO Seems to be ignored. Header is 7bit once received.
1033 1033
 
1034
-		dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out);
1035
-		return $out;
1036
-	}
1034
+        dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out);
1035
+        return $out;
1036
+    }
1037 1037
 
1038 1038
 
1039 1039
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1040
-	/**
1041
-	 * Create header MIME (mode = 'mail')
1042
-	 *
1043
-	 * @param	array	$filename_list			Array of filenames
1044
-	 * @param 	array	$mimefilename_list		Array of mime types
1045
-	 * @return	string							mime headers
1046
-	 */
1047
-	function write_mimeheaders($filename_list, $mimefilename_list)
1048
-	{
1040
+    /**
1041
+     * Create header MIME (mode = 'mail')
1042
+     *
1043
+     * @param	array	$filename_list			Array of filenames
1044
+     * @param 	array	$mimefilename_list		Array of mime types
1045
+     * @return	string							mime headers
1046
+     */
1047
+    function write_mimeheaders($filename_list, $mimefilename_list)
1048
+    {
1049 1049
         // phpcs:enable
1050
-		$mimedone=0;
1051
-		$out = "";
1052
-
1053
-		if (is_array($filename_list))
1054
-		{
1055
-			$filename_list_size=count($filename_list);
1056
-			for($i=0;$i < $filename_list_size;$i++)
1057
-			{
1058
-				if ($filename_list[$i])
1059
-				{
1060
-					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1061
-					$out.= "X-attachments: $filename_list[$i]".$this->eol2;
1062
-				}
1063
-			}
1064
-		}
1065
-
1066
-		dol_syslog("CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG);
1067
-		return $out;
1068
-	}
1050
+        $mimedone=0;
1051
+        $out = "";
1052
+
1053
+        if (is_array($filename_list))
1054
+        {
1055
+            $filename_list_size=count($filename_list);
1056
+            for($i=0;$i < $filename_list_size;$i++)
1057
+            {
1058
+                if ($filename_list[$i])
1059
+                {
1060
+                    if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1061
+                    $out.= "X-attachments: $filename_list[$i]".$this->eol2;
1062
+                }
1063
+            }
1064
+        }
1069 1065
 
1070
-    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1071
-	/**
1072
-	 * Return email content (mode = 'mail')
1073
-	 *
1074
-	 * @param	string		$msgtext		Message string
1075
-	 * @return	string						String content
1076
-	 */
1077
-	function write_body($msgtext)
1078
-	{
1079
-        // phpcs:enable
1080
-		global $conf;
1081
-
1082
-		$out='';
1083
-
1084
-		$out.= "--" . $this->mixed_boundary . $this->eol;
1085
-
1086
-		if ($this->atleastoneimage)
1087
-		{
1088
-			$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1089
-			$out.= $this->eol;
1090
-			$out.= "--" . $this->alternative_boundary . $this->eol;
1091
-		}
1092
-
1093
-		// Make RFC821 Compliant, replace bare linefeeds
1094
-		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext);	// PCRE modifier /s means new lines are common chars
1095
-		if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1096
-		{
1097
-			$strContent = preg_replace("/\r\n/si", "\n", $strContent);	// PCRE modifier /s means new lines are common chars
1098
-		}
1099
-
1100
-		$strContentAltText = '';
1101
-		if ($this->msgishtml)
1102
-		{
1103
-			// Similar code to forge a text from html is also in CMailFile.class.php
1104
-			$strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1105
-			$strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1106
-			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));
1107
-
1108
-			// Check if html header already in message, if not complete the message
1109
-			$strContent = $this->checkIfHTML($strContent);
1110
-		}
1111
-
1112
-		// Make RFC2045 Compliant, split lines
1113
-		//$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1114
-		// TODO Encode main content into base64 and use the chunk_split, or quoted-printable
1115
-		$strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1116
-
1117
-		if ($this->msgishtml)
1118
-		{
1119
-			if ($this->atleastoneimage)
1120
-			{
1121
-				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1122
-				//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1123
-				$out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message
1124
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1125
-				$out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
1126
-				$out.= $this->eol;
1127
-				$out.= "--" . $this->related_boundary . $this->eol;
1128
-			}
1129
-
1130
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1131
-			{
1132
-				$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1133
-				$out.= $this->eol;
1134
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1135
-				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1136
-				//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1137
-				$out.= $this->eol.$strContentAltText.$this->eol;
1138
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1139
-			}
1140
-
1141
-			$out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1142
-			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;	// TODO Use base64
1143
-			$out.= $this->eol.$strContent.$this->eol;
1144
-
1145
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1146
-			{
1147
-				$out.= "--" . $this->alternative_boundary . "--". $this->eol;
1148
-			}
1149
-		}
1150
-		else
1151
-		{
1152
-			$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1153
-			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1154
-			$out.= $this->eol.$strContent.$this->eol;
1155
-		}
1156
-
1157
-		$out.= $this->eol;
1158
-
1159
-		// Encode images
1160
-		if ($this->atleastoneimage)
1161
-		{
1162
-			$out .= $this->write_images($this->images_encoded);
1163
-			// always end related and end alternative after inline images
1164
-			$out .= "--" . $this->related_boundary . "--" . $this->eol;
1165
-			$out .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol;
1166
-			$out .= $this->eol;
1167
-		}
1168
-
1169
-		return $out;
1170
-	}
1066
+        dol_syslog("CMailFile::write_mimeheaders mime_header=\n".$out, LOG_DEBUG);
1067
+        return $out;
1068
+    }
1171 1069
 
1172 1070
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1173
-	/**
1174
-	 * Attach file to email (mode = 'mail')
1175
-	 *
1176
-	 * @param	array	$filename_list		Tableau
1177
-	 * @param	array	$mimetype_list		Tableau
1178
-	 * @param 	array	$mimefilename_list	Tableau
1179
-	 * @return	string						Chaine fichiers encodes
1180
-	 */
1181
-	function write_files($filename_list,$mimetype_list,$mimefilename_list)
1182
-	{
1071
+    /**
1072
+     * Return email content (mode = 'mail')
1073
+     *
1074
+     * @param	string		$msgtext		Message string
1075
+     * @return	string						String content
1076
+     */
1077
+    function write_body($msgtext)
1078
+    {
1183 1079
         // phpcs:enable
1184
-		$out = '';
1185
-
1186
-		$filename_list_size=count($filename_list);
1187
-		for($i=0;$i < $filename_list_size;$i++)
1188
-		{
1189
-			if ($filename_list[$i])
1190
-			{
1191
-				dol_syslog("CMailFile::write_files: i=$i");
1192
-				$encoded = $this->_encode_file($filename_list[$i]);
1193
-				if ($encoded >= 0)
1194
-				{
1195
-					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1196
-					if (! $mimetype_list[$i]) {
1197
-						$mimetype_list[$i] = "application/octet-stream";
1198
-					}
1199
-
1200
-					$out.= "--" . $this->mixed_boundary . $this->eol;
1201
-					$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
1202
-					$out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol;
1203
-					$out.= "Content-Transfer-Encoding: base64".$this->eol;
1204
-					$out.= "Content-Description: ".$filename_list[$i].$this->eol;
1205
-					$out.= $this->eol;
1206
-					$out.= $encoded;
1207
-					$out.= $this->eol;
1208
-					//$out.= $this->eol;
1209
-				}
1210
-				else
1211
-				{
1212
-					return $encoded;
1213
-				}
1214
-			}
1215
-		}
1216
-
1217
-		return $out;
1218
-	}
1080
+        global $conf;
1081
+
1082
+        $out='';
1083
+
1084
+        $out.= "--" . $this->mixed_boundary . $this->eol;
1085
+
1086
+        if ($this->atleastoneimage)
1087
+        {
1088
+            $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1089
+            $out.= $this->eol;
1090
+            $out.= "--" . $this->alternative_boundary . $this->eol;
1091
+        }
1092
+
1093
+        // Make RFC821 Compliant, replace bare linefeeds
1094
+        $strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext);	// PCRE modifier /s means new lines are common chars
1095
+        if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1096
+        {
1097
+            $strContent = preg_replace("/\r\n/si", "\n", $strContent);	// PCRE modifier /s means new lines are common chars
1098
+        }
1099
+
1100
+        $strContentAltText = '';
1101
+        if ($this->msgishtml)
1102
+        {
1103
+            // Similar code to forge a text from html is also in CMailFile.class.php
1104
+            $strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1105
+            $strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1106
+            $strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));
1107
+
1108
+            // Check if html header already in message, if not complete the message
1109
+            $strContent = $this->checkIfHTML($strContent);
1110
+        }
1111
+
1112
+        // Make RFC2045 Compliant, split lines
1113
+        //$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1114
+        // TODO Encode main content into base64 and use the chunk_split, or quoted-printable
1115
+        $strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1116
+
1117
+        if ($this->msgishtml)
1118
+        {
1119
+            if ($this->atleastoneimage)
1120
+            {
1121
+                $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1122
+                //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1123
+                $out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message
1124
+                $out.= "--" . $this->alternative_boundary . $this->eol;
1125
+                $out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
1126
+                $out.= $this->eol;
1127
+                $out.= "--" . $this->related_boundary . $this->eol;
1128
+            }
1129
+
1130
+            if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1131
+            {
1132
+                $out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1133
+                $out.= $this->eol;
1134
+                $out.= "--" . $this->alternative_boundary . $this->eol;
1135
+                $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1136
+                //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1137
+                $out.= $this->eol.$strContentAltText.$this->eol;
1138
+                $out.= "--" . $this->alternative_boundary . $this->eol;
1139
+            }
1140
+
1141
+            $out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1142
+            //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;	// TODO Use base64
1143
+            $out.= $this->eol.$strContent.$this->eol;
1219 1144
 
1145
+            if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1146
+            {
1147
+                $out.= "--" . $this->alternative_boundary . "--". $this->eol;
1148
+            }
1149
+        }
1150
+        else
1151
+        {
1152
+            $out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1153
+            //$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1154
+            $out.= $this->eol.$strContent.$this->eol;
1155
+        }
1156
+
1157
+        $out.= $this->eol;
1158
+
1159
+        // Encode images
1160
+        if ($this->atleastoneimage)
1161
+        {
1162
+            $out .= $this->write_images($this->images_encoded);
1163
+            // always end related and end alternative after inline images
1164
+            $out .= "--" . $this->related_boundary . "--" . $this->eol;
1165
+            $out .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol;
1166
+            $out .= $this->eol;
1167
+        }
1168
+
1169
+        return $out;
1170
+    }
1220 1171
 
1221 1172
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1222
-	/**
1223
-	 * Attach an image to email (mode = 'mail')
1224
-	 *
1225
-	 * @param	array	$images_list	Array of array image
1226
-	 * @return	string					Chaine images encodees
1227
-	 */
1228
-	function write_images($images_list)
1229
-	{
1173
+    /**
1174
+     * Attach file to email (mode = 'mail')
1175
+     *
1176
+     * @param	array	$filename_list		Tableau
1177
+     * @param	array	$mimetype_list		Tableau
1178
+     * @param 	array	$mimefilename_list	Tableau
1179
+     * @return	string						Chaine fichiers encodes
1180
+     */
1181
+    function write_files($filename_list,$mimetype_list,$mimefilename_list)
1182
+    {
1230 1183
         // phpcs:enable
1231
-		$out = '';
1184
+        $out = '';
1185
+
1186
+        $filename_list_size=count($filename_list);
1187
+        for($i=0;$i < $filename_list_size;$i++)
1188
+        {
1189
+            if ($filename_list[$i])
1190
+            {
1191
+                dol_syslog("CMailFile::write_files: i=$i");
1192
+                $encoded = $this->_encode_file($filename_list[$i]);
1193
+                if ($encoded >= 0)
1194
+                {
1195
+                    if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1196
+                    if (! $mimetype_list[$i]) {
1197
+                        $mimetype_list[$i] = "application/octet-stream";
1198
+                    }
1199
+
1200
+                    $out.= "--" . $this->mixed_boundary . $this->eol;
1201
+                    $out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
1202
+                    $out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol;
1203
+                    $out.= "Content-Transfer-Encoding: base64".$this->eol;
1204
+                    $out.= "Content-Description: ".$filename_list[$i].$this->eol;
1205
+                    $out.= $this->eol;
1206
+                    $out.= $encoded;
1207
+                    $out.= $this->eol;
1208
+                    //$out.= $this->eol;
1209
+                }
1210
+                else
1211
+                {
1212
+                    return $encoded;
1213
+                }
1214
+            }
1215
+        }
1232 1216
 
1233
-		if (is_array($images_list))
1234
-		{
1235
-			foreach ($images_list as $img)
1236
-			{
1237
-				dol_syslog("CMailFile::write_images: ".$img["name"]);
1217
+        return $out;
1218
+    }
1238 1219
 
1239
-				$out.= "--" . $this->related_boundary . $this->eol; // always related for an inline image
1240
-				$out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol;
1241
-				$out.= "Content-Transfer-Encoding: base64".$this->eol;
1242
-				$out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
1243
-				$out.= "Content-ID: <".$img["cid"].">".$this->eol;
1244
-				$out.= $this->eol;
1245
-				$out.= $img["image_encoded"];
1246
-				$out.= $this->eol;
1247
-			}
1248
-		}
1249 1220
 
1250
-		return $out;
1251
-	}
1221
+    // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1222
+    /**
1223
+     * Attach an image to email (mode = 'mail')
1224
+     *
1225
+     * @param	array	$images_list	Array of array image
1226
+     * @return	string					Chaine images encodees
1227
+     */
1228
+    function write_images($images_list)
1229
+    {
1230
+        // phpcs:enable
1231
+        $out = '';
1232
+
1233
+        if (is_array($images_list))
1234
+        {
1235
+            foreach ($images_list as $img)
1236
+            {
1237
+                dol_syslog("CMailFile::write_images: ".$img["name"]);
1238
+
1239
+                $out.= "--" . $this->related_boundary . $this->eol; // always related for an inline image
1240
+                $out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol;
1241
+                $out.= "Content-Transfer-Encoding: base64".$this->eol;
1242
+                $out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
1243
+                $out.= "Content-ID: <".$img["cid"].">".$this->eol;
1244
+                $out.= $this->eol;
1245
+                $out.= $img["image_encoded"];
1246
+                $out.= $this->eol;
1247
+            }
1248
+        }
1249
+
1250
+        return $out;
1251
+    }
1252 1252
 
1253 1253
 
1254 1254
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1255
-	/**
1256
-	 * Try to create a socket connection
1257
-	 *
1258
-	 * @param 	string		$host		Add ssl:// for SSL/TLS.
1259
-	 * @param 	int			$port		Example: 25, 465
1260
-	 * @return	int						Socket id if ok, 0 if KO
1261
-	 */
1262
-	function check_server_port($host,$port)
1263
-	{
1255
+    /**
1256
+     * Try to create a socket connection
1257
+     *
1258
+     * @param 	string		$host		Add ssl:// for SSL/TLS.
1259
+     * @param 	int			$port		Example: 25, 465
1260
+     * @return	int						Socket id if ok, 0 if KO
1261
+     */
1262
+    function check_server_port($host,$port)
1263
+    {
1264 1264
         // phpcs:enable
1265
-		global $conf;
1266
-
1267
-		$_retVal=0;
1268
-		$timeout=5;	// Timeout in seconds
1269
-
1270
-		if (function_exists('fsockopen'))
1271
-		{
1272
-			$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
1273
-			$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
1274
-			$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
1275
-			$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
1276
-			$keyfortls       ='MAIN_MAIL_EMAIL_TLS';
1277
-			$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
1278
-			if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
1279
-			{
1280
-				$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
1281
-				$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
1282
-				$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
1283
-				$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
1284
-				$keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
1285
-				$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1286
-			}
1287
-
1288
-			// If we use SSL/TLS
1289
-			if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host;
1290
-			// tls smtp start with no encryption
1291
-			//if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host;
1292
-
1293
-			dol_syslog("Try socket connection to host=".$host." port=".$port);
1294
-			//See if we can connect to the SMTP server
1295
-			if ($socket = @fsockopen(
1296
-					$host,       // Host to test, IP or domain. Add ssl:// for SSL/TLS.
1297
-					$port,       // which Port number to use
1298
-					$errno,      // actual system level error
1299
-					$errstr,     // and any text that goes with the error
1300
-					$timeout
1301
-			))  // timeout for reading/writing data over the socket
1302
-			{
1303
-				// Windows still does not have support for this timeout function
1304
-				if (function_exists('stream_set_timeout')) stream_set_timeout($socket, $timeout, 0);
1305
-
1306
-				dol_syslog("Now we wait for answer 220");
1307
-
1308
-				// Check response from Server
1309
-				if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket;
1310
-			}
1311
-			else
1312
-			{
1313
-				$this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr);
1314
-			}
1315
-		}
1316
-		return $_retVal;
1317
-	}
1265
+        global $conf;
1266
+
1267
+        $_retVal=0;
1268
+        $timeout=5;	// Timeout in seconds
1269
+
1270
+        if (function_exists('fsockopen'))
1271
+        {
1272
+            $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
1273
+            $keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
1274
+            $keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
1275
+            $keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
1276
+            $keyfortls       ='MAIN_MAIL_EMAIL_TLS';
1277
+            $keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
1278
+            if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
1279
+            {
1280
+                $keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
1281
+                $keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
1282
+                $keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
1283
+                $keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
1284
+                $keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
1285
+                $keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1286
+            }
1287
+
1288
+            // If we use SSL/TLS
1289
+            if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host;
1290
+            // tls smtp start with no encryption
1291
+            //if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host;
1292
+
1293
+            dol_syslog("Try socket connection to host=".$host." port=".$port);
1294
+            //See if we can connect to the SMTP server
1295
+            if ($socket = @fsockopen(
1296
+                    $host,       // Host to test, IP or domain. Add ssl:// for SSL/TLS.
1297
+                    $port,       // which Port number to use
1298
+                    $errno,      // actual system level error
1299
+                    $errstr,     // and any text that goes with the error
1300
+                    $timeout
1301
+            ))  // timeout for reading/writing data over the socket
1302
+            {
1303
+                // Windows still does not have support for this timeout function
1304
+                if (function_exists('stream_set_timeout')) stream_set_timeout($socket, $timeout, 0);
1305
+
1306
+                dol_syslog("Now we wait for answer 220");
1307
+
1308
+                // Check response from Server
1309
+                if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket;
1310
+            }
1311
+            else
1312
+            {
1313
+                $this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr);
1314
+            }
1315
+        }
1316
+        return $_retVal;
1317
+    }
1318 1318
 
1319 1319
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1320
-	/**
1321
-	 * This function has been modified as provided by SirSir to allow multiline responses when
1322
-	 * using SMTP Extensions.
1323
-	 *
1324
-	 * @param	Socket	$socket			Socket
1325
-	 * @param   string	$response		Response string
1326
-	 * @return  boolean					true if success
1327
-	 */
1328
-	function server_parse($socket, $response)
1329
-	{
1320
+    /**
1321
+     * This function has been modified as provided by SirSir to allow multiline responses when
1322
+     * using SMTP Extensions.
1323
+     *
1324
+     * @param	Socket	$socket			Socket
1325
+     * @param   string	$response		Response string
1326
+     * @return  boolean					true if success
1327
+     */
1328
+    function server_parse($socket, $response)
1329
+    {
1330 1330
         // phpcs:enable
1331
-		$_retVal = true;	// Indicates if Object was created or not
1332
-		$server_response = '';
1333
-
1334
-		while (substr($server_response,3,1) != ' ')
1335
-		{
1336
-			if (! ($server_response = fgets($socket, 256)) )
1337
-			{
1338
-				$this->error="Couldn't get mail server response codes";
1339
-				return false;
1340
-			}
1341
-		}
1342
-
1343
-		if( !( substr($server_response, 0, 3) == $response ) )
1344
-		{
1345
-			$this->error="Ran into problems sending Mail.\r\nResponse: $server_response";
1346
-			$_retVal = false;
1347
-		}
1348
-
1349
-		return $_retVal;
1350
-	}
1351
-
1352
-	/**
1353
-	 * Seearch images into html message and init array this->images_encoded if found
1354
-	 *
1355
-	 * @param	string	$images_dir		Location of physical images files
1356
-	 * @return	int 		        	>0 if OK, <0 if KO
1357
-	 */
1358
-	function findHtmlImages($images_dir)
1359
-	{
1360
-		// Build the list of image extensions
1361
-		$extensions = array_keys($this->image_types);
1362
-
1363
-		$matches = array();
1364
-		preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches);  // If "xxx.ext" or 'xxx.ext' found
1365
-
1366
-		if (! empty($matches))
1367
-		{
1368
-			$i=0;
1369
-			foreach ($matches[1] as $full)
1370
-			{
1371
-
1372
-				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs))   // If xxx is 'file=aaa'
1373
-				{
1374
-					$img = $regs[1];
1375
-
1376
-					if (file_exists($images_dir.'/'.$img))
1377
-					{
1378
-						// Image path in src
1379
-						$src = preg_quote($full,'/');
1380
-
1381
-						// Image full path
1382
-						$this->html_images[$i]["fullpath"] = $images_dir.'/'.$img;
1383
-
1384
-						// Image name
1385
-						$this->html_images[$i]["name"] = $img;
1386
-
1387
-						// Content type
1388
-						if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg))
1389
-						{
1390
-							$ext=strtolower($reg[1]);
1391
-							$this->html_images[$i]["content_type"] = $this->image_types[$ext];
1392
-						}
1393
-
1394
-						// cid
1395
-						$this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3);	// Force md5 hash (does not contains special chars)
1396
-						$this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html);
1397
-					}
1398
-					$i++;
1399
-				}
1400
-			}
1401
-
1402
-			if (!empty($this->html_images))
1403
-			{
1404
-				$inline = array();
1405
-
1406
-				$i=0;
1407
-
1408
-				foreach ($this->html_images as $img)
1409
-				{
1410
-					$fullpath = $images_dir.'/'.$img["name"];
1411
-
1412
-					// If duplicate images are embedded, they may show up as attachments, so remove them.
1413
-					if (!in_array($fullpath,$inline))
1414
-					{
1415
-						// Read image file
1416
-						if ($image = file_get_contents($fullpath))
1417
-						{
1418
-							// On garde que le nom de l'image
1419
-							preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i',$img["name"],$regs);
1420
-							$imgName = $regs[1];
1421
-
1422
-							$this->images_encoded[$i]['name'] = $imgName;
1423
-							$this->images_encoded[$i]['fullpath'] = $fullpath;
1424
-							$this->images_encoded[$i]['content_type'] = $img["content_type"];
1425
-							$this->images_encoded[$i]['cid'] = $img["cid"];
1426
-							// Encodage de l'image
1427
-							$this->images_encoded[$i]["image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol);
1428
-							$inline[] = $fullpath;
1429
-						}
1430
-					}
1431
-					$i++;
1432
-				}
1433
-			}
1434
-			else
1435
-			{
1436
-				return -1;
1437
-			}
1438
-
1439
-			return 1;
1440
-		}
1441
-		else
1442
-		{
1443
-			return 0;
1444
-		}
1445
-	}
1446
-
1447
-	/**
1448
-	 * Return a formatted address string for SMTP protocol
1449
-	 *
1450
-	 * @param	string		$address		     Example: 'John Doe <[email protected]>, Alan Smith <[email protected]>' or '[email protected], [email protected]'
1451
-	 * @param	int			$format			     0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between "
1452
-	 * @param	int			$encode			     0=No encode name, 1=Encode name to RFC2822
1453
-	 * @param   int         $maxnumberofemail    0=No limit. Otherwise, maximum number of emails returned ($address may contains several email separated with ','). Add '...' if there is more.
1454
-	 * @return	string						     If format 0: '<[email protected]>' or 'John Doe <[email protected]>' or '=?UTF-8?B?Sm9obiBEb2U=?= <[email protected]>'
1455
-	 * 										     If format 1: '<[email protected]>'
1456
-	 *										     If format 2: '[email protected]'
1457
-	 *										     If format 3: '<[email protected]>' or '"John Doe" <[email protected]>' or '"=?UTF-8?B?Sm9obiBEb2U=?=" <[email protected]>'
1458
-	 *                                           If format 4: 'John Doe' or '[email protected]' if no label exists
1459
-	 */
1460
-	static function getValidAddress($address,$format,$encode=0,$maxnumberofemail=0)
1461
-	{
1462
-		global $conf;
1463
-
1464
-		$ret='';
1465
-
1466
-		$arrayaddress=explode(',',$address);
1467
-
1468
-		// Boucle sur chaque composant de l'adresse
1469
-		$i=0;
1470
-		foreach($arrayaddress as $val)
1471
-		{
1472
-			if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1473
-			{
1474
-				$name  = trim($regs[1]);
1475
-				$email = trim($regs[2]);
1476
-			}
1477
-			else
1478
-			{
1479
-				$name  = '';
1480
-				$email = trim($val);
1481
-			}
1482
-
1483
-			if ($email)
1484
-			{
1485
-				$i++;
1486
-
1487
-				$newemail='';
1488
-				if ($format == 4)
1489
-				{
1490
-					$newemail = $name?$name:$email;
1491
-				}
1492
-				if ($format == 2)
1493
-				{
1494
-					$newemail=$email;
1495
-				}
1496
-				if ($format == 1 || $format == 3)
1497
-				{
1498
-					$newemail='<'.$email.'>';
1499
-				}
1500
-				if ($format == 0 || $format == 3)
1501
-				{
1502
-					if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>';
1503
-					elseif (! $name) $newemail='<'.$email.'>';
1504
-					else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>';
1505
-				}
1506
-
1507
-				$ret=($ret ? $ret.',' : '').$newemail;
1508
-
1509
-				// Stop if we have too much records
1510
-				if ($maxnumberofemail && $i >= $maxnumberofemail)
1511
-				{
1512
-					if (count($arrayaddress) > $maxnumberofemail) $ret.='...';
1513
-					break;
1514
-				}
1515
-			}
1516
-		}
1517
-
1518
-		return $ret;
1519
-	}
1520
-
1521
-	/**
1522
-	 * Return a formatted array of address string for SMTP protocol
1523
-	 *
1524
-	 * @param   string      $address        Example: 'John Doe <[email protected]>, Alan Smith <[email protected]>' or '[email protected], [email protected]'
1525
-	 * @return  array                       array of email => name
1526
-	 */
1527
-	function getArrayAddress($address)
1528
-	{
1529
-		global $conf;
1530
-
1531
-		$ret=array();
1532
-
1533
-		$arrayaddress=explode(',',$address);
1534
-
1535
-		// Boucle sur chaque composant de l'adresse
1536
-		foreach($arrayaddress as $val)
1537
-		{
1538
-			if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1539
-			{
1540
-				$name  = trim($regs[1]);
1541
-				$email = trim($regs[2]);
1542
-			}
1543
-			else
1544
-			{
1545
-				$name  = null;
1546
-				$email = trim($val);
1547
-			}
1548
-
1549
-			$ret[$email]=empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)?$name:null;
1550
-		}
1551
-
1552
-		return $ret;
1553
-	}
1331
+        $_retVal = true;	// Indicates if Object was created or not
1332
+        $server_response = '';
1333
+
1334
+        while (substr($server_response,3,1) != ' ')
1335
+        {
1336
+            if (! ($server_response = fgets($socket, 256)) )
1337
+            {
1338
+                $this->error="Couldn't get mail server response codes";
1339
+                return false;
1340
+            }
1341
+        }
1342
+
1343
+        if( !( substr($server_response, 0, 3) == $response ) )
1344
+        {
1345
+            $this->error="Ran into problems sending Mail.\r\nResponse: $server_response";
1346
+            $_retVal = false;
1347
+        }
1348
+
1349
+        return $_retVal;
1350
+    }
1351
+
1352
+    /**
1353
+     * Seearch images into html message and init array this->images_encoded if found
1354
+     *
1355
+     * @param	string	$images_dir		Location of physical images files
1356
+     * @return	int 		        	>0 if OK, <0 if KO
1357
+     */
1358
+    function findHtmlImages($images_dir)
1359
+    {
1360
+        // Build the list of image extensions
1361
+        $extensions = array_keys($this->image_types);
1362
+
1363
+        $matches = array();
1364
+        preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches);  // If "xxx.ext" or 'xxx.ext' found
1365
+
1366
+        if (! empty($matches))
1367
+        {
1368
+            $i=0;
1369
+            foreach ($matches[1] as $full)
1370
+            {
1371
+
1372
+                if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs))   // If xxx is 'file=aaa'
1373
+                {
1374
+                    $img = $regs[1];
1375
+
1376
+                    if (file_exists($images_dir.'/'.$img))
1377
+                    {
1378
+                        // Image path in src
1379
+                        $src = preg_quote($full,'/');
1380
+
1381
+                        // Image full path
1382
+                        $this->html_images[$i]["fullpath"] = $images_dir.'/'.$img;
1383
+
1384
+                        // Image name
1385
+                        $this->html_images[$i]["name"] = $img;
1386
+
1387
+                        // Content type
1388
+                        if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg))
1389
+                        {
1390
+                            $ext=strtolower($reg[1]);
1391
+                            $this->html_images[$i]["content_type"] = $this->image_types[$ext];
1392
+                        }
1393
+
1394
+                        // cid
1395
+                        $this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3);	// Force md5 hash (does not contains special chars)
1396
+                        $this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html);
1397
+                    }
1398
+                    $i++;
1399
+                }
1400
+            }
1401
+
1402
+            if (!empty($this->html_images))
1403
+            {
1404
+                $inline = array();
1405
+
1406
+                $i=0;
1407
+
1408
+                foreach ($this->html_images as $img)
1409
+                {
1410
+                    $fullpath = $images_dir.'/'.$img["name"];
1411
+
1412
+                    // If duplicate images are embedded, they may show up as attachments, so remove them.
1413
+                    if (!in_array($fullpath,$inline))
1414
+                    {
1415
+                        // Read image file
1416
+                        if ($image = file_get_contents($fullpath))
1417
+                        {
1418
+                            // On garde que le nom de l'image
1419
+                            preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i',$img["name"],$regs);
1420
+                            $imgName = $regs[1];
1421
+
1422
+                            $this->images_encoded[$i]['name'] = $imgName;
1423
+                            $this->images_encoded[$i]['fullpath'] = $fullpath;
1424
+                            $this->images_encoded[$i]['content_type'] = $img["content_type"];
1425
+                            $this->images_encoded[$i]['cid'] = $img["cid"];
1426
+                            // Encodage de l'image
1427
+                            $this->images_encoded[$i]["image_encoded"] = chunk_split(base64_encode($image), 68, $this->eol);
1428
+                            $inline[] = $fullpath;
1429
+                        }
1430
+                    }
1431
+                    $i++;
1432
+                }
1433
+            }
1434
+            else
1435
+            {
1436
+                return -1;
1437
+            }
1438
+
1439
+            return 1;
1440
+        }
1441
+        else
1442
+        {
1443
+            return 0;
1444
+        }
1445
+    }
1446
+
1447
+    /**
1448
+     * Return a formatted address string for SMTP protocol
1449
+     *
1450
+     * @param	string		$address		     Example: 'John Doe <[email protected]>, Alan Smith <[email protected]>' or '[email protected], [email protected]'
1451
+     * @param	int			$format			     0=auto, 1=emails with <>, 2=emails without <>, 3=auto + label between "
1452
+     * @param	int			$encode			     0=No encode name, 1=Encode name to RFC2822
1453
+     * @param   int         $maxnumberofemail    0=No limit. Otherwise, maximum number of emails returned ($address may contains several email separated with ','). Add '...' if there is more.
1454
+     * @return	string						     If format 0: '<[email protected]>' or 'John Doe <[email protected]>' or '=?UTF-8?B?Sm9obiBEb2U=?= <[email protected]>'
1455
+     * 										     If format 1: '<[email protected]>'
1456
+     *										     If format 2: '[email protected]'
1457
+     *										     If format 3: '<[email protected]>' or '"John Doe" <[email protected]>' or '"=?UTF-8?B?Sm9obiBEb2U=?=" <[email protected]>'
1458
+     *                                           If format 4: 'John Doe' or '[email protected]' if no label exists
1459
+     */
1460
+    static function getValidAddress($address,$format,$encode=0,$maxnumberofemail=0)
1461
+    {
1462
+        global $conf;
1463
+
1464
+        $ret='';
1465
+
1466
+        $arrayaddress=explode(',',$address);
1467
+
1468
+        // Boucle sur chaque composant de l'adresse
1469
+        $i=0;
1470
+        foreach($arrayaddress as $val)
1471
+        {
1472
+            if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1473
+            {
1474
+                $name  = trim($regs[1]);
1475
+                $email = trim($regs[2]);
1476
+            }
1477
+            else
1478
+            {
1479
+                $name  = '';
1480
+                $email = trim($val);
1481
+            }
1482
+
1483
+            if ($email)
1484
+            {
1485
+                $i++;
1486
+
1487
+                $newemail='';
1488
+                if ($format == 4)
1489
+                {
1490
+                    $newemail = $name?$name:$email;
1491
+                }
1492
+                if ($format == 2)
1493
+                {
1494
+                    $newemail=$email;
1495
+                }
1496
+                if ($format == 1 || $format == 3)
1497
+                {
1498
+                    $newemail='<'.$email.'>';
1499
+                }
1500
+                if ($format == 0 || $format == 3)
1501
+                {
1502
+                    if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>';
1503
+                    elseif (! $name) $newemail='<'.$email.'>';
1504
+                    else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>';
1505
+                }
1506
+
1507
+                $ret=($ret ? $ret.',' : '').$newemail;
1508
+
1509
+                // Stop if we have too much records
1510
+                if ($maxnumberofemail && $i >= $maxnumberofemail)
1511
+                {
1512
+                    if (count($arrayaddress) > $maxnumberofemail) $ret.='...';
1513
+                    break;
1514
+                }
1515
+            }
1516
+        }
1517
+
1518
+        return $ret;
1519
+    }
1520
+
1521
+    /**
1522
+     * Return a formatted array of address string for SMTP protocol
1523
+     *
1524
+     * @param   string      $address        Example: 'John Doe <[email protected]>, Alan Smith <[email protected]>' or '[email protected], [email protected]'
1525
+     * @return  array                       array of email => name
1526
+     */
1527
+    function getArrayAddress($address)
1528
+    {
1529
+        global $conf;
1530
+
1531
+        $ret=array();
1532
+
1533
+        $arrayaddress=explode(',',$address);
1534
+
1535
+        // Boucle sur chaque composant de l'adresse
1536
+        foreach($arrayaddress as $val)
1537
+        {
1538
+            if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1539
+            {
1540
+                $name  = trim($regs[1]);
1541
+                $email = trim($regs[2]);
1542
+            }
1543
+            else
1544
+            {
1545
+                $name  = null;
1546
+                $email = trim($val);
1547
+            }
1548
+
1549
+            $ret[$email]=empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)?$name:null;
1550
+        }
1551
+
1552
+        return $ret;
1553
+    }
1554 1554
 }
Please login to merge, or discard this patch.
Spacing   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
 	public $sendmode;
41 41
 	public $sendsetup;
42 42
 
43
-	var $subject;      	// Topic:       Subject of email
44
-	var $addr_from;    	// From:		Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to).
43
+	var $subject; // Topic:       Subject of email
44
+	var $addr_from; // From:		Label and EMail of sender (must include '<>'). For example '<[email protected]>' or 'John Doe <[email protected]>' or '<[email protected]>'). Note that with gmail smtps, value here is forced by google to account (but not the reply-to).
45 45
 	// Sender:      Who send the email ("Sender" has sent emails on behalf of "From").
46 46
 	//              Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, add Sender field with an email of the protected domain.
47 47
 	// Return-Path: Email where to send bounds.
48
-	var $reply_to;		// Reply-To:	Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined)
49
-	var $errors_to;		// Errors-To:	Email where to send errors.
48
+	var $reply_to; // Reply-To:	Email where to send replies from mailer software (mailer use From if reply-to not defined, Gmail use gmail account if reply-to not defined)
49
+	var $errors_to; // Errors-To:	Email where to send errors.
50 50
 	var $addr_to;
51 51
 	var $addr_cc;
52 52
 	var $addr_bcc;
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 	/**
64 64
 	 * @var string Error code (or message)
65 65
 	 */
66
-	public $error='';
66
+	public $error = '';
67 67
 
68
-	var $smtps;			// Contains SMTPs object (if this method is used)
69
-	var $phpmailer;		// Contains PHPMailer object (if this method is used)
68
+	var $smtps; // Contains SMTPs object (if this method is used)
69
+	var $phpmailer; // Contains PHPMailer object (if this method is used)
70 70
 
71 71
 	/**
72 72
 	 * @var string CSS
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
 	// Image
84 84
 	var $html;
85 85
 	var $image_boundary;
86
-	var $atleastoneimage=0;    // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
87
-	var $html_images=array();
88
-	var $images_encoded=array();
86
+	var $atleastoneimage = 0; // at least one image file with file=xxx.ext into content (TODO Debug this. How can this case be tested. Remove if not used).
87
+	var $html_images = array();
88
+	var $images_encoded = array();
89 89
 	var $image_types = array(
90 90
         'gif'  => 'image/gif',
91 91
 		'jpg'  => 'image/jpeg',
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
 	 *  @param  string  $sendcontext      	 'standard', 'emailing', ... (used to define with sending mode and parameters to use)
120 120
 	 *  @param	string	$replyto			 Reply-to email (will be set to same value than From by default if not provided)
121 121
 	 */
122
-	function __construct($subject, $to, $from, $msg, $filename_list=array(), $mimetype_list=array(), $mimefilename_list=array(), $addr_cc="", $addr_bcc="", $deliveryreceipt=0, $msgishtml=0, $errors_to='', $css='', $trackid='', $moreinheader='', $sendcontext='standard', $replyto='')
122
+	function __construct($subject, $to, $from, $msg, $filename_list = array(), $mimetype_list = array(), $mimefilename_list = array(), $addr_cc = "", $addr_bcc = "", $deliveryreceipt = 0, $msgishtml = 0, $errors_to = '', $css = '', $trackid = '', $moreinheader = '', $sendcontext = 'standard', $replyto = '')
123 123
 	{
124 124
 		global $conf, $dolibarr_main_data_root;
125 125
 
126 126
 		$this->sendcontext = $sendcontext;
127 127
 
128
-		if (empty($replyto)) $replyto=$from;
128
+		if (empty($replyto)) $replyto = $from;
129 129
 
130 130
 		// Define this->sendmode
131 131
 		$this->sendmode = '';
@@ -133,28 +133,28 @@  discard block
 block discarded – undo
133 133
 		{
134 134
 			$this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING;
135 135
 		}
136
-		if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE;
137
-		if (empty($this->sendmode)) $this->sendmode='mail';
136
+		if (empty($this->sendmode)) $this->sendmode = $conf->global->MAIN_MAIL_SENDMODE;
137
+		if (empty($this->sendmode)) $this->sendmode = 'mail';
138 138
 
139 139
 		// We define end of line (RFC 821).
140
-		$this->eol="\r\n";
140
+		$this->eol = "\r\n";
141 141
 		// We define end of line for header fields (RFC 822bis section 2.3 says header must contains \r\n).
142
-		$this->eol2="\r\n";
143
-		if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
142
+		$this->eol2 = "\r\n";
143
+		if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
144 144
 		{
145
-			$this->eol="\n";
146
-			$this->eol2="\n";
147
-			$moreinheader = str_replace("\r\n","\n",$moreinheader);
145
+			$this->eol = "\n";
146
+			$this->eol2 = "\n";
147
+			$moreinheader = str_replace("\r\n", "\n", $moreinheader);
148 148
 		}
149 149
 
150 150
 		// On defini mixed_boundary
151
-		$this->mixed_boundary = "multipart_x." . time() . ".x_boundary";
151
+		$this->mixed_boundary = "multipart_x.".time().".x_boundary";
152 152
 
153 153
 		// On defini related_boundary
154
-		$this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3);	// Force md5 hash (does not contains special chars)
154
+		$this->related_boundary = 'mul_'.dol_hash(uniqid("dolibarr2"), 3); // Force md5 hash (does not contains special chars)
155 155
 
156 156
 		// On defini alternative_boundary
157
-		$this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3);	// Force md5 hash (does not contains special chars)
157
+		$this->alternative_boundary = 'mul_'.dol_hash(uniqid("dolibarr3"), 3); // Force md5 hash (does not contains special chars)
158 158
 
159 159
 		dol_syslog("CMailFile::CMailfile: sendmode=".$this->sendmode." charset=".$conf->file->character_set_client." from=$from, to=$to, addr_cc=$addr_cc, addr_bcc=$addr_bcc, errors_to=$errors_to, trackid=$trackid sendcontext=$sendcontext", LOG_DEBUG);
160 160
 		dol_syslog("CMailFile::CMailfile: subject=".$subject.", deliveryreceipt=".$deliveryreceipt.", msgishtml=".$msgishtml, LOG_DEBUG);
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 		if (empty($subject))
163 163
 		{
164 164
 			dol_syslog("CMailFile::CMailfile: Try to send an email with empty subject");
165
-			$this->error='ErrorSubjectIsRequired';
165
+			$this->error = 'ErrorSubjectIsRequired';
166 166
 			return;
167 167
 		}
168 168
 		if (empty($msg))
169 169
 		{
170 170
 		    dol_syslog("CMailFile::CMailfile: Try to send an email with empty body");
171
-		    $msg='.';     // Avoid empty message (with empty message conten show a multipart structure)
171
+		    $msg = '.'; // Avoid empty message (with empty message conten show a multipart structure)
172 172
 		}
173 173
 
174 174
 		// Detect if message is HTML (use fast method)
@@ -185,21 +185,21 @@  discard block
 block discarded – undo
185 185
 		global $dolibarr_main_url_root;
186 186
 
187 187
 		// Define $urlwithroot
188
-		$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root));
189
-		$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT;		// This is to use external domain name found into config file
188
+		$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
189
+		$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
190 190
 		//$urlwithroot=DOL_MAIN_URL_ROOT;					// This is to use same domain name than current
191 191
 
192 192
 		// Replace relative /viewimage to absolute path
193
-		$msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
193
+		$msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT, '/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
194 194
 
195
-		if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html.
195
+		if (!empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml = 1; // To force to send everything with content type html.
196 196
 
197 197
 		// Detect images
198 198
 		if ($this->msgishtml)
199 199
 		{
200 200
 			$this->html = $msg;
201 201
 
202
-			if (! empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
202
+			if (!empty($conf->global->MAIN_MAIL_ADD_INLINE_IMAGES_IF_IN_MEDIAS))
203 203
 			{
204 204
 				$findimg = $this->findHtmlImages($dolibarr_main_data_root.'/medias');
205 205
 			}
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 				{
212 212
 					if ($this->html_images[$i])
213 213
 					{
214
-						$this->atleastoneimage=1;
214
+						$this->atleastoneimage = 1;
215 215
 						dol_syslog("CMailFile::CMailfile: html_images[$i]['name']=".$this->html_images[$i]['name'], LOG_DEBUG);
216 216
 					}
217 217
 				}
@@ -225,14 +225,14 @@  discard block
 block discarded – undo
225 225
 			{
226 226
 				if ($filename_list[$i])
227 227
 				{
228
-					$this->atleastonefile=1;
228
+					$this->atleastonefile = 1;
229 229
 					dol_syslog("CMailFile::CMailfile: filename_list[$i]=".$filename_list[$i].", mimetype_list[$i]=".$mimetype_list[$i]." mimefilename_list[$i]=".$mimefilename_list[$i], LOG_DEBUG);
230 230
 				}
231 231
 			}
232 232
 		}
233 233
 
234 234
 		// Add autocopy to (Note: Adding bcc for specific modules are also done from pages)
235
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
235
+		if (!empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc .= ($addr_bcc ? ', ' : '').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
236 236
 
237 237
 		// Action according to choosed sending method
238 238
 		if ($this->sendmode == 'mail')
@@ -257,17 +257,17 @@  discard block
 block discarded – undo
257 257
 			$this->trackid = $trackid;
258 258
 
259 259
 			$smtp_headers = $this->write_smtpheaders();
260
-			if (! empty($moreinheader)) $smtp_headers.=$moreinheader;   // $moreinheader contains the \r\n
260
+			if (!empty($moreinheader)) $smtp_headers .= $moreinheader; // $moreinheader contains the \r\n
261 261
 
262 262
 			// Define mime_headers
263 263
 			$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
264 264
 
265
-			if (! empty($this->html))
265
+			if (!empty($this->html))
266 266
 			{
267 267
 				if (!empty($css))
268 268
 				{
269 269
 					$this->css = $css;
270
-					$this->buildCSS();    // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
270
+					$this->buildCSS(); // Build a css style (mode = all) into this->styleCSS and this->bodyCSS
271 271
 				}
272 272
 
273 273
 				$msg = $this->html;
@@ -279,20 +279,20 @@  discard block
 block discarded – undo
279 279
 			// Add attachments to text_encoded
280 280
 			if ($this->atleastonefile)
281 281
 			{
282
-				$files_encoded = $this->write_files($filename_list,$mimetype_list,$mimefilename_list);
282
+				$files_encoded = $this->write_files($filename_list, $mimetype_list, $mimefilename_list);
283 283
 			}
284 284
 
285 285
 			// We now define $this->headers and $this->message
286
-			$this->headers = $smtp_headers . $mime_headers;
286
+			$this->headers = $smtp_headers.$mime_headers;
287 287
 			// On nettoie le header pour qu'il ne se termine pas par un retour chariot.
288 288
 			// Ceci evite aussi les lignes vides en fin qui peuvent etre interpretees
289 289
 			// comme des injections mail par les serveurs de messagerie.
290
-			$this->headers = preg_replace("/([\r\n]+)$/i","",$this->headers);
290
+			$this->headers = preg_replace("/([\r\n]+)$/i", "", $this->headers);
291 291
 
292 292
 			//$this->message = $this->eol.'This is a message with multiple parts in MIME format.'.$this->eol;
293 293
 			$this->message = 'This is a message with multiple parts in MIME format.'.$this->eol;
294
-			$this->message.= $text_body . $files_encoded;
295
-			$this->message.= "--" . $this->mixed_boundary . "--" . $this->eol;
294
+			$this->message .= $text_body.$files_encoded;
295
+			$this->message .= "--".$this->mixed_boundary."--".$this->eol;
296 296
 		}
297 297
 		else if ($this->sendmode == 'smtps')
298 298
 		{
@@ -304,14 +304,14 @@  discard block
 block discarded – undo
304 304
 			$smtps->setCharSet($conf->file->character_set_client);
305 305
 
306 306
 			$smtps->setSubject($this->encodetorfc2822($subject));
307
-			$smtps->setTO($this->getValidAddress($to,0,1));
308
-			$smtps->setFrom($this->getValidAddress($from,0,1));
307
+			$smtps->setTO($this->getValidAddress($to, 0, 1));
308
+			$smtps->setFrom($this->getValidAddress($from, 0, 1));
309 309
 			$smtps->setTrackId($trackid);
310
-			$smtps->setReplyTo($this->getValidAddress($replyto,0,1));
310
+			$smtps->setReplyTo($this->getValidAddress($replyto, 0, 1));
311 311
 
312
-			if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
312
+			if (!empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
313 313
 
314
-			if (! empty($this->html))
314
+			if (!empty($this->html))
315 315
 			{
316 316
 				if (!empty($css))
317 317
 				{
@@ -322,14 +322,14 @@  discard block
 block discarded – undo
322 322
 				$msg = $this->checkIfHTML($msg);
323 323
 			}
324 324
 
325
-			if ($this->msgishtml) $smtps->setBodyContent($msg,'html');
326
-			else $smtps->setBodyContent($msg,'plain');
325
+			if ($this->msgishtml) $smtps->setBodyContent($msg, 'html');
326
+			else $smtps->setBodyContent($msg, 'plain');
327 327
 
328 328
 			if ($this->atleastoneimage)
329 329
 			{
330 330
 				foreach ($this->images_encoded as $img)
331 331
 				{
332
-					$smtps->setImageInline($img['image_encoded'],$img['name'],$img['content_type'],$img['cid']);
332
+					$smtps->setImageInline($img['image_encoded'], $img['name'], $img['content_type'], $img['cid']);
333 333
 				}
334 334
 			}
335 335
 
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
 			{
338 338
 				foreach ($filename_list as $i => $val)
339 339
 				{
340
-					$content=file_get_contents($filename_list[$i]);
341
-					$smtps->setAttachment($content,$mimefilename_list[$i],$mimetype_list[$i]);
340
+					$content = file_get_contents($filename_list[$i]);
341
+					$smtps->setAttachment($content, $mimefilename_list[$i], $mimetype_list[$i]);
342 342
 				}
343 343
 			}
344 344
 
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 			$smtps->setErrorsTo($errors_to);
348 348
 			$smtps->setDeliveryReceipt($deliveryreceipt);
349 349
 
350
-			$this->smtps=$smtps;
350
+			$this->smtps = $smtps;
351 351
 		}
352 352
 		else if ($this->sendmode == 'swiftmailer')
353 353
 		{
@@ -383,8 +383,8 @@  discard block
 block discarded – undo
383 383
             //$this->message = new Swift_SignedMessage();
384 384
             // Adding a trackid header to a message
385 385
 			$headers = $this->message->getHeaders();
386
-			$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid . '@' . $host);
387
-			$headerID = time() . '.swiftmailer-dolibarr-' . $trackid . '@' . $host;
386
+			$headers->addTextHeader('X-Dolibarr-TRACKID', $trackid.'@'.$host);
387
+			$headerID = time().'.swiftmailer-dolibarr-'.$trackid.'@'.$host;
388 388
 			$msgid = $headers->get('Message-ID');
389 389
 			$msgid->setId($headerID);
390 390
 			$headers->addIdHeader('References', $headerID);
@@ -394,12 +394,12 @@  discard block
 block discarded – undo
394 394
 			try {
395 395
 				$result = $this->message->setSubject($subject);
396 396
 			} catch (Exception $e) {
397
-				$this->errors[] =  $e->getMessage();
397
+				$this->errors[] = $e->getMessage();
398 398
 			}
399 399
 
400 400
 			// Set the From address with an associative array
401 401
 			//$this->message->setFrom(array('[email protected]' => 'John Doe'));
402
-			if (! empty($from)) {
402
+			if (!empty($from)) {
403 403
                 try {
404 404
                 	$result = $this->message->setFrom($this->getArrayAddress($from));
405 405
                 } catch (Exception $e) {
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
             }
409 409
 
410 410
 			// Set the To addresses with an associative array
411
-			if (! empty($to)) {
411
+			if (!empty($to)) {
412 412
                 try {
413 413
                 	$result = $this->message->setTo($this->getArrayAddress($to));
414 414
                 } catch (Exception $e) {
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
                 }
417 417
             }
418 418
 
419
-			if (! empty($replyto)) {
419
+			if (!empty($replyto)) {
420 420
                 try {
421 421
                 	$result = $this->message->SetReplyTo($this->getArrayAddress($replyto));
422 422
                 } catch (Exception $e) {
@@ -427,10 +427,10 @@  discard block
 block discarded – undo
427 427
 			try {
428 428
 				$result = $this->message->setCharSet($conf->file->character_set_client);
429 429
 			} catch (Exception $e) {
430
-				$this->errors[] =  $e->getMessage();
430
+				$this->errors[] = $e->getMessage();
431 431
 			}
432 432
 
433
-			if (! empty($this->html))
433
+			if (!empty($this->html))
434 434
 			{
435 435
 				if (!empty($css))
436 436
 				{
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 			}
456 456
 
457 457
 			if ($this->msgishtml) {
458
-				$this->message->setBody($msg,'text/html');
458
+				$this->message->setBody($msg, 'text/html');
459 459
 				// And optionally an alternative body
460 460
 				$this->message->addPart(html_entity_decode(strip_tags($msg)), 'text/plain');
461 461
 			} else {
462
-				$this->message->setBody($msg,'text/plain');
462
+				$this->message->setBody($msg, 'text/plain');
463 463
 				// And optionally an alternative body
464 464
 				$this->message->addPart($msg, 'text/html');
465 465
 			}
@@ -469,13 +469,13 @@  discard block
 block discarded – undo
469 469
 				foreach ($filename_list as $i => $val)
470 470
 				{
471 471
 					//$this->message->attach(Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]));
472
-					$attachment = Swift_Attachment::fromPath($filename_list[$i],$mimetype_list[$i]);
472
+					$attachment = Swift_Attachment::fromPath($filename_list[$i], $mimetype_list[$i]);
473 473
 					$this->message->attach($attachment);
474 474
 				}
475 475
 			}
476 476
 
477
-			if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
-			if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
477
+			if (!empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
+			if (!empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
479 479
 			//if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to);
480 480
 			if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from));
481 481
 		}
@@ -495,25 +495,25 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	function sendfile()
497 497
 	{
498
-		global $conf,$db,$langs;
498
+		global $conf, $db, $langs;
499 499
 
500
-		$errorlevel=error_reporting();
500
+		$errorlevel = error_reporting();
501 501
 		//error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
502 502
 
503
-		$res=false;
503
+		$res = false;
504 504
 
505 505
 		if (empty($conf->global->MAIN_DISABLE_ALL_MAILS) || !empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
506 506
 		{
507
-			require_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php';
507
+			require_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php';
508 508
 			$hookmanager = new HookManager($db);
509 509
 			$hookmanager->initHooks(array('mail'));
510 510
 
511
-			$parameters=array(); $action='';
511
+			$parameters = array(); $action = '';
512 512
 			$reshook = $hookmanager->executeHooks('sendMail', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
513 513
 			if ($reshook < 0)
514 514
 			{
515
-				$this->error = "Error in hook maildao sendMail " . $reshook;
516
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
515
+				$this->error = "Error in hook maildao sendMail ".$reshook;
516
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
517 517
 
518 518
 				return $reshook;
519 519
 			}
@@ -523,52 +523,52 @@  discard block
 block discarded – undo
523 523
 			}
524 524
 
525 525
 			// Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL
526
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10;
526
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL = 10;
527 527
 			$tmparray1 = explode(',', $this->addr_to);
528 528
 			if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)
529 529
 			{
530 530
 				$this->error = 'Too much recipients in to:';
531
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
531
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
532 532
 				return false;
533 533
 			}
534
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10;
534
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL = 10;
535 535
 			$tmparray2 = explode(',', $this->addr_cc);
536 536
 			if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)
537 537
 			{
538 538
 				$this->error = 'Too much recipients in cc:';
539
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
539
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
540 540
 				return false;
541 541
 			}
542
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10;
542
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL = 10;
543 543
 			$tmparray3 = explode(',', $this->addr_bcc);
544 544
 			if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)
545 545
 			{
546 546
 				$this->error = 'Too much recipients in bcc:';
547
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
547
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
548 548
 				return false;
549 549
 			}
550
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10;
551
-			if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
550
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL = 10;
551
+			if ((count($tmparray1) + count($tmparray2) + count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
552 552
 			{
553 553
 				$this->error = 'Too much recipients in to:, cc:, bcc:';
554
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
554
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_WARNING);
555 555
 				return false;
556 556
 			}
557 557
 
558
-			$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
559
-			$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
560
-			$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
561
-			$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
562
-			$keyfortls       ='MAIN_MAIL_EMAIL_TLS';
563
-			$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
558
+			$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER';
559
+			$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT';
560
+			$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID';
561
+			$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW';
562
+			$keyfortls       = 'MAIN_MAIL_EMAIL_TLS';
563
+			$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS';
564 564
 			if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
565 565
 			{
566
-				$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
567
-				$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
568
-				$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
569
-				$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
570
-				$keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
571
-				$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
566
+				$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING';
567
+				$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT_EMAILING';
568
+				$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID_EMAILING';
569
+				$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW_EMAILING';
570
+				$keyfortls       = 'MAIN_MAIL_EMAIL_TLS_EMAILING';
571
+				$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
572 572
 			}
573 573
 
574 574
 			if (!empty($conf->global->MAIN_MAIL_FORCE_SENDTO))
@@ -591,68 +591,68 @@  discard block
 block discarded – undo
591 591
 				if (isset($_SERVER["WINDIR"]))
592 592
 				{
593 593
 					if (empty($this->addr_from)) $this->addr_from = '[email protected]';
594
-					@ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2));
594
+					@ini_set('sendmail_from', $this->getValidAddress($this->addr_from, 2));
595 595
 				}
596 596
 
597 597
 				// Force parameters
598
-				if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver);
599
-				if (! empty($conf->global->$keyforsmtpport))   ini_set('smtp_port',$conf->global->$keyforsmtpport);
598
+				if (!empty($conf->global->$keyforsmtpserver)) ini_set('SMTP', $conf->global->$keyforsmtpserver);
599
+				if (!empty($conf->global->$keyforsmtpport))   ini_set('smtp_port', $conf->global->$keyforsmtpport);
600 600
 
601
-				$res=true;
602
-				if ($res && ! $this->subject)
601
+				$res = true;
602
+				if ($res && !$this->subject)
603 603
 				{
604
-					$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
604
+					$this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Subject is empty";
605 605
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
606
-					$res=false;
606
+					$res = false;
607 607
 				}
608
-				$dest=$this->getValidAddress($this->addr_to,2);
609
-				if ($res && ! $dest)
608
+				$dest = $this->getValidAddress($this->addr_to, 2);
609
+				if ($res && !$dest)
610 610
 				{
611
-					$this->error="Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
611
+					$this->error = "Failed to send mail with php mail to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port')."<br>Recipient address '$dest' invalid";
612 612
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
613
-					$res=false;
613
+					$res = false;
614 614
 				}
615 615
 
616 616
 				if ($res)
617 617
 				{
618
-					$additionnalparam = '';	// By default
619
-					if (! empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
618
+					$additionnalparam = ''; // By default
619
+					if (!empty($conf->global->MAIN_MAIL_ALLOW_SENDMAIL_F))
620 620
 					{
621 621
 						// le "Return-Path" (retour des messages bounced) dans les header ne fonctionne pas avec tous les MTA
622 622
 						// Le forcage de la valeur grace à l'option -f de sendmail est donc possible si la constante MAIN_MAIL_ALLOW_SENDMAIL_F est definie.
623 623
 						// Having this variable defined may create problems with some sendmail (option -f refused)
624 624
 						// Having this variable not defined may create problems with some other sendmail (option -f required)
625
-						$additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') );
625
+						$additionnalparam .= ($additionnalparam ? ' ' : '').(!empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f'.$this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO, 2) : ($this->addr_from != '' ? '-f'.$this->getValidAddress($this->addr_from, 2) : ''));
626 626
 					}
627
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
627
+					if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
628 628
 					{
629
-						$additionnalparam .= ($additionnalparam?' ':'').'-ba';
629
+						$additionnalparam .= ($additionnalparam ? ' ' : '').'-ba';
630 630
 					}
631 631
 
632
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params
632
+					if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam ? ' ' : '').'-U '.$additionnalparam; // Use -U to add additionnal params
633 633
 
634 634
 					dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
635 635
 
636
-					$this->message=stripslashes($this->message);
636
+					$this->message = stripslashes($this->message);
637 637
 
638
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
638
+					if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
639 639
 
640
-					if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
640
+					if (!empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
641 641
 					else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers);
642 642
 
643
-					if (! $res)
643
+					if (!$res)
644 644
 					{
645 645
 						$langs->load("errors");
646
-						$this->error="Failed to send mail with php mail";
647
-						$linuxlike=1;
648
-						if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
649
-						if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
650
-						if (! $linuxlike)
646
+						$this->error = "Failed to send mail with php mail";
647
+						$linuxlike = 1;
648
+						if (preg_match('/^win/i', PHP_OS)) $linuxlike = 0;
649
+						if (preg_match('/^mac/i', PHP_OS)) $linuxlike = 0;
650
+						if (!$linuxlike)
651 651
 						{
652
-							$this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port');	// This values are value used only for non linuxlike systems
652
+							$this->error .= " to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port'); // This values are value used only for non linuxlike systems
653 653
 						}
654
-						$this->error.=".<br>";
655
-						$this->error.=$langs->trans("ErrorPhpMailDelivery");
654
+						$this->error .= ".<br>";
655
+						$this->error .= $langs->trans("ErrorPhpMailDelivery");
656 656
 						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
657 657
 					}
658 658
 					else
@@ -667,86 +667,86 @@  discard block
 block discarded – undo
667 667
 				}
668 668
 
669 669
 				// Restore parameters
670
-				if (! empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
-				if (! empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
670
+				if (!empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
+				if (!empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
672 672
 			}
673 673
 			else if ($this->sendmode == 'smtps')
674 674
 			{
675
-				if (! is_object($this->smtps))
675
+				if (!is_object($this->smtps))
676 676
 				{
677
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors.";
677
+					$this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Constructor of object CMailFile was not initialized without errors.";
678 678
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
679 679
 					return false;
680 680
 				}
681 681
 
682 682
 				// Use SMTPS library
683 683
 				// ------------------------------------------
684
-				$this->smtps->setTransportType(0);	// Only this method is coded in SMTPs library
684
+				$this->smtps->setTransportType(0); // Only this method is coded in SMTPs library
685 685
 
686 686
 				// Clean parameters
687
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
688
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
687
+				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP');
688
+				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport = ini_get('smtp_port');
689 689
 
690 690
 				// If we use SSL/TLS
691
-				$server=$conf->global->$keyforsmtpserver;
692
-				$secure='';
693
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
694
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
695
-				$server=($secure?$secure.'://':'').$server;
691
+				$server = $conf->global->$keyforsmtpserver;
692
+				$secure = '';
693
+				if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl';
694
+				if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls';
695
+				$server = ($secure ? $secure.'://' : '').$server;
696 696
 
697
-				$port=$conf->global->$keyforsmtpport;
697
+				$port = $conf->global->$keyforsmtpport;
698 698
 
699 699
 				$this->smtps->setHost($server);
700 700
 				$this->smtps->setPort($port); // 25, 465...;
701 701
 
702
-				$loginid=''; $loginpass='';
703
-				if (! empty($conf->global->$keyforsmtpid))
702
+				$loginid = ''; $loginpass = '';
703
+				if (!empty($conf->global->$keyforsmtpid))
704 704
 				{
705 705
 					$loginid = $conf->global->$keyforsmtpid;
706 706
 					$this->smtps->setID($loginid);
707 707
 				}
708
-				if (! empty($conf->global->$keyforsmtppw))
708
+				if (!empty($conf->global->$keyforsmtppw))
709 709
 				{
710 710
 					$loginpass = $conf->global->$keyforsmtppw;
711 711
 					$this->smtps->setPW($loginpass);
712 712
 				}
713 713
 
714
-				$res=true;
715
-				$from=$this->smtps->getFrom('org');
716
-				if ($res && ! $from)
714
+				$res = true;
715
+				$from = $this->smtps->getFrom('org');
716
+				if ($res && !$from)
717 717
 				{
718
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
718
+					$this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Sender address '$from' invalid";
719 719
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
720
-					$res=false;
720
+					$res = false;
721 721
 				}
722
-				$dest=$this->smtps->getTo();
723
-				if ($res && ! $dest)
722
+				$dest = $this->smtps->getTo();
723
+				if ($res && !$dest)
724 724
 				{
725
-					$this->error="Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
725
+					$this->error = "Failed to send mail with smtps lib to HOST=".$server.", PORT=".$conf->global->$keyforsmtpport."<br>Recipient address '$dest' invalid";
726 726
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
727
-					$res=false;
727
+					$res = false;
728 728
 				}
729 729
 
730 730
 				if ($res)
731 731
 				{
732
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
732
+					if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
733 733
 
734
-					$result=$this->smtps->sendMsg();
734
+					$result = $this->smtps->sendMsg();
735 735
 					//print $result;
736 736
 
737
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
737
+					if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
738 738
 
739
-					$result=$this->smtps->getErrors();
739
+					$result = $this->smtps->getErrors();
740 740
 					if (empty($this->error) && empty($result))
741 741
 					{
742 742
 						dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
743
-						$res=true;
743
+						$res = true;
744 744
 					}
745 745
 					else
746 746
 					{
747
-						if (empty($this->error)) $this->error=$result;
747
+						if (empty($this->error)) $this->error = $result;
748 748
 						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
749
-						$res=false;
749
+						$res = false;
750 750
 					}
751 751
 				}
752 752
 			}
@@ -757,19 +757,19 @@  discard block
 block discarded – undo
757 757
 				require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
758 758
 
759 759
 				// Clean parameters
760
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
761
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
760
+				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver = ini_get('SMTP');
761
+				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport = ini_get('smtp_port');
762 762
 
763 763
 				// If we use SSL/TLS
764 764
 				$server = $conf->global->$keyforsmtpserver;
765 765
 				$secure = '';
766
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
767
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
766
+				if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure = 'ssl';
767
+				if (!empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure = 'tls';
768 768
 
769 769
 				$this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
770 770
 
771
-				if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
-				if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
771
+				if (!empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
+				if (!empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
773 773
 				//$smtps->_msgReplyTo  = '[email protected]';
774 774
 
775 775
 				// Create the Mailer using your created Transport
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
                     $this->message->attachSigner($signer->ignoreHeader('Return-Path'));
785 785
                 }
786 786
 
787
-                if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
787
+                if (!empty($conf->global->MAIN_MAIL_DEBUG)) {
788 788
 					// To use the ArrayLogger
789 789
 					$this->logger = new Swift_Plugins_Loggers_ArrayLogger();
790 790
 					// Or to use the Echo Logger
@@ -795,14 +795,14 @@  discard block
 block discarded – undo
795 795
 				try {
796 796
 					$result = $this->mailer->send($this->message);
797 797
 				} catch (Exception $e) {
798
-					$this->error =  $e->getMessage();
798
+					$this->error = $e->getMessage();
799 799
 				}
800
-				if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
800
+				if (!empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
801 801
 
802 802
 				$res = true;
803
-				if (! empty($this->error) || ! $result) {
803
+				if (!empty($this->error) || !$result) {
804 804
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
805
-					$res=false;
805
+					$res = false;
806 806
 				}
807 807
 				else
808 808
 				{
@@ -817,23 +817,23 @@  discard block
 block discarded – undo
817 817
 				return 'Bad value for sendmode';
818 818
 			}
819 819
 
820
-			$parameters=array(); $action='';
820
+			$parameters = array(); $action = '';
821 821
 			$reshook = $hookmanager->executeHooks('sendMailAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
822 822
 			if ($reshook < 0)
823 823
 			{
824
-				$this->error = "Error in hook maildao sendMailAfter " . $reshook;
825
-				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_ERR);
824
+				$this->error = "Error in hook maildao sendMailAfter ".$reshook;
825
+				dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
826 826
 
827 827
 				return $reshook;
828 828
 			}
829 829
 		}
830 830
 		else
831 831
 		{
832
-			$this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
832
+			$this->error = 'No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
833 833
 			dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING);
834 834
 		}
835 835
 
836
-		error_reporting($errorlevel);              // Reactive niveau erreur origine
836
+		error_reporting($errorlevel); // Reactive niveau erreur origine
837 837
 
838 838
 		return $res;
839 839
 	}
@@ -860,17 +860,17 @@  discard block
 block discarded – undo
860 860
 	function _encode_file($sourcefile)
861 861
 	{
862 862
         // phpcs:enable
863
-		$newsourcefile=dol_osencode($sourcefile);
863
+		$newsourcefile = dol_osencode($sourcefile);
864 864
 
865 865
 		if (is_readable($newsourcefile))
866 866
 		{
867
-			$contents = file_get_contents($newsourcefile);	// Need PHP 4.3
868
-			$encoded = chunk_split(base64_encode($contents), 76, $this->eol);    // 76 max is defined into http://tools.ietf.org/html/rfc2047
867
+			$contents = file_get_contents($newsourcefile); // Need PHP 4.3
868
+			$encoded = chunk_split(base64_encode($contents), 76, $this->eol); // 76 max is defined into http://tools.ietf.org/html/rfc2047
869 869
 			return $encoded;
870 870
 		}
871 871
 		else
872 872
 		{
873
-			$this->error="Error: Can't read file '".$sourcefile."' into _encode_file";
873
+			$this->error = "Error: Can't read file '".$sourcefile."' into _encode_file";
874 874
 			dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR);
875 875
 			return -1;
876 876
 		}
@@ -888,30 +888,30 @@  discard block
 block discarded – undo
888 888
 	function dump_mail()
889 889
 	{
890 890
         // phpcs:enable
891
-		global $conf,$dolibarr_main_data_root;
891
+		global $conf, $dolibarr_main_data_root;
892 892
 
893 893
 		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
894 894
 		{
895
-			$outputfile=$dolibarr_main_data_root."/dolibarr_mail.log";
896
-			$fp = fopen($outputfile,"w");
895
+			$outputfile = $dolibarr_main_data_root."/dolibarr_mail.log";
896
+			$fp = fopen($outputfile, "w");
897 897
 
898 898
 			if ($this->sendmode == 'mail')
899 899
 			{
900 900
 				fputs($fp, $this->headers);
901
-				fputs($fp, $this->eol);			// This eol is added by the mail function, so we add it in log
901
+				fputs($fp, $this->eol); // This eol is added by the mail function, so we add it in log
902 902
 				fputs($fp, $this->message);
903 903
 			}
904 904
 			elseif ($this->sendmode == 'smtps')
905 905
 			{
906
-				fputs($fp, $this->smtps->log);	// this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
906
+				fputs($fp, $this->smtps->log); // this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
907 907
 			}
908 908
 			elseif ($this->sendmode == 'swiftmailer')
909 909
 			{
910
-				fputs($fp, $this->logger->dump());	// this->logger is filled only if MAIN_MAIL_DEBUG was set to on
910
+				fputs($fp, $this->logger->dump()); // this->logger is filled only if MAIN_MAIL_DEBUG was set to on
911 911
 			}
912 912
 
913 913
 			fclose($fp);
914
-			if (! empty($conf->global->MAIN_UMASK))
914
+			if (!empty($conf->global->MAIN_UMASK))
915 915
 				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
916 916
 		}
917 917
 	}
@@ -925,15 +925,15 @@  discard block
 block discarded – undo
925 925
 	 */
926 926
 	function checkIfHTML($msg)
927 927
 	{
928
-		if (!preg_match('/^[\s\t]*<html/i',$msg))
928
+		if (!preg_match('/^[\s\t]*<html/i', $msg))
929 929
 		{
930 930
 			$out = "<html><head><title></title>";
931
-			if (!empty($this->styleCSS)) $out.= $this->styleCSS;
932
-			$out.= "</head><body";
933
-			if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
934
-			$out.= ">";
935
-			$out.= $msg;
936
-			$out.= "</body></html>";
931
+			if (!empty($this->styleCSS)) $out .= $this->styleCSS;
932
+			$out .= "</head><body";
933
+			if (!empty($this->bodyCSS)) $out .= $this->bodyCSS;
934
+			$out .= ">";
935
+			$out .= $msg;
936
+			$out .= "</body></html>";
937 937
 		}
938 938
 		else
939 939
 		{
@@ -950,24 +950,24 @@  discard block
 block discarded – undo
950 950
 	 */
951 951
 	function buildCSS()
952 952
 	{
953
-		if (! empty($this->css))
953
+		if (!empty($this->css))
954 954
 		{
955 955
 			// Style CSS
956 956
 			$this->styleCSS = '<style type="text/css">';
957
-			$this->styleCSS.= 'body {';
957
+			$this->styleCSS .= 'body {';
958 958
 
959 959
 			if ($this->css['bgcolor'])
960 960
 			{
961
-				$this->styleCSS.= '  background-color: '.$this->css['bgcolor'].';';
962
-				$this->bodyCSS.= ' bgcolor="'.$this->css['bgcolor'].'"';
961
+				$this->styleCSS .= '  background-color: '.$this->css['bgcolor'].';';
962
+				$this->bodyCSS .= ' bgcolor="'.$this->css['bgcolor'].'"';
963 963
 			}
964 964
 			if ($this->css['bgimage'])
965 965
 			{
966 966
 				// TODO recuperer cid
967
-				$this->styleCSS.= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
967
+				$this->styleCSS .= ' background-image: url("cid:'.$this->css['bgimage_cid'].'");';
968 968
 			}
969
-			$this->styleCSS.= '}';
970
-			$this->styleCSS.= '</style>';
969
+			$this->styleCSS .= '}';
970
+			$this->styleCSS .= '</style>';
971 971
 		}
972 972
 	}
973 973
 
@@ -988,48 +988,48 @@  discard block
 block discarded – undo
988 988
 
989 989
 		// Sender
990 990
 		//$out.= "Sender: ".getValidAddress($this->addr_from,2)).$this->eol2;
991
-		$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol2;
992
-		if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
991
+		$out .= "From: ".$this->getValidAddress($this->addr_from, 3, 1).$this->eol2;
992
+		if (!empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))
993 993
 		{
994
-			$out.= "To: ".$this->getValidAddress($this->addr_to,0,1).$this->eol2;
994
+			$out .= "To: ".$this->getValidAddress($this->addr_to, 0, 1).$this->eol2;
995 995
 		}
996 996
 		// Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that.
997
-		$out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2;
998
-		if (isset($this->reply_to)  && $this->reply_to)  $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2;
999
-		if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2;
997
+		$out .= "Return-Path: ".$this->getValidAddress($this->addr_from, 0, 1).$this->eol2;
998
+		if (isset($this->reply_to) && $this->reply_to)  $out .= "Reply-To: ".$this->getValidAddress($this->reply_to, 2).$this->eol2;
999
+		if (isset($this->errors_to) && $this->errors_to) $out .= "Errors-To: ".$this->getValidAddress($this->errors_to, 2).$this->eol2;
1000 1000
 
1001 1001
 		// Receiver
1002
-		if (isset($this->addr_cc)   && $this->addr_cc)   $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2;
1003
-		if (isset($this->addr_bcc)  && $this->addr_bcc)  $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2;    // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1002
+		if (isset($this->addr_cc) && $this->addr_cc)   $out .= "Cc: ".$this->getValidAddress($this->addr_cc, 2).$this->eol2;
1003
+		if (isset($this->addr_bcc) && $this->addr_bcc)  $out .= "Bcc: ".$this->getValidAddress($this->addr_bcc, 2).$this->eol2; // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1004 1004
 
1005 1005
 		// Delivery receipt
1006
-		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2;
1006
+		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out .= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from, 2).$this->eol2;
1007 1007
 
1008 1008
 		//$out.= "X-Priority: 3".$this->eol2;
1009 1009
 
1010
-		$out.= 'Date: ' . date("r") . $this->eol2;
1010
+		$out .= 'Date: '.date("r").$this->eol2;
1011 1011
 
1012 1012
 		$trackid = $this->trackid;
1013 1013
 		if ($trackid)
1014 1014
 		{
1015 1015
 			// References is kept in response and Message-ID is returned into In-Reply-To:
1016
-			$out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;	// Uppercase seems replaced by phpmail
1017
-			$out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;
1018
-			$out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2;
1016
+			$out .= 'Message-ID: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2; // Uppercase seems replaced by phpmail
1017
+			$out .= 'References: <'.time().'.phpmail-dolibarr-'.$trackid.'@'.$host.">".$this->eol2;
1018
+			$out .= 'X-Dolibarr-TRACKID: '.$trackid.'@'.$host.$this->eol2;
1019 1019
 		}
1020 1020
 		else
1021 1021
 		{
1022
-			$out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
1022
+			$out .= 'Message-ID: <'.time().'.phpmail@'.$host.">".$this->eol2;
1023 1023
 		}
1024 1024
 
1025
-		if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2;
1026
-		$out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2;
1027
-		$out.= "Mime-Version: 1.0".$this->eol2;
1025
+		if (!empty($_SERVER['REMOTE_ADDR'])) $out .= "X-RemoteAddr: ".$_SERVER['REMOTE_ADDR'].$this->eol2;
1026
+		$out .= "X-Mailer: Dolibarr version ".DOL_VERSION." (using php mail)".$this->eol2;
1027
+		$out .= "Mime-Version: 1.0".$this->eol2;
1028 1028
 
1029 1029
 		//$out.= "From: ".$this->getValidAddress($this->addr_from,3,1).$this->eol;
1030 1030
 
1031
-		$out.= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
1032
-		$out.= "Content-Transfer-Encoding: 8bit".$this->eol2;		// TODO Seems to be ignored. Header is 7bit once received.
1031
+		$out .= "Content-Type: multipart/mixed;".$this->eol2." boundary=\"".$this->mixed_boundary."\"".$this->eol2;
1032
+		$out .= "Content-Transfer-Encoding: 8bit".$this->eol2; // TODO Seems to be ignored. Header is 7bit once received.
1033 1033
 
1034 1034
 		dol_syslog("CMailFile::write_smtpheaders smtp_header=\n".$out);
1035 1035
 		return $out;
@@ -1047,18 +1047,18 @@  discard block
 block discarded – undo
1047 1047
 	function write_mimeheaders($filename_list, $mimefilename_list)
1048 1048
 	{
1049 1049
         // phpcs:enable
1050
-		$mimedone=0;
1050
+		$mimedone = 0;
1051 1051
 		$out = "";
1052 1052
 
1053 1053
 		if (is_array($filename_list))
1054 1054
 		{
1055
-			$filename_list_size=count($filename_list);
1056
-			for($i=0;$i < $filename_list_size;$i++)
1055
+			$filename_list_size = count($filename_list);
1056
+			for ($i = 0; $i < $filename_list_size; $i++)
1057 1057
 			{
1058 1058
 				if ($filename_list[$i])
1059 1059
 				{
1060 1060
 					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1061
-					$out.= "X-attachments: $filename_list[$i]".$this->eol2;
1061
+					$out .= "X-attachments: $filename_list[$i]".$this->eol2;
1062 1062
 				}
1063 1063
 			}
1064 1064
 		}
@@ -1079,31 +1079,31 @@  discard block
 block discarded – undo
1079 1079
         // phpcs:enable
1080 1080
 		global $conf;
1081 1081
 
1082
-		$out='';
1082
+		$out = '';
1083 1083
 
1084
-		$out.= "--" . $this->mixed_boundary . $this->eol;
1084
+		$out .= "--".$this->mixed_boundary.$this->eol;
1085 1085
 
1086 1086
 		if ($this->atleastoneimage)
1087 1087
 		{
1088
-			$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1089
-			$out.= $this->eol;
1090
-			$out.= "--" . $this->alternative_boundary . $this->eol;
1088
+			$out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1089
+			$out .= $this->eol;
1090
+			$out .= "--".$this->alternative_boundary.$this->eol;
1091 1091
 		}
1092 1092
 
1093 1093
 		// Make RFC821 Compliant, replace bare linefeeds
1094
-		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext);	// PCRE modifier /s means new lines are common chars
1095
-		if (! empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1094
+		$strContent = preg_replace("/(?<!\r)\n/si", "\r\n", $msgtext); // PCRE modifier /s means new lines are common chars
1095
+		if (!empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA))
1096 1096
 		{
1097
-			$strContent = preg_replace("/\r\n/si", "\n", $strContent);	// PCRE modifier /s means new lines are common chars
1097
+			$strContent = preg_replace("/\r\n/si", "\n", $strContent); // PCRE modifier /s means new lines are common chars
1098 1098
 		}
1099 1099
 
1100 1100
 		$strContentAltText = '';
1101 1101
 		if ($this->msgishtml)
1102 1102
 		{
1103 1103
 			// Similar code to forge a text from html is also in CMailFile.class.php
1104
-			$strContentAltText = preg_replace("/<br\s*[^>]*>/"," ", $strContent);
1104
+			$strContentAltText = preg_replace("/<br\s*[^>]*>/", " ", $strContent);
1105 1105
 			$strContentAltText = html_entity_decode(strip_tags($strContentAltText));
1106
-			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));
1106
+			$strContentAltText = rtrim(wordwrap($strContentAltText, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n"));
1107 1107
 
1108 1108
 			// Check if html header already in message, if not complete the message
1109 1109
 			$strContent = $this->checkIfHTML($strContent);
@@ -1112,57 +1112,57 @@  discard block
 block discarded – undo
1112 1112
 		// Make RFC2045 Compliant, split lines
1113 1113
 		//$strContent = rtrim(chunk_split($strContent));    // Function chunck_split seems ko if not used on a base64 content
1114 1114
 		// TODO Encode main content into base64 and use the chunk_split, or quoted-printable
1115
-		$strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA)?"\r\n":"\n"));   // TODO Using this method creates unexpected line break on text/plain content.
1115
+		$strContent = rtrim(wordwrap($strContent, 75, empty($conf->global->MAIN_FIX_FOR_BUGGED_MTA) ? "\r\n" : "\n")); // TODO Using this method creates unexpected line break on text/plain content.
1116 1116
 
1117 1117
 		if ($this->msgishtml)
1118 1118
 		{
1119 1119
 			if ($this->atleastoneimage)
1120 1120
 			{
1121
-				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1121
+				$out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1122 1122
 				//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1123
-				$out.= $this->eol.($strContentAltText?$strContentAltText:strip_tags($strContent)).$this->eol; // Add plain text message
1124
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1125
-				$out.= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
1126
-				$out.= $this->eol;
1127
-				$out.= "--" . $this->related_boundary . $this->eol;
1123
+				$out .= $this->eol.($strContentAltText ? $strContentAltText : strip_tags($strContent)).$this->eol; // Add plain text message
1124
+				$out .= "--".$this->alternative_boundary.$this->eol;
1125
+				$out .= "Content-Type: multipart/related;".$this->eol." boundary=\"".$this->related_boundary."\"".$this->eol;
1126
+				$out .= $this->eol;
1127
+				$out .= "--".$this->related_boundary.$this->eol;
1128 1128
 			}
1129 1129
 
1130
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1130
+			if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1131 1131
 			{
1132
-				$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1133
-				$out.= $this->eol;
1134
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1135
-				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1132
+				$out .= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1133
+				$out .= $this->eol;
1134
+				$out .= "--".$this->alternative_boundary.$this->eol;
1135
+				$out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1136 1136
 				//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1137
-				$out.= $this->eol.$strContentAltText.$this->eol;
1138
-				$out.= "--" . $this->alternative_boundary . $this->eol;
1137
+				$out .= $this->eol.$strContentAltText.$this->eol;
1138
+				$out .= "--".$this->alternative_boundary.$this->eol;
1139 1139
 			}
1140 1140
 
1141
-			$out.= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1141
+			$out .= "Content-Type: text/html; charset=".$conf->file->character_set_client.$this->eol;
1142 1142
 			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;	// TODO Use base64
1143
-			$out.= $this->eol.$strContent.$this->eol;
1143
+			$out .= $this->eol.$strContent.$this->eol;
1144 1144
 
1145
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1145
+			if (!$this->atleastoneimage && $strContentAltText && !empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1146 1146
 			{
1147
-				$out.= "--" . $this->alternative_boundary . "--". $this->eol;
1147
+				$out .= "--".$this->alternative_boundary."--".$this->eol;
1148 1148
 			}
1149 1149
 		}
1150 1150
 		else
1151 1151
 		{
1152
-			$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1152
+			$out .= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1153 1153
 			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
1154
-			$out.= $this->eol.$strContent.$this->eol;
1154
+			$out .= $this->eol.$strContent.$this->eol;
1155 1155
 		}
1156 1156
 
1157
-		$out.= $this->eol;
1157
+		$out .= $this->eol;
1158 1158
 
1159 1159
 		// Encode images
1160 1160
 		if ($this->atleastoneimage)
1161 1161
 		{
1162 1162
 			$out .= $this->write_images($this->images_encoded);
1163 1163
 			// always end related and end alternative after inline images
1164
-			$out .= "--" . $this->related_boundary . "--" . $this->eol;
1165
-			$out .= $this->eol . "--" . $this->alternative_boundary . "--" . $this->eol;
1164
+			$out .= "--".$this->related_boundary."--".$this->eol;
1165
+			$out .= $this->eol."--".$this->alternative_boundary."--".$this->eol;
1166 1166
 			$out .= $this->eol;
1167 1167
 		}
1168 1168
 
@@ -1178,13 +1178,13 @@  discard block
 block discarded – undo
1178 1178
 	 * @param 	array	$mimefilename_list	Tableau
1179 1179
 	 * @return	string						Chaine fichiers encodes
1180 1180
 	 */
1181
-	function write_files($filename_list,$mimetype_list,$mimefilename_list)
1181
+	function write_files($filename_list, $mimetype_list, $mimefilename_list)
1182 1182
 	{
1183 1183
         // phpcs:enable
1184 1184
 		$out = '';
1185 1185
 
1186
-		$filename_list_size=count($filename_list);
1187
-		for($i=0;$i < $filename_list_size;$i++)
1186
+		$filename_list_size = count($filename_list);
1187
+		for ($i = 0; $i < $filename_list_size; $i++)
1188 1188
 		{
1189 1189
 			if ($filename_list[$i])
1190 1190
 			{
@@ -1193,18 +1193,18 @@  discard block
 block discarded – undo
1193 1193
 				if ($encoded >= 0)
1194 1194
 				{
1195 1195
 					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1196
-					if (! $mimetype_list[$i]) {
1196
+					if (!$mimetype_list[$i]) {
1197 1197
 						$mimetype_list[$i] = "application/octet-stream";
1198 1198
 					}
1199 1199
 
1200
-					$out.= "--" . $this->mixed_boundary . $this->eol;
1201
-					$out.= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
1202
-					$out.= "Content-Type: " . $mimetype_list[$i] . "; name=\"".$filename_list[$i]."\"".$this->eol;
1203
-					$out.= "Content-Transfer-Encoding: base64".$this->eol;
1204
-					$out.= "Content-Description: ".$filename_list[$i].$this->eol;
1205
-					$out.= $this->eol;
1206
-					$out.= $encoded;
1207
-					$out.= $this->eol;
1200
+					$out .= "--".$this->mixed_boundary.$this->eol;
1201
+					$out .= "Content-Disposition: attachment; filename=\"".$filename_list[$i]."\"".$this->eol;
1202
+					$out .= "Content-Type: ".$mimetype_list[$i]."; name=\"".$filename_list[$i]."\"".$this->eol;
1203
+					$out .= "Content-Transfer-Encoding: base64".$this->eol;
1204
+					$out .= "Content-Description: ".$filename_list[$i].$this->eol;
1205
+					$out .= $this->eol;
1206
+					$out .= $encoded;
1207
+					$out .= $this->eol;
1208 1208
 					//$out.= $this->eol;
1209 1209
 				}
1210 1210
 				else
@@ -1236,14 +1236,14 @@  discard block
 block discarded – undo
1236 1236
 			{
1237 1237
 				dol_syslog("CMailFile::write_images: ".$img["name"]);
1238 1238
 
1239
-				$out.= "--" . $this->related_boundary . $this->eol; // always related for an inline image
1240
-				$out.= "Content-Type: " . $img["content_type"] . "; name=\"".$img["name"]."\"".$this->eol;
1241
-				$out.= "Content-Transfer-Encoding: base64".$this->eol;
1242
-				$out.= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
1243
-				$out.= "Content-ID: <".$img["cid"].">".$this->eol;
1244
-				$out.= $this->eol;
1245
-				$out.= $img["image_encoded"];
1246
-				$out.= $this->eol;
1239
+				$out .= "--".$this->related_boundary.$this->eol; // always related for an inline image
1240
+				$out .= "Content-Type: ".$img["content_type"]."; name=\"".$img["name"]."\"".$this->eol;
1241
+				$out .= "Content-Transfer-Encoding: base64".$this->eol;
1242
+				$out .= "Content-Disposition: inline; filename=\"".$img["name"]."\"".$this->eol;
1243
+				$out .= "Content-ID: <".$img["cid"].">".$this->eol;
1244
+				$out .= $this->eol;
1245
+				$out .= $img["image_encoded"];
1246
+				$out .= $this->eol;
1247 1247
 			}
1248 1248
 		}
1249 1249
 
@@ -1259,44 +1259,44 @@  discard block
 block discarded – undo
1259 1259
 	 * @param 	int			$port		Example: 25, 465
1260 1260
 	 * @return	int						Socket id if ok, 0 if KO
1261 1261
 	 */
1262
-	function check_server_port($host,$port)
1262
+	function check_server_port($host, $port)
1263 1263
 	{
1264 1264
         // phpcs:enable
1265 1265
 		global $conf;
1266 1266
 
1267
-		$_retVal=0;
1268
-		$timeout=5;	// Timeout in seconds
1267
+		$_retVal = 0;
1268
+		$timeout = 5; // Timeout in seconds
1269 1269
 
1270 1270
 		if (function_exists('fsockopen'))
1271 1271
 		{
1272
-			$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER';
1273
-			$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT';
1274
-			$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID';
1275
-			$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW';
1276
-			$keyfortls       ='MAIN_MAIL_EMAIL_TLS';
1277
-			$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS';
1272
+			$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER';
1273
+			$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT';
1274
+			$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID';
1275
+			$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW';
1276
+			$keyfortls       = 'MAIN_MAIL_EMAIL_TLS';
1277
+			$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS';
1278 1278
 			if ($this->sendcontext == 'emailing' && !empty($conf->global->MAIN_MAIL_SENDMODE_EMAILING) && $conf->global->MAIN_MAIL_SENDMODE_EMAILING != 'default')
1279 1279
 			{
1280
-				$keyforsmtpserver='MAIN_MAIL_SMTP_SERVER_EMAILING';
1281
-				$keyforsmtpport  ='MAIN_MAIL_SMTP_PORT_EMAILING';
1282
-				$keyforsmtpid    ='MAIN_MAIL_SMTPS_ID_EMAILING';
1283
-				$keyforsmtppw    ='MAIN_MAIL_SMTPS_PW_EMAILING';
1284
-				$keyfortls       ='MAIN_MAIL_EMAIL_TLS_EMAILING';
1285
-				$keyforstarttls  ='MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1280
+				$keyforsmtpserver = 'MAIN_MAIL_SMTP_SERVER_EMAILING';
1281
+				$keyforsmtpport  = 'MAIN_MAIL_SMTP_PORT_EMAILING';
1282
+				$keyforsmtpid    = 'MAIN_MAIL_SMTPS_ID_EMAILING';
1283
+				$keyforsmtppw    = 'MAIN_MAIL_SMTPS_PW_EMAILING';
1284
+				$keyfortls       = 'MAIN_MAIL_EMAIL_TLS_EMAILING';
1285
+				$keyforstarttls  = 'MAIN_MAIL_EMAIL_STARTTLS_EMAILING';
1286 1286
 			}
1287 1287
 
1288 1288
 			// If we use SSL/TLS
1289
-			if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host;
1289
+			if (!empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host = 'ssl://'.$host;
1290 1290
 			// tls smtp start with no encryption
1291 1291
 			//if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host;
1292 1292
 
1293 1293
 			dol_syslog("Try socket connection to host=".$host." port=".$port);
1294 1294
 			//See if we can connect to the SMTP server
1295 1295
 			if ($socket = @fsockopen(
1296
-					$host,       // Host to test, IP or domain. Add ssl:// for SSL/TLS.
1297
-					$port,       // which Port number to use
1298
-					$errno,      // actual system level error
1299
-					$errstr,     // and any text that goes with the error
1296
+					$host, // Host to test, IP or domain. Add ssl:// for SSL/TLS.
1297
+					$port, // which Port number to use
1298
+					$errno, // actual system level error
1299
+					$errstr, // and any text that goes with the error
1300 1300
 					$timeout
1301 1301
 			))  // timeout for reading/writing data over the socket
1302 1302
 			{
@@ -1306,11 +1306,11 @@  discard block
 block discarded – undo
1306 1306
 				dol_syslog("Now we wait for answer 220");
1307 1307
 
1308 1308
 				// Check response from Server
1309
-				if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket;
1309
+				if ($_retVal = $this->server_parse($socket, "220")) $_retVal = $socket;
1310 1310
 			}
1311 1311
 			else
1312 1312
 			{
1313
-				$this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr);
1313
+				$this->error = utf8_check('Error '.$errno.' - '.$errstr) ? 'Error '.$errno.' - '.$errstr : utf8_encode('Error '.$errno.' - '.$errstr);
1314 1314
 			}
1315 1315
 		}
1316 1316
 		return $_retVal;
@@ -1328,21 +1328,21 @@  discard block
 block discarded – undo
1328 1328
 	function server_parse($socket, $response)
1329 1329
 	{
1330 1330
         // phpcs:enable
1331
-		$_retVal = true;	// Indicates if Object was created or not
1331
+		$_retVal = true; // Indicates if Object was created or not
1332 1332
 		$server_response = '';
1333 1333
 
1334
-		while (substr($server_response,3,1) != ' ')
1334
+		while (substr($server_response, 3, 1) != ' ')
1335 1335
 		{
1336
-			if (! ($server_response = fgets($socket, 256)) )
1336
+			if (!($server_response = fgets($socket, 256)))
1337 1337
 			{
1338
-				$this->error="Couldn't get mail server response codes";
1338
+				$this->error = "Couldn't get mail server response codes";
1339 1339
 				return false;
1340 1340
 			}
1341 1341
 		}
1342 1342
 
1343
-		if( !( substr($server_response, 0, 3) == $response ) )
1343
+		if (!(substr($server_response, 0, 3) == $response))
1344 1344
 		{
1345
-			$this->error="Ran into problems sending Mail.\r\nResponse: $server_response";
1345
+			$this->error = "Ran into problems sending Mail.\r\nResponse: $server_response";
1346 1346
 			$_retVal = false;
1347 1347
 		}
1348 1348
 
@@ -1361,22 +1361,22 @@  discard block
 block discarded – undo
1361 1361
 		$extensions = array_keys($this->image_types);
1362 1362
 
1363 1363
 		$matches = array();
1364
-		preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches);  // If "xxx.ext" or 'xxx.ext' found
1364
+		preg_match_all('/(?:"|\')([^"\']+\.('.implode('|', $extensions).'))(?:"|\')/Ui', $this->html, $matches); // If "xxx.ext" or 'xxx.ext' found
1365 1365
 
1366
-		if (! empty($matches))
1366
+		if (!empty($matches))
1367 1367
 		{
1368
-			$i=0;
1368
+			$i = 0;
1369 1369
 			foreach ($matches[1] as $full)
1370 1370
 			{
1371 1371
 
1372
-				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs))   // If xxx is 'file=aaa'
1372
+				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i', $full, $regs))   // If xxx is 'file=aaa'
1373 1373
 				{
1374 1374
 					$img = $regs[1];
1375 1375
 
1376 1376
 					if (file_exists($images_dir.'/'.$img))
1377 1377
 					{
1378 1378
 						// Image path in src
1379
-						$src = preg_quote($full,'/');
1379
+						$src = preg_quote($full, '/');
1380 1380
 
1381 1381
 						// Image full path
1382 1382
 						$this->html_images[$i]["fullpath"] = $images_dir.'/'.$img;
@@ -1387,12 +1387,12 @@  discard block
 block discarded – undo
1387 1387
 						// Content type
1388 1388
 						if (preg_match('/^.+\.(\w{3,4})$/', $img, $reg))
1389 1389
 						{
1390
-							$ext=strtolower($reg[1]);
1390
+							$ext = strtolower($reg[1]);
1391 1391
 							$this->html_images[$i]["content_type"] = $this->image_types[$ext];
1392 1392
 						}
1393 1393
 
1394 1394
 						// cid
1395
-						$this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3);	// Force md5 hash (does not contains special chars)
1395
+						$this->html_images[$i]["cid"] = dol_hash(uniqid(time()), 3); // Force md5 hash (does not contains special chars)
1396 1396
 						$this->html = preg_replace("/src=\"$src\"|src='$src'/i", "src=\"cid:".$this->html_images[$i]["cid"]."\"", $this->html);
1397 1397
 					}
1398 1398
 					$i++;
@@ -1403,20 +1403,20 @@  discard block
 block discarded – undo
1403 1403
 			{
1404 1404
 				$inline = array();
1405 1405
 
1406
-				$i=0;
1406
+				$i = 0;
1407 1407
 
1408 1408
 				foreach ($this->html_images as $img)
1409 1409
 				{
1410 1410
 					$fullpath = $images_dir.'/'.$img["name"];
1411 1411
 
1412 1412
 					// If duplicate images are embedded, they may show up as attachments, so remove them.
1413
-					if (!in_array($fullpath,$inline))
1413
+					if (!in_array($fullpath, $inline))
1414 1414
 					{
1415 1415
 						// Read image file
1416 1416
 						if ($image = file_get_contents($fullpath))
1417 1417
 						{
1418 1418
 							// On garde que le nom de l'image
1419
-							preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i',$img["name"],$regs);
1419
+							preg_match('/([A-Za-z0-9_-]+[\.]?[A-Za-z0-9]+)?$/i', $img["name"], $regs);
1420 1420
 							$imgName = $regs[1];
1421 1421
 
1422 1422
 							$this->images_encoded[$i]['name'] = $imgName;
@@ -1457,19 +1457,19 @@  discard block
 block discarded – undo
1457 1457
 	 *										     If format 3: '<[email protected]>' or '"John Doe" <[email protected]>' or '"=?UTF-8?B?Sm9obiBEb2U=?=" <[email protected]>'
1458 1458
 	 *                                           If format 4: 'John Doe' or '[email protected]' if no label exists
1459 1459
 	 */
1460
-	static function getValidAddress($address,$format,$encode=0,$maxnumberofemail=0)
1460
+	static function getValidAddress($address, $format, $encode = 0, $maxnumberofemail = 0)
1461 1461
 	{
1462 1462
 		global $conf;
1463 1463
 
1464
-		$ret='';
1464
+		$ret = '';
1465 1465
 
1466
-		$arrayaddress=explode(',',$address);
1466
+		$arrayaddress = explode(',', $address);
1467 1467
 
1468 1468
 		// Boucle sur chaque composant de l'adresse
1469
-		$i=0;
1470
-		foreach($arrayaddress as $val)
1469
+		$i = 0;
1470
+		foreach ($arrayaddress as $val)
1471 1471
 		{
1472
-			if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1472
+			if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs))
1473 1473
 			{
1474 1474
 				$name  = trim($regs[1]);
1475 1475
 				$email = trim($regs[2]);
@@ -1484,32 +1484,32 @@  discard block
 block discarded – undo
1484 1484
 			{
1485 1485
 				$i++;
1486 1486
 
1487
-				$newemail='';
1487
+				$newemail = '';
1488 1488
 				if ($format == 4)
1489 1489
 				{
1490
-					$newemail = $name?$name:$email;
1490
+					$newemail = $name ? $name : $email;
1491 1491
 				}
1492 1492
 				if ($format == 2)
1493 1493
 				{
1494
-					$newemail=$email;
1494
+					$newemail = $email;
1495 1495
 				}
1496 1496
 				if ($format == 1 || $format == 3)
1497 1497
 				{
1498
-					$newemail='<'.$email.'>';
1498
+					$newemail = '<'.$email.'>';
1499 1499
 				}
1500 1500
 				if ($format == 0 || $format == 3)
1501 1501
 				{
1502
-					if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>';
1503
-					elseif (! $name) $newemail='<'.$email.'>';
1504
-					else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>';
1502
+					if (!empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail = '<'.$email.'>';
1503
+					elseif (!$name) $newemail = '<'.$email.'>';
1504
+					else $newemail = ($format == 3 ? '"' : '').($encode ?self::encodetorfc2822($name) : $name).($format == 3 ? '"' : '').' <'.$email.'>';
1505 1505
 				}
1506 1506
 
1507
-				$ret=($ret ? $ret.',' : '').$newemail;
1507
+				$ret = ($ret ? $ret.',' : '').$newemail;
1508 1508
 
1509 1509
 				// Stop if we have too much records
1510 1510
 				if ($maxnumberofemail && $i >= $maxnumberofemail)
1511 1511
 				{
1512
-					if (count($arrayaddress) > $maxnumberofemail) $ret.='...';
1512
+					if (count($arrayaddress) > $maxnumberofemail) $ret .= '...';
1513 1513
 					break;
1514 1514
 				}
1515 1515
 			}
@@ -1528,14 +1528,14 @@  discard block
 block discarded – undo
1528 1528
 	{
1529 1529
 		global $conf;
1530 1530
 
1531
-		$ret=array();
1531
+		$ret = array();
1532 1532
 
1533
-		$arrayaddress=explode(',',$address);
1533
+		$arrayaddress = explode(',', $address);
1534 1534
 
1535 1535
 		// Boucle sur chaque composant de l'adresse
1536
-		foreach($arrayaddress as $val)
1536
+		foreach ($arrayaddress as $val)
1537 1537
 		{
1538
-			if (preg_match('/^(.*)<(.*)>$/i',trim($val),$regs))
1538
+			if (preg_match('/^(.*)<(.*)>$/i', trim($val), $regs))
1539 1539
 			{
1540 1540
 				$name  = trim($regs[1]);
1541 1541
 				$email = trim($regs[2]);
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
 				$email = trim($val);
1547 1547
 			}
1548 1548
 
1549
-			$ret[$email]=empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)?$name:null;
1549
+			$ret[$email] = empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL) ? $name : null;
1550 1550
 		}
1551 1551
 
1552 1552
 		return $ret;
Please login to merge, or discard this patch.
Braces   +221 added lines, -113 removed lines patch added patch discarded remove patch
@@ -125,7 +125,9 @@  discard block
 block discarded – undo
125 125
 
126 126
 		$this->sendcontext = $sendcontext;
127 127
 
128
-		if (empty($replyto)) $replyto=$from;
128
+		if (empty($replyto)) {
129
+		    $replyto=$from;
130
+		}
129 131
 
130 132
 		// Define this->sendmode
131 133
 		$this->sendmode = '';
@@ -133,8 +135,12 @@  discard block
 block discarded – undo
133 135
 		{
134 136
 			$this->sendmode = $conf->global->MAIN_MAIL_SENDMODE_EMAILING;
135 137
 		}
136
-		if (empty($this->sendmode)) $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE;
137
-		if (empty($this->sendmode)) $this->sendmode='mail';
138
+		if (empty($this->sendmode)) {
139
+		    $this->sendmode=$conf->global->MAIN_MAIL_SENDMODE;
140
+		}
141
+		if (empty($this->sendmode)) {
142
+		    $this->sendmode='mail';
143
+		}
138 144
 
139 145
 		// We define end of line (RFC 821).
140 146
 		$this->eol="\r\n";
@@ -175,9 +181,10 @@  discard block
 block discarded – undo
175 181
 		if ($msgishtml == -1)
176 182
 		{
177 183
 			$this->msgishtml = 0;
178
-			if (dol_textishtml($msg)) $this->msgishtml = 1;
179
-		}
180
-		else
184
+			if (dol_textishtml($msg)) {
185
+			    $this->msgishtml = 1;
186
+			}
187
+		} else
181 188
 		{
182 189
 			$this->msgishtml = $msgishtml;
183 190
 		}
@@ -192,7 +199,10 @@  discard block
 block discarded – undo
192 199
 		// Replace relative /viewimage to absolute path
193 200
 		$msg = preg_replace('/src="'.preg_quote(DOL_URL_ROOT,'/').'\/viewimage\.php/ims', 'src="'.$urlwithroot.'/viewimage.php', $msg, -1, $nbrep);
194 201
 
195
-		if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) $this->msgishtml=1; // To force to send everything with content type html.
202
+		if (! empty($conf->global->MAIN_MAIL_FORCE_CONTENT_TYPE_TO_HTML)) {
203
+		    $this->msgishtml=1;
204
+		}
205
+		// To force to send everything with content type html.
196 206
 
197 207
 		// Detect images
198 208
 		if ($this->msgishtml)
@@ -232,7 +242,9 @@  discard block
 block discarded – undo
232 242
 		}
233 243
 
234 244
 		// Add autocopy to (Note: Adding bcc for specific modules are also done from pages)
235
-		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
245
+		if (! empty($conf->global->MAIN_MAIL_AUTOCOPY_TO)) {
246
+		    $addr_bcc.=($addr_bcc?', ':'').$conf->global->MAIN_MAIL_AUTOCOPY_TO;
247
+		}
236 248
 
237 249
 		// Action according to choosed sending method
238 250
 		if ($this->sendmode == 'mail')
@@ -257,7 +269,10 @@  discard block
 block discarded – undo
257 269
 			$this->trackid = $trackid;
258 270
 
259 271
 			$smtp_headers = $this->write_smtpheaders();
260
-			if (! empty($moreinheader)) $smtp_headers.=$moreinheader;   // $moreinheader contains the \r\n
272
+			if (! empty($moreinheader)) {
273
+			    $smtp_headers.=$moreinheader;
274
+			}
275
+			// $moreinheader contains the \r\n
261 276
 
262 277
 			// Define mime_headers
263 278
 			$mime_headers = $this->write_mimeheaders($filename_list, $mimefilename_list);
@@ -293,8 +308,7 @@  discard block
 block discarded – undo
293 308
 			$this->message = 'This is a message with multiple parts in MIME format.'.$this->eol;
294 309
 			$this->message.= $text_body . $files_encoded;
295 310
 			$this->message.= "--" . $this->mixed_boundary . "--" . $this->eol;
296
-		}
297
-		else if ($this->sendmode == 'smtps')
311
+		} else if ($this->sendmode == 'smtps')
298 312
 		{
299 313
 			// Use SMTPS library
300 314
 			// ------------------------------------------
@@ -309,7 +323,9 @@  discard block
 block discarded – undo
309 323
 			$smtps->setTrackId($trackid);
310 324
 			$smtps->setReplyTo($this->getValidAddress($replyto,0,1));
311 325
 
312
-			if (! empty($moreinheader)) $smtps->setMoreInHeader($moreinheader);
326
+			if (! empty($moreinheader)) {
327
+			    $smtps->setMoreInHeader($moreinheader);
328
+			}
313 329
 
314 330
 			if (! empty($this->html))
315 331
 			{
@@ -322,8 +338,11 @@  discard block
 block discarded – undo
322 338
 				$msg = $this->checkIfHTML($msg);
323 339
 			}
324 340
 
325
-			if ($this->msgishtml) $smtps->setBodyContent($msg,'html');
326
-			else $smtps->setBodyContent($msg,'plain');
341
+			if ($this->msgishtml) {
342
+			    $smtps->setBodyContent($msg,'html');
343
+			} else {
344
+			    $smtps->setBodyContent($msg,'plain');
345
+			}
327 346
 
328 347
 			if ($this->atleastoneimage)
329 348
 			{
@@ -348,8 +367,7 @@  discard block
 block discarded – undo
348 367
 			$smtps->setDeliveryReceipt($deliveryreceipt);
349 368
 
350 369
 			$this->smtps=$smtps;
351
-		}
352
-		else if ($this->sendmode == 'swiftmailer')
370
+		} else if ($this->sendmode == 'swiftmailer')
353 371
 		{
354 372
 			// Use Swift Mailer library
355 373
 			// ------------------------------------------
@@ -474,12 +492,17 @@  discard block
 block discarded – undo
474 492
 				}
475 493
 			}
476 494
 
477
-			if (! empty($addr_cc)) $this->message->setCc($this->getArrayAddress($addr_cc));
478
-			if (! empty($addr_bcc)) $this->message->setBcc($this->getArrayAddress($addr_bcc));
495
+			if (! empty($addr_cc)) {
496
+			    $this->message->setCc($this->getArrayAddress($addr_cc));
497
+			}
498
+			if (! empty($addr_bcc)) {
499
+			    $this->message->setBcc($this->getArrayAddress($addr_bcc));
500
+			}
479 501
 			//if (! empty($errors_to)) $this->message->setErrorsTo($this->getArrayAddress($errors_to);
480
-			if (isset($deliveryreceipt) && $deliveryreceipt == 1) $this->message->setReadReceiptTo($this->getArrayAddress($from));
481
-		}
482
-		else
502
+			if (isset($deliveryreceipt) && $deliveryreceipt == 1) {
503
+			    $this->message->setReadReceiptTo($this->getArrayAddress($from));
504
+			}
505
+		} else
483 506
 		{
484 507
 			// Send mail method not correctly defined
485 508
 			// --------------------------------------
@@ -517,13 +540,17 @@  discard block
 block discarded – undo
517 540
 
518 541
 				return $reshook;
519 542
 			}
520
-			if ($reshook == 1)	// Hook replace standard code
543
+			if ($reshook == 1) {
544
+			    // Hook replace standard code
521 545
 			{
522 546
 				return true;
523 547
 			}
548
+			}
524 549
 
525 550
 			// Check number of recipient is lower or equal than MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL
526
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10;
551
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)) {
552
+			    $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL=10;
553
+			}
527 554
 			$tmparray1 = explode(',', $this->addr_to);
528 555
 			if (count($tmparray1) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_TO_IN_SAME_EMAIL)
529 556
 			{
@@ -531,7 +558,9 @@  discard block
 block discarded – undo
531 558
 				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
532 559
 				return false;
533 560
 			}
534
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10;
561
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)) {
562
+			    $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL=10;
563
+			}
535 564
 			$tmparray2 = explode(',', $this->addr_cc);
536 565
 			if (count($tmparray2) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_CC_IN_SAME_EMAIL)
537 566
 			{
@@ -539,7 +568,9 @@  discard block
 block discarded – undo
539 568
 				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
540 569
 				return false;
541 570
 			}
542
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10;
571
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)) {
572
+			    $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL=10;
573
+			}
543 574
 			$tmparray3 = explode(',', $this->addr_bcc);
544 575
 			if (count($tmparray3) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_BCC_IN_SAME_EMAIL)
545 576
 			{
@@ -547,7 +578,9 @@  discard block
 block discarded – undo
547 578
 				dol_syslog("CMailFile::sendfile: mail end error=" . $this->error, LOG_WARNING);
548 579
 				return false;
549 580
 			}
550
-			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10;
581
+			if (empty($conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)) {
582
+			    $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL=10;
583
+			}
551 584
 			if ((count($tmparray1)+count($tmparray2)+count($tmparray3)) > $conf->global->MAIL_MAX_NB_OF_RECIPIENTS_IN_SAME_EMAIL)
552 585
 			{
553 586
 				$this->error = 'Too much recipients in to:, cc:, bcc:';
@@ -590,13 +623,19 @@  discard block
 block discarded – undo
590 623
 				// If Windows, sendmail_from must be defined
591 624
 				if (isset($_SERVER["WINDIR"]))
592 625
 				{
593
-					if (empty($this->addr_from)) $this->addr_from = '[email protected]';
626
+					if (empty($this->addr_from)) {
627
+					    $this->addr_from = '[email protected]';
628
+					}
594 629
 					@ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2));
595 630
 				}
596 631
 
597 632
 				// Force parameters
598
-				if (! empty($conf->global->$keyforsmtpserver)) ini_set('SMTP',$conf->global->$keyforsmtpserver);
599
-				if (! empty($conf->global->$keyforsmtpport))   ini_set('smtp_port',$conf->global->$keyforsmtpport);
633
+				if (! empty($conf->global->$keyforsmtpserver)) {
634
+				    ini_set('SMTP',$conf->global->$keyforsmtpserver);
635
+				}
636
+				if (! empty($conf->global->$keyforsmtpport)) {
637
+				    ini_set('smtp_port',$conf->global->$keyforsmtpport);
638
+				}
600 639
 
601 640
 				$res=true;
602 641
 				if ($res && ! $this->subject)
@@ -624,29 +663,43 @@  discard block
 block discarded – undo
624 663
 						// Having this variable not defined may create problems with some other sendmail (option -f required)
625 664
 						$additionnalparam .= ($additionnalparam?' ':'').(! empty($conf->global->MAIN_MAIL_ERRORS_TO) ? '-f' . $this->getValidAddress($conf->global->MAIN_MAIL_ERRORS_TO,2) : ($this->addr_from != '' ? '-f' . $this->getValidAddress($this->addr_from,2) : '') );
626 665
 					}
627
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA))    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
666
+					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_BA)) {
667
+					    // To force usage of -ba option. This option tells sendmail to read From: or Sender: to setup sender
628 668
 					{
629 669
 						$additionnalparam .= ($additionnalparam?' ':'').'-ba';
630 670
 					}
671
+					}
631 672
 
632
-					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam; // Use -U to add additionnal params
673
+					if (! empty($conf->global->MAIN_MAIL_SENDMAIL_FORCE_ADDPARAM)) {
674
+					    $additionnalparam .= ($additionnalparam?' ':'').'-U '.$additionnalparam;
675
+					}
676
+					// Use -U to add additionnal params
633 677
 
634 678
 					dol_syslog("CMailFile::sendfile: mail start HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port').", additionnal_parameters=".$additionnalparam, LOG_DEBUG);
635 679
 
636 680
 					$this->message=stripslashes($this->message);
637 681
 
638
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
682
+					if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
683
+					    $this->dump_mail();
684
+					}
639 685
 
640
-					if (! empty($additionnalparam)) $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
641
-					else $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers);
686
+					if (! empty($additionnalparam)) {
687
+					    $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers, $additionnalparam);
688
+					} else {
689
+					    $res = mail($dest, $this->encodetorfc2822($this->subject), $this->message, $this->headers);
690
+					}
642 691
 
643 692
 					if (! $res)
644 693
 					{
645 694
 						$langs->load("errors");
646 695
 						$this->error="Failed to send mail with php mail";
647 696
 						$linuxlike=1;
648
-						if (preg_match('/^win/i',PHP_OS)) $linuxlike=0;
649
-						if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0;
697
+						if (preg_match('/^win/i',PHP_OS)) {
698
+						    $linuxlike=0;
699
+						}
700
+						if (preg_match('/^mac/i',PHP_OS)) {
701
+						    $linuxlike=0;
702
+						}
650 703
 						if (! $linuxlike)
651 704
 						{
652 705
 							$this->error.=" to HOST=".ini_get('SMTP').", PORT=".ini_get('smtp_port');	// This values are value used only for non linuxlike systems
@@ -654,8 +707,7 @@  discard block
 block discarded – undo
654 707
 						$this->error.=".<br>";
655 708
 						$this->error.=$langs->trans("ErrorPhpMailDelivery");
656 709
 						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
657
-					}
658
-					else
710
+					} else
659 711
 					{
660 712
 						dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
661 713
 					}
@@ -667,10 +719,13 @@  discard block
 block discarded – undo
667 719
 				}
668 720
 
669 721
 				// Restore parameters
670
-				if (! empty($conf->global->$keyforsmtpserver))	ini_restore('SMTP');
671
-				if (! empty($conf->global->$keyforsmtpport)) 	ini_restore('smtp_port');
672
-			}
673
-			else if ($this->sendmode == 'smtps')
722
+				if (! empty($conf->global->$keyforsmtpserver)) {
723
+				    ini_restore('SMTP');
724
+				}
725
+				if (! empty($conf->global->$keyforsmtpport)) {
726
+				    ini_restore('smtp_port');
727
+				}
728
+			} else if ($this->sendmode == 'smtps')
674 729
 			{
675 730
 				if (! is_object($this->smtps))
676 731
 				{
@@ -684,14 +739,22 @@  discard block
 block discarded – undo
684 739
 				$this->smtps->setTransportType(0);	// Only this method is coded in SMTPs library
685 740
 
686 741
 				// Clean parameters
687
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
688
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
742
+				if (empty($conf->global->$keyforsmtpserver)) {
743
+				    $conf->global->$keyforsmtpserver=ini_get('SMTP');
744
+				}
745
+				if (empty($conf->global->$keyforsmtpport)) {
746
+				    $conf->global->$keyforsmtpport=ini_get('smtp_port');
747
+				}
689 748
 
690 749
 				// If we use SSL/TLS
691 750
 				$server=$conf->global->$keyforsmtpserver;
692 751
 				$secure='';
693
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
694
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
752
+				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) {
753
+				    $secure='ssl';
754
+				}
755
+				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) {
756
+				    $secure='tls';
757
+				}
695 758
 				$server=($secure?$secure.'://':'').$server;
696 759
 
697 760
 				$port=$conf->global->$keyforsmtpport;
@@ -729,47 +792,63 @@  discard block
 block discarded – undo
729 792
 
730 793
 				if ($res)
731 794
 				{
732
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->smtps->setDebug(true);
795
+					if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
796
+					    $this->smtps->setDebug(true);
797
+					}
733 798
 
734 799
 					$result=$this->smtps->sendMsg();
735 800
 					//print $result;
736 801
 
737
-					if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
802
+					if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
803
+					    $this->dump_mail();
804
+					}
738 805
 
739 806
 					$result=$this->smtps->getErrors();
740 807
 					if (empty($this->error) && empty($result))
741 808
 					{
742 809
 						dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
743 810
 						$res=true;
744
-					}
745
-					else
811
+					} else
746 812
 					{
747
-						if (empty($this->error)) $this->error=$result;
813
+						if (empty($this->error)) {
814
+						    $this->error=$result;
815
+						}
748 816
 						dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
749 817
 						$res=false;
750 818
 					}
751 819
 				}
752
-			}
753
-			else if ($this->sendmode == 'swiftmailer')
820
+			} else if ($this->sendmode == 'swiftmailer')
754 821
 			{
755 822
 				// Use Swift Mailer library
756 823
 				// ------------------------------------------
757 824
 				require_once DOL_DOCUMENT_ROOT.'/includes/swiftmailer/lib/swift_required.php';
758 825
 
759 826
 				// Clean parameters
760
-				if (empty($conf->global->$keyforsmtpserver)) $conf->global->$keyforsmtpserver=ini_get('SMTP');
761
-				if (empty($conf->global->$keyforsmtpport))   $conf->global->$keyforsmtpport=ini_get('smtp_port');
827
+				if (empty($conf->global->$keyforsmtpserver)) {
828
+				    $conf->global->$keyforsmtpserver=ini_get('SMTP');
829
+				}
830
+				if (empty($conf->global->$keyforsmtpport)) {
831
+				    $conf->global->$keyforsmtpport=ini_get('smtp_port');
832
+				}
762 833
 
763 834
 				// If we use SSL/TLS
764 835
 				$server = $conf->global->$keyforsmtpserver;
765 836
 				$secure = '';
766
-				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $secure='ssl';
767
-				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) $secure='tls';
837
+				if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) {
838
+				    $secure='ssl';
839
+				}
840
+				if (! empty($conf->global->$keyforstarttls) && function_exists('openssl_open')) {
841
+				    $secure='tls';
842
+				}
768 843
 
769 844
 				$this->transport = new Swift_SmtpTransport($server, $conf->global->$keyforsmtpport, $secure);
770 845
 
771
-				if (! empty($conf->global->$keyforsmtpid)) $this->transport->setUsername($conf->global->$keyforsmtpid);
772
-				if (! empty($conf->global->$keyforsmtppw)) $this->transport->setPassword($conf->global->$keyforsmtppw);
846
+				if (! empty($conf->global->$keyforsmtpid)) {
847
+				    $this->transport->setUsername($conf->global->$keyforsmtpid);
848
+				}
849
+				if (! empty($conf->global->$keyforsmtppw)) {
850
+				    $this->transport->setPassword($conf->global->$keyforsmtppw);
851
+				}
773 852
 				//$smtps->_msgReplyTo  = '[email protected]';
774 853
 
775 854
 				// Create the Mailer using your created Transport
@@ -797,19 +876,19 @@  discard block
 block discarded – undo
797 876
 				} catch (Exception $e) {
798 877
 					$this->error =  $e->getMessage();
799 878
 				}
800
-				if (! empty($conf->global->MAIN_MAIL_DEBUG)) $this->dump_mail();
879
+				if (! empty($conf->global->MAIN_MAIL_DEBUG)) {
880
+				    $this->dump_mail();
881
+				}
801 882
 
802 883
 				$res = true;
803 884
 				if (! empty($this->error) || ! $result) {
804 885
 					dol_syslog("CMailFile::sendfile: mail end error=".$this->error, LOG_ERR);
805 886
 					$res=false;
806
-				}
807
-				else
887
+				} else
808 888
 				{
809 889
 					dol_syslog("CMailFile::sendfile: mail end success", LOG_DEBUG);
810 890
 				}
811
-			}
812
-			else
891
+			} else
813 892
 			{
814 893
 				// Send mail method not correctly defined
815 894
 				// --------------------------------------
@@ -826,8 +905,7 @@  discard block
 block discarded – undo
826 905
 
827 906
 				return $reshook;
828 907
 			}
829
-		}
830
-		else
908
+		} else
831 909
 		{
832 910
 			$this->error='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
833 911
 			dol_syslog("CMailFile::sendfile: ".$this->error, LOG_WARNING);
@@ -867,8 +945,7 @@  discard block
 block discarded – undo
867 945
 			$contents = file_get_contents($newsourcefile);	// Need PHP 4.3
868 946
 			$encoded = chunk_split(base64_encode($contents), 76, $this->eol);    // 76 max is defined into http://tools.ietf.org/html/rfc2047
869 947
 			return $encoded;
870
-		}
871
-		else
948
+		} else
872 949
 		{
873 950
 			$this->error="Error: Can't read file '".$sourcefile."' into _encode_file";
874 951
 			dol_syslog("CMailFile::encode_file: ".$this->error, LOG_ERR);
@@ -890,9 +967,11 @@  discard block
 block discarded – undo
890 967
         // phpcs:enable
891 968
 		global $conf,$dolibarr_main_data_root;
892 969
 
893
-		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
970
+		if (@is_writeable($dolibarr_main_data_root)) {
971
+		    // Avoid fatal error on fopen with open_basedir
894 972
 		{
895 973
 			$outputfile=$dolibarr_main_data_root."/dolibarr_mail.log";
974
+		}
896 975
 			$fp = fopen($outputfile,"w");
897 976
 
898 977
 			if ($this->sendmode == 'mail')
@@ -900,19 +979,18 @@  discard block
 block discarded – undo
900 979
 				fputs($fp, $this->headers);
901 980
 				fputs($fp, $this->eol);			// This eol is added by the mail function, so we add it in log
902 981
 				fputs($fp, $this->message);
903
-			}
904
-			elseif ($this->sendmode == 'smtps')
982
+			} elseif ($this->sendmode == 'smtps')
905 983
 			{
906 984
 				fputs($fp, $this->smtps->log);	// this->smtps->log is filled only if MAIN_MAIL_DEBUG was set to on
907
-			}
908
-			elseif ($this->sendmode == 'swiftmailer')
985
+			} elseif ($this->sendmode == 'swiftmailer')
909 986
 			{
910 987
 				fputs($fp, $this->logger->dump());	// this->logger is filled only if MAIN_MAIL_DEBUG was set to on
911 988
 			}
912 989
 
913 990
 			fclose($fp);
914
-			if (! empty($conf->global->MAIN_UMASK))
915
-				@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
991
+			if (! empty($conf->global->MAIN_UMASK)) {
992
+							@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
993
+			}
916 994
 		}
917 995
 	}
918 996
 
@@ -928,14 +1006,17 @@  discard block
 block discarded – undo
928 1006
 		if (!preg_match('/^[\s\t]*<html/i',$msg))
929 1007
 		{
930 1008
 			$out = "<html><head><title></title>";
931
-			if (!empty($this->styleCSS)) $out.= $this->styleCSS;
1009
+			if (!empty($this->styleCSS)) {
1010
+			    $out.= $this->styleCSS;
1011
+			}
932 1012
 			$out.= "</head><body";
933
-			if (!empty($this->bodyCSS)) $out.= $this->bodyCSS;
1013
+			if (!empty($this->bodyCSS)) {
1014
+			    $out.= $this->bodyCSS;
1015
+			}
934 1016
 			$out.= ">";
935 1017
 			$out.= $msg;
936 1018
 			$out.= "</body></html>";
937
-		}
938
-		else
1019
+		} else
939 1020
 		{
940 1021
 			$out = $msg;
941 1022
 		}
@@ -995,15 +1076,26 @@  discard block
 block discarded – undo
995 1076
 		}
996 1077
 		// Return-Path is important because it is used by SPF. Some MTA does not read Return-Path from header but from command line. See option MAIN_MAIL_ALLOW_SENDMAIL_F for that.
997 1078
 		$out.= "Return-Path: ".$this->getValidAddress($this->addr_from,0,1).$this->eol2;
998
-		if (isset($this->reply_to)  && $this->reply_to)  $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2;
999
-		if (isset($this->errors_to) && $this->errors_to) $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2;
1079
+		if (isset($this->reply_to)  && $this->reply_to) {
1080
+		    $out.= "Reply-To: ".$this->getValidAddress($this->reply_to,2).$this->eol2;
1081
+		}
1082
+		if (isset($this->errors_to) && $this->errors_to) {
1083
+		    $out.= "Errors-To: ".$this->getValidAddress($this->errors_to,2).$this->eol2;
1084
+		}
1000 1085
 
1001 1086
 		// Receiver
1002
-		if (isset($this->addr_cc)   && $this->addr_cc)   $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2;
1003
-		if (isset($this->addr_bcc)  && $this->addr_bcc)  $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2;    // TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1087
+		if (isset($this->addr_cc)   && $this->addr_cc) {
1088
+		    $out.= "Cc: ".$this->getValidAddress($this->addr_cc,2).$this->eol2;
1089
+		}
1090
+		if (isset($this->addr_bcc)  && $this->addr_bcc) {
1091
+		    $out.= "Bcc: ".$this->getValidAddress($this->addr_bcc,2).$this->eol2;
1092
+		}
1093
+		// TODO Question: bcc must not be into header, only into SMTP command "RCPT TO". Does php mail support this ?
1004 1094
 
1005 1095
 		// Delivery receipt
1006
-		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2;
1096
+		if (isset($this->deliveryreceipt) && $this->deliveryreceipt == 1) {
1097
+		    $out.= "Disposition-Notification-To: ".$this->getValidAddress($this->addr_from,2).$this->eol2;
1098
+		}
1007 1099
 
1008 1100
 		//$out.= "X-Priority: 3".$this->eol2;
1009 1101
 
@@ -1016,13 +1108,14 @@  discard block
 block discarded – undo
1016 1108
 			$out.= 'Message-ID: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;	// Uppercase seems replaced by phpmail
1017 1109
 			$out.= 'References: <' . time() . '.phpmail-dolibarr-'. $trackid . '@' . $host . ">" . $this->eol2;
1018 1110
 			$out.= 'X-Dolibarr-TRACKID: ' . $trackid . '@' . $host. $this->eol2;
1019
-		}
1020
-		else
1111
+		} else
1021 1112
 		{
1022 1113
 			$out.= 'Message-ID: <' . time() . '.phpmail@' . $host . ">" . $this->eol2;
1023 1114
 		}
1024 1115
 
1025
-		if (! empty($_SERVER['REMOTE_ADDR'])) $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2;
1116
+		if (! empty($_SERVER['REMOTE_ADDR'])) {
1117
+		    $out.= "X-RemoteAddr: " . $_SERVER['REMOTE_ADDR']. $this->eol2;
1118
+		}
1026 1119
 		$out.= "X-Mailer: Dolibarr version " . DOL_VERSION ." (using php mail)".$this->eol2;
1027 1120
 		$out.= "Mime-Version: 1.0".$this->eol2;
1028 1121
 
@@ -1057,7 +1150,9 @@  discard block
 block discarded – undo
1057 1150
 			{
1058 1151
 				if ($filename_list[$i])
1059 1152
 				{
1060
-					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1153
+					if ($mimefilename_list[$i]) {
1154
+					    $filename_list[$i] = $mimefilename_list[$i];
1155
+					}
1061 1156
 					$out.= "X-attachments: $filename_list[$i]".$this->eol2;
1062 1157
 				}
1063 1158
 			}
@@ -1127,9 +1222,11 @@  discard block
 block discarded – undo
1127 1222
 				$out.= "--" . $this->related_boundary . $this->eol;
1128 1223
 			}
1129 1224
 
1130
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part before html part
1225
+			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1226
+			    // Add plain text message part before html part
1131 1227
 			{
1132 1228
 				$out.= "Content-Type: multipart/alternative;".$this->eol." boundary=\"".$this->alternative_boundary."\"".$this->eol;
1229
+			}
1133 1230
 				$out.= $this->eol;
1134 1231
 				$out.= "--" . $this->alternative_boundary . $this->eol;
1135 1232
 				$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
@@ -1142,12 +1239,13 @@  discard block
 block discarded – undo
1142 1239
 			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;	// TODO Use base64
1143 1240
 			$out.= $this->eol.$strContent.$this->eol;
1144 1241
 
1145
-			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART))    // Add plain text message part after html part
1242
+			if (! $this->atleastoneimage && $strContentAltText && ! empty($conf->global->MAIN_MAIL_USE_MULTI_PART)) {
1243
+			    // Add plain text message part after html part
1146 1244
 			{
1147 1245
 				$out.= "--" . $this->alternative_boundary . "--". $this->eol;
1148 1246
 			}
1149
-		}
1150
-		else
1247
+			}
1248
+		} else
1151 1249
 		{
1152 1250
 			$out.= "Content-Type: text/plain; charset=".$conf->file->character_set_client.$this->eol;
1153 1251
 			//$out.= "Content-Transfer-Encoding: 7bit".$this->eol;
@@ -1192,7 +1290,9 @@  discard block
 block discarded – undo
1192 1290
 				$encoded = $this->_encode_file($filename_list[$i]);
1193 1291
 				if ($encoded >= 0)
1194 1292
 				{
1195
-					if ($mimefilename_list[$i]) $filename_list[$i] = $mimefilename_list[$i];
1293
+					if ($mimefilename_list[$i]) {
1294
+					    $filename_list[$i] = $mimefilename_list[$i];
1295
+					}
1196 1296
 					if (! $mimetype_list[$i]) {
1197 1297
 						$mimetype_list[$i] = "application/octet-stream";
1198 1298
 					}
@@ -1206,8 +1306,7 @@  discard block
 block discarded – undo
1206 1306
 					$out.= $encoded;
1207 1307
 					$out.= $this->eol;
1208 1308
 					//$out.= $this->eol;
1209
-				}
1210
-				else
1309
+				} else
1211 1310
 				{
1212 1311
 					return $encoded;
1213 1312
 				}
@@ -1286,7 +1385,9 @@  discard block
 block discarded – undo
1286 1385
 			}
1287 1386
 
1288 1387
 			// If we use SSL/TLS
1289
-			if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) $host='ssl://'.$host;
1388
+			if (! empty($conf->global->$keyfortls) && function_exists('openssl_open')) {
1389
+			    $host='ssl://'.$host;
1390
+			}
1290 1391
 			// tls smtp start with no encryption
1291 1392
 			//if (! empty($conf->global->MAIN_MAIL_EMAIL_STARTTLS) && function_exists('openssl_open')) $host='tls://'.$host;
1292 1393
 
@@ -1298,17 +1399,20 @@  discard block
 block discarded – undo
1298 1399
 					$errno,      // actual system level error
1299 1400
 					$errstr,     // and any text that goes with the error
1300 1401
 					$timeout
1301
-			))  // timeout for reading/writing data over the socket
1402
+			)) {
1403
+			    // timeout for reading/writing data over the socket
1302 1404
 			{
1303 1405
 				// Windows still does not have support for this timeout function
1304 1406
 				if (function_exists('stream_set_timeout')) stream_set_timeout($socket, $timeout, 0);
1407
+			}
1305 1408
 
1306 1409
 				dol_syslog("Now we wait for answer 220");
1307 1410
 
1308 1411
 				// Check response from Server
1309
-				if ( $_retVal = $this->server_parse($socket, "220") ) $_retVal = $socket;
1310
-			}
1311
-			else
1412
+				if ( $_retVal = $this->server_parse($socket, "220") ) {
1413
+				    $_retVal = $socket;
1414
+				}
1415
+			} else
1312 1416
 			{
1313 1417
 				$this->error = utf8_check('Error '.$errno.' - '.$errstr)?'Error '.$errno.' - '.$errstr:utf8_encode('Error '.$errno.' - '.$errstr);
1314 1418
 			}
@@ -1369,9 +1473,11 @@  discard block
 block discarded – undo
1369 1473
 			foreach ($matches[1] as $full)
1370 1474
 			{
1371 1475
 
1372
-				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs))   // If xxx is 'file=aaa'
1476
+				if (preg_match('/file=([A-Za-z0-9_\-\/]+[\.]?[A-Za-z0-9]+)?$/i',$full,$regs)) {
1477
+				    // If xxx is 'file=aaa'
1373 1478
 				{
1374 1479
 					$img = $regs[1];
1480
+				}
1375 1481
 
1376 1482
 					if (file_exists($images_dir.'/'.$img))
1377 1483
 					{
@@ -1430,15 +1536,13 @@  discard block
 block discarded – undo
1430 1536
 					}
1431 1537
 					$i++;
1432 1538
 				}
1433
-			}
1434
-			else
1539
+			} else
1435 1540
 			{
1436 1541
 				return -1;
1437 1542
 			}
1438 1543
 
1439 1544
 			return 1;
1440
-		}
1441
-		else
1545
+		} else
1442 1546
 		{
1443 1547
 			return 0;
1444 1548
 		}
@@ -1473,8 +1577,7 @@  discard block
 block discarded – undo
1473 1577
 			{
1474 1578
 				$name  = trim($regs[1]);
1475 1579
 				$email = trim($regs[2]);
1476
-			}
1477
-			else
1580
+			} else
1478 1581
 			{
1479 1582
 				$name  = '';
1480 1583
 				$email = trim($val);
@@ -1499,9 +1602,13 @@  discard block
 block discarded – undo
1499 1602
 				}
1500 1603
 				if ($format == 0 || $format == 3)
1501 1604
 				{
1502
-					if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) $newemail='<'.$email.'>';
1503
-					elseif (! $name) $newemail='<'.$email.'>';
1504
-					else $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>';
1605
+					if (! empty($conf->global->MAIN_MAIL_NO_FULL_EMAIL)) {
1606
+					    $newemail='<'.$email.'>';
1607
+					} elseif (! $name) {
1608
+					    $newemail='<'.$email.'>';
1609
+					} else {
1610
+					    $newemail=($format==3?'"':'').($encode?self::encodetorfc2822($name):$name).($format==3?'"':'').' <'.$email.'>';
1611
+					}
1505 1612
 				}
1506 1613
 
1507 1614
 				$ret=($ret ? $ret.',' : '').$newemail;
@@ -1509,7 +1616,9 @@  discard block
 block discarded – undo
1509 1616
 				// Stop if we have too much records
1510 1617
 				if ($maxnumberofemail && $i >= $maxnumberofemail)
1511 1618
 				{
1512
-					if (count($arrayaddress) > $maxnumberofemail) $ret.='...';
1619
+					if (count($arrayaddress) > $maxnumberofemail) {
1620
+					    $ret.='...';
1621
+					}
1513 1622
 					break;
1514 1623
 				}
1515 1624
 			}
@@ -1539,8 +1648,7 @@  discard block
 block discarded – undo
1539 1648
 			{
1540 1649
 				$name  = trim($regs[1]);
1541 1650
 				$email = trim($regs[2]);
1542
-			}
1543
-			else
1651
+			} else
1544 1652
 			{
1545 1653
 				$name  = null;
1546 1654
 				$email = trim($val);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/html.formbarcode.class.php 2 patches
Spacing   +31 added lines, -31 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
     /**
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      *  @param  int		$idForm			Id du formulaire
61 61
      * 	@return	string					HTML select string
62 62
      */
63
-    function setBarcodeEncoder($selected,$barcodelist,$code_id,$idForm='formbarcode')
63
+    function setBarcodeEncoder($selected, $barcodelist, $code_id, $idForm = 'formbarcode')
64 64
     {
65 65
         global $conf, $langs;
66 66
 
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
         }
82 82
 
83 83
         // We check if barcode is already selected by default
84
-        if (((! empty($conf->product->enabled) || ! empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) ||
85
-        (! empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id))
84
+        if (((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && $conf->global->PRODUIT_DEFAULT_BARCODE_TYPE == $code_id) ||
85
+        (!empty($conf->societe->enabled) && $conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY == $code_id))
86 86
         {
87 87
             $disable = 'disabled';
88 88
         }
@@ -90,24 +90,24 @@  discard block
 block discarded – undo
90 90
         if (!empty($conf->use_javascript_ajax))
91 91
         {
92 92
             $select_encoder = '<form action="'.DOL_URL_ROOT.'/admin/barcode.php" method="POST" id="form'.$idForm.'">';
93
-            $select_encoder.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
94
-            $select_encoder.= '<input type="hidden" name="action" value="update">';
95
-            $select_encoder.= '<input type="hidden" name="code_id" value="'.$code_id.'">';
93
+            $select_encoder .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
94
+            $select_encoder .= '<input type="hidden" name="action" value="update">';
95
+            $select_encoder .= '<input type="hidden" name="code_id" value="'.$code_id.'">';
96 96
         }
97 97
         
98
-        $selectname=(!empty($conf->use_javascript_ajax)?'coder':'coder'.$code_id);
99
-        $select_encoder.= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">';
100
-        $select_encoder.= '<option value="0"'.($selected==0?' selected':'').' '.$disable.'>'.$langs->trans('Disable').'</option>';
101
-        $select_encoder.= '<option value="-1" disabled>--------------------</option>';
102
-        foreach($barcodelist as $key => $value)
98
+        $selectname = (!empty($conf->use_javascript_ajax) ? 'coder' : 'coder'.$code_id);
99
+        $select_encoder .= '<select id="select'.$idForm.'" class="flat" name="'.$selectname.'">';
100
+        $select_encoder .= '<option value="0"'.($selected == 0 ? ' selected' : '').' '.$disable.'>'.$langs->trans('Disable').'</option>';
101
+        $select_encoder .= '<option value="-1" disabled>--------------------</option>';
102
+        foreach ($barcodelist as $key => $value)
103 103
         {
104
-            $select_encoder.= '<option value="'.$key.'"'.($selected==$key?' selected':'').'>'.$value.'</option>';
104
+            $select_encoder .= '<option value="'.$key.'"'.($selected == $key ? ' selected' : '').'>'.$value.'</option>';
105 105
         }
106
-        $select_encoder.= '</select>';
106
+        $select_encoder .= '</select>';
107 107
         
108 108
         if (!empty($conf->use_javascript_ajax))
109 109
         {
110
-            $select_encoder.= '</form>';
110
+            $select_encoder .= '</form>';
111 111
         }
112 112
 
113 113
         return $select_encoder;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
      *  @return void
124 124
      *  @deprecated
125 125
      */
126
-    function select_barcode_type($selected='', $htmlname='barcodetype_id', $useempty=0)
126
+    function select_barcode_type($selected = '', $htmlname = 'barcodetype_id', $useempty = 0)
127 127
     {
128 128
         // phpcs:enable
129 129
         print $this->selectBarcodeType($selected, $htmlname, $useempty);
@@ -137,17 +137,17 @@  discard block
 block discarded – undo
137 137
      *  @param  int     $useempty          Display empty value in select
138 138
      *  @return string
139 139
      */
140
-    function selectBarcodeType($selected='', $htmlname='barcodetype_id', $useempty=0)
140
+    function selectBarcodeType($selected = '', $htmlname = 'barcodetype_id', $useempty = 0)
141 141
     {
142 142
         global $langs, $conf;
143 143
 
144 144
         $out = '';
145 145
 
146 146
         $sql = "SELECT rowid, code, libelle";
147
-        $sql.= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
148
-        $sql.= " WHERE coder <> '0'";
149
-        $sql.= " AND entity = ".$conf->entity;
150
-        $sql.= " ORDER BY code";
147
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type";
148
+        $sql .= " WHERE coder <> '0'";
149
+        $sql .= " AND entity = ".$conf->entity;
150
+        $sql .= " ORDER BY code";
151 151
 
152 152
         $result = $this->db->query($sql);
153 153
         if ($result) {
@@ -155,20 +155,20 @@  discard block
 block discarded – undo
155 155
             $i = 0;
156 156
 
157 157
             if ($useempty && $num > 0) {
158
-                $out .= '<select class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
158
+                $out .= '<select class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">';
159 159
                 $out .= '<option value="0">&nbsp;</option>';
160 160
             } else {
161 161
                 $langs->load("errors");
162
-                $out .= '<select disabled class="flat minwidth75imp" name="' . $htmlname . '" id="select_' . $htmlname . '">';
163
-                $out .= '<option value="0" selected>' . $langs->trans('ErrorNoActivatedBarcode') . '</option>';
162
+                $out .= '<select disabled class="flat minwidth75imp" name="'.$htmlname.'" id="select_'.$htmlname.'">';
163
+                $out .= '<option value="0" selected>'.$langs->trans('ErrorNoActivatedBarcode').'</option>';
164 164
             }
165 165
 
166 166
             while ($i < $num) {
167 167
                 $obj = $this->db->fetch_object($result);
168 168
                 if ($selected == $obj->rowid) {
169
-                    $out .= '<option value="' . $obj->rowid . '" selected>';
169
+                    $out .= '<option value="'.$obj->rowid.'" selected>';
170 170
                 } else {
171
-                    $out .= '<option value="' . $obj->rowid . '">';
171
+                    $out .= '<option value="'.$obj->rowid.'">';
172 172
                 }
173 173
                 $out .= $obj->libelle;
174 174
                 $out .= '</option>';
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
      *  @return	void
194 194
      *  @deprecated
195 195
      */
196
-    function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
196
+    function form_barcode_type($page, $selected = '', $htmlname = 'barcodetype_id')
197 197
     {
198 198
         // phpcs:enable
199 199
         print $this->formBarcodeType($page, $selected, $htmlname);
@@ -207,19 +207,19 @@  discard block
 block discarded – undo
207 207
      *  @param  string      $htmlname       Nom du formulaire select
208 208
      *  @return string
209 209
      */
210
-    function formBarcodeType($page, $selected='', $htmlname='barcodetype_id')
210
+    function formBarcodeType($page, $selected = '', $htmlname = 'barcodetype_id')
211 211
     {
212 212
         global $langs, $conf;
213 213
         $out = '';
214 214
         if ($htmlname != "none") {
215
-            $out .= '<form method="post" action="' . $page . '">';
216
-            $out .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
215
+            $out .= '<form method="post" action="'.$page.'">';
216
+            $out .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
217 217
             $out .= '<input type="hidden" name="action" value="set'.$htmlname.'">';
218 218
             $out .= '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
219 219
             $out .= '<tr><td>';
220 220
             $out .= $this->selectBarcodeType($selected, $htmlname, 1);
221 221
             $out .= '</td>';
222
-            $out .= '<td align="left"><input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
222
+            $out .= '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'">';
223 223
             $out .= '</td></tr></table></form>';
224 224
         }
225 225
         return $out;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -176,8 +176,7 @@
 block discarded – undo
176 176
             }
177 177
             $out .= "</select>";
178 178
             $out .= ajax_combobox("select_".$htmlname);
179
-        }
180
-        else {
179
+        } else {
181 180
             dol_print_error($this->db);
182 181
         }
183 182
         return $out;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/class/CSMSFile.class.php 3 patches
Indentation   +162 added lines, -162 removed lines patch added patch discarded remove patch
@@ -35,73 +35,73 @@  discard block
 block discarded – undo
35 35
 class CSMSFile
36 36
 {
37 37
     /**
38
-	 * @var string Error code (or message)
39
-	 */
40
-	public $error='';
41
-
42
-	public $addr_from;
43
-	public $addr_to;
44
-	public $deferred;
45
-	public $priority;
46
-	public $class;
47
-	public $message;
48
-	public $nostop;
49
-
50
-
51
-	/**
52
-	 *	CSMSFile
53
-	 *
54
-	 *	@param	string	$to                 Recipients SMS
55
-	 *	@param 	string	$from               Sender SMS
56
-	 *	@param 	string	$msg                Message
57
-	 *	@param 	int		$deliveryreceipt	Not used
58
-	 *	@param 	int		$deferred			Deferred or not
59
-	 *	@param 	int		$priority			Priority
60
-	 *	@param 	int		$class				Class
61
-	 */
62
-	function __construct($to,$from,$msg,$deliveryreceipt=0,$deferred=0,$priority=3,$class=1)
63
-	{
64
-		global $conf;
65
-
66
-		// On definit fin de ligne
67
-		$this->eol="\n";
68
-		if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n";
69
-		if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r";
70
-
71
-		// If ending method not defined
72
-		if (empty($conf->global->MAIN_SMS_SENDMODE))
73
-		{
74
-		    $this->error='No SMS Engine defined';
75
-		    return -1;
76
-		}
77
-
78
-		dol_syslog("CSMSFile::CSMSFile: MAIN_SMS_SENDMODE=".$conf->global->MAIN_SMS_SENDMODE." charset=".$conf->file->character_set_client." from=".$from.", to=".$to.", msg length=".count($msg), LOG_DEBUG);
79
-		dol_syslog("CSMSFile::CSMSFile: deferred=".$deferred." priority=".$priority." class=".$class, LOG_DEBUG);
80
-
81
-		// Action according to choosed sending method
82
-	    $this->addr_from=$from;
83
-	    $this->addr_to=$to;
38
+     * @var string Error code (or message)
39
+     */
40
+    public $error='';
41
+
42
+    public $addr_from;
43
+    public $addr_to;
44
+    public $deferred;
45
+    public $priority;
46
+    public $class;
47
+    public $message;
48
+    public $nostop;
49
+
50
+
51
+    /**
52
+     *	CSMSFile
53
+     *
54
+     *	@param	string	$to                 Recipients SMS
55
+     *	@param 	string	$from               Sender SMS
56
+     *	@param 	string	$msg                Message
57
+     *	@param 	int		$deliveryreceipt	Not used
58
+     *	@param 	int		$deferred			Deferred or not
59
+     *	@param 	int		$priority			Priority
60
+     *	@param 	int		$class				Class
61
+     */
62
+    function __construct($to,$from,$msg,$deliveryreceipt=0,$deferred=0,$priority=3,$class=1)
63
+    {
64
+        global $conf;
65
+
66
+        // On definit fin de ligne
67
+        $this->eol="\n";
68
+        if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n";
69
+        if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r";
70
+
71
+        // If ending method not defined
72
+        if (empty($conf->global->MAIN_SMS_SENDMODE))
73
+        {
74
+            $this->error='No SMS Engine defined';
75
+            return -1;
76
+        }
77
+
78
+        dol_syslog("CSMSFile::CSMSFile: MAIN_SMS_SENDMODE=".$conf->global->MAIN_SMS_SENDMODE." charset=".$conf->file->character_set_client." from=".$from.", to=".$to.", msg length=".count($msg), LOG_DEBUG);
79
+        dol_syslog("CSMSFile::CSMSFile: deferred=".$deferred." priority=".$priority." class=".$class, LOG_DEBUG);
80
+
81
+        // Action according to choosed sending method
82
+        $this->addr_from=$from;
83
+        $this->addr_to=$to;
84 84
         $this->deferred=$deferred;
85 85
         $this->priority=$priority;
86 86
         $this->class=$class;
87 87
         $this->message=$msg;
88 88
         $this->nostop=false;
89
-	}
89
+    }
90 90
 
91 91
 
92
-	/**
93
-	 * Send sms that was prepared by constructor
94
-	 *
95
-	 * @return    boolean     True if sms sent, false otherwise
96
-	 */
97
-	function sendfile()
98
-	{
99
-		global $conf;
92
+    /**
93
+     * Send sms that was prepared by constructor
94
+     *
95
+     * @return    boolean     True if sms sent, false otherwise
96
+     */
97
+    function sendfile()
98
+    {
99
+        global $conf;
100 100
 
101
-		$errorlevel=error_reporting();
102
-		error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
101
+        $errorlevel=error_reporting();
102
+        error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
103 103
 
104
-		$res=false;
104
+        $res=false;
105 105
 
106 106
         dol_syslog("CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG);
107 107
         dol_syslog("CSMSFile::sendfile message=\n".$this->message);
@@ -110,121 +110,121 @@  discard block
 block discarded – undo
110 110
 
111 111
         if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
112 112
 
113
-		if (empty($conf->global->MAIN_DISABLE_ALL_SMS))
114
-		{
115
-
116
-		    // Action according to choosed sending method
117
-		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')    // Backward compatibility    @deprecated
118
-			{
119
-				dol_include_once('/ovh/class/ovhsms.class.php');
120
-				$sms=new OvhSms($this->db);
121
-				$sms->expe=$this->addr_from;
122
-				$sms->dest=$this->addr_to;
123
-				$sms->message=$this->message;
124
-				$sms->deferred=$this->deferred;
125
-				$sms->priority=$this->priority;
113
+        if (empty($conf->global->MAIN_DISABLE_ALL_SMS))
114
+        {
115
+
116
+            // Action according to choosed sending method
117
+            if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')    // Backward compatibility    @deprecated
118
+            {
119
+                dol_include_once('/ovh/class/ovhsms.class.php');
120
+                $sms=new OvhSms($this->db);
121
+                $sms->expe=$this->addr_from;
122
+                $sms->dest=$this->addr_to;
123
+                $sms->message=$this->message;
124
+                $sms->deferred=$this->deferred;
125
+                $sms->priority=$this->priority;
126 126
                 $sms->class=$this->class;
127 127
                 $sms->nostop=$this->nostop;
128 128
 
129 129
                 $res=$sms->SmsSend();
130
-				if ($res <= 0)
131
-				{
132
-					$this->error=$sms->error;
133
-					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
134
-				}
135
-				else
136
-				{
137
-					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
138
-					//var_dump($res);        // 1973128
139
-					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
140
-				}
141
-			}
142
-		    else if (! empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
143
-		    {
144
-		        $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
145
-		        $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
146
-		        dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
147
-		        try
148
-		        {
149
-		            $classname=ucfirst($classfile);
150
-		            $sms = new $classname($this->db);
151
-		            $sms->expe=$this->addr_from;
152
-		            $sms->dest=$this->addr_to;
153
-		            $sms->deferred=$this->deferred;
154
-		            $sms->priority=$this->priority;
155
-		            $sms->class=$this->class;
156
-		            $sms->message=$this->message;
157
-		            $sms->nostop=$this->nostop;
130
+                if ($res <= 0)
131
+                {
132
+                    $this->error=$sms->error;
133
+                    dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
134
+                }
135
+                else
136
+                {
137
+                    dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
138
+                    //var_dump($res);        // 1973128
139
+                    if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
140
+                }
141
+            }
142
+            else if (! empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
143
+            {
144
+                $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
145
+                $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
146
+                dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
147
+                try
148
+                {
149
+                    $classname=ucfirst($classfile);
150
+                    $sms = new $classname($this->db);
151
+                    $sms->expe=$this->addr_from;
152
+                    $sms->dest=$this->addr_to;
153
+                    $sms->deferred=$this->deferred;
154
+                    $sms->priority=$this->priority;
155
+                    $sms->class=$this->class;
156
+                    $sms->message=$this->message;
157
+                    $sms->nostop=$this->nostop;
158 158
 
159 159
                     $res=$sms->SmsSend();
160 160
                     $this->error = $sms->error;
161 161
                     $this->errors = $sms->errors;
162
-    				if ($res <= 0)
163
-    				{
164
-    					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
165
-    				}
166
-    				else
167
-    				{
168
-    					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
169
-    					//var_dump($res);        // 1973128
170
-    					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
171
-    				}
172
-		        }
173
-		        catch(Exception $e)
174
-		        {
175
-		            dol_print_error('','Error to get list of senders: '.$e->getMessage());
176
-		        }
177
-		    }
178
-			else
179
-			{
180
-				// Send sms method not correctly defined
181
-				// --------------------------------------
182
-
183
-				return 'Bad value for MAIN_SMS_SENDMODE constant';
184
-			}
185
-		}
186
-		else
187
-		{
188
-			$this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
189
-			dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING);
190
-		}
191
-
192
-		error_reporting($errorlevel);              // Reactive niveau erreur origine
193
-
194
-		return $res;
195
-	}
162
+                    if ($res <= 0)
163
+                    {
164
+                        dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
165
+                    }
166
+                    else
167
+                    {
168
+                        dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
169
+                        //var_dump($res);        // 1973128
170
+                        if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
171
+                    }
172
+                }
173
+                catch(Exception $e)
174
+                {
175
+                    dol_print_error('','Error to get list of senders: '.$e->getMessage());
176
+                }
177
+            }
178
+            else
179
+            {
180
+                // Send sms method not correctly defined
181
+                // --------------------------------------
182
+
183
+                return 'Bad value for MAIN_SMS_SENDMODE constant';
184
+            }
185
+        }
186
+        else
187
+        {
188
+            $this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
189
+            dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING);
190
+        }
191
+
192
+        error_reporting($errorlevel);              // Reactive niveau erreur origine
193
+
194
+        return $res;
195
+    }
196 196
 
197 197
 
198 198
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
199
-	/**
200
-	 *  Write content of a SendSms request into a dump file (mode = all)
201
-	 *  Used for debugging.
202
-	 *
203
-	 *  @return	void
204
-	 */
205
-	function dump_sms()
206
-	{
199
+    /**
200
+     *  Write content of a SendSms request into a dump file (mode = all)
201
+     *  Used for debugging.
202
+     *
203
+     *  @return	void
204
+     */
205
+    function dump_sms()
206
+    {
207 207
         // phpcs:enable
208
-		global $conf,$dolibarr_main_data_root;
209
-
210
-		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
211
-		{
212
-			$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
213
-			$fp = fopen($outputfile,"w");
214
-
215
-			fputs($fp, "From: ".$this->addr_from."\n");
216
-			fputs($fp, "To: ".$this->addr_to."\n");
217
-			fputs($fp, "Priority: ".$this->priority."\n");
218
-			fputs($fp, "Class: ".$this->class."\n");
219
-			fputs($fp, "Deferred: ".$this->deferred."\n");
220
-			fputs($fp, "DisableStop: ".$this->nostop."\n");
221
-			fputs($fp, "Message:\n".$this->message);
222
-
223
-			fclose($fp);
224
-			if (! empty($conf->global->MAIN_UMASK))
225
-			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
226
-		}
227
-	}
208
+        global $conf,$dolibarr_main_data_root;
209
+
210
+        if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
211
+        {
212
+            $outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
213
+            $fp = fopen($outputfile,"w");
214
+
215
+            fputs($fp, "From: ".$this->addr_from."\n");
216
+            fputs($fp, "To: ".$this->addr_to."\n");
217
+            fputs($fp, "Priority: ".$this->priority."\n");
218
+            fputs($fp, "Class: ".$this->class."\n");
219
+            fputs($fp, "Deferred: ".$this->deferred."\n");
220
+            fputs($fp, "DisableStop: ".$this->nostop."\n");
221
+            fputs($fp, "Message:\n".$this->message);
222
+
223
+            fclose($fp);
224
+            if (! empty($conf->global->MAIN_UMASK))
225
+            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
226
+        }
227
+    }
228 228
 
229 229
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
230 230
     /**
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 
242 242
         if (@is_writeable($dolibarr_main_data_root))    // Avoid fatal error on fopen with open_basedir
243 243
         {
244
-        	$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
244
+            $outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
245 245
             $fp = fopen($outputfile,"a+");
246 246
 
247 247
             fputs($fp, "\nResult id=".$result);
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 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
 	public $addr_from;
43 43
 	public $addr_to;
@@ -59,19 +59,19 @@  discard block
 block discarded – undo
59 59
 	 *	@param 	int		$priority			Priority
60 60
 	 *	@param 	int		$class				Class
61 61
 	 */
62
-	function __construct($to,$from,$msg,$deliveryreceipt=0,$deferred=0,$priority=3,$class=1)
62
+	function __construct($to, $from, $msg, $deliveryreceipt = 0, $deferred = 0, $priority = 3, $class = 1)
63 63
 	{
64 64
 		global $conf;
65 65
 
66 66
 		// On definit fin de ligne
67
-		$this->eol="\n";
68
-		if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n";
69
-		if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r";
67
+		$this->eol = "\n";
68
+		if (preg_match('/^win/i', PHP_OS)) $this->eol = "\r\n";
69
+		if (preg_match('/^mac/i', PHP_OS)) $this->eol = "\r";
70 70
 
71 71
 		// If ending method not defined
72 72
 		if (empty($conf->global->MAIN_SMS_SENDMODE))
73 73
 		{
74
-		    $this->error='No SMS Engine defined';
74
+		    $this->error = 'No SMS Engine defined';
75 75
 		    return -1;
76 76
 		}
77 77
 
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
 		dol_syslog("CSMSFile::CSMSFile: deferred=".$deferred." priority=".$priority." class=".$class, LOG_DEBUG);
80 80
 
81 81
 		// Action according to choosed sending method
82
-	    $this->addr_from=$from;
83
-	    $this->addr_to=$to;
84
-        $this->deferred=$deferred;
85
-        $this->priority=$priority;
86
-        $this->class=$class;
87
-        $this->message=$msg;
88
-        $this->nostop=false;
82
+	    $this->addr_from = $from;
83
+	    $this->addr_to = $to;
84
+        $this->deferred = $deferred;
85
+        $this->priority = $priority;
86
+        $this->class = $class;
87
+        $this->message = $msg;
88
+        $this->nostop = false;
89 89
 	}
90 90
 
91 91
 
@@ -98,17 +98,17 @@  discard block
 block discarded – undo
98 98
 	{
99 99
 		global $conf;
100 100
 
101
-		$errorlevel=error_reporting();
102
-		error_reporting($errorlevel ^ E_WARNING);   // Desactive warnings
101
+		$errorlevel = error_reporting();
102
+		error_reporting($errorlevel ^ E_WARNING); // Desactive warnings
103 103
 
104
-		$res=false;
104
+		$res = false;
105 105
 
106 106
         dol_syslog("CSMSFile::sendfile addr_to=".$this->addr_to, LOG_DEBUG);
107 107
         dol_syslog("CSMSFile::sendfile message=\n".$this->message);
108 108
 
109
-        $this->message=stripslashes($this->message);
109
+        $this->message = stripslashes($this->message);
110 110
 
111
-        if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
111
+        if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
112 112
 
113 113
 		if (empty($conf->global->MAIN_DISABLE_ALL_SMS))
114 114
 		{
@@ -117,46 +117,46 @@  discard block
 block discarded – undo
117 117
 		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')    // Backward compatibility    @deprecated
118 118
 			{
119 119
 				dol_include_once('/ovh/class/ovhsms.class.php');
120
-				$sms=new OvhSms($this->db);
121
-				$sms->expe=$this->addr_from;
122
-				$sms->dest=$this->addr_to;
123
-				$sms->message=$this->message;
124
-				$sms->deferred=$this->deferred;
125
-				$sms->priority=$this->priority;
126
-                $sms->class=$this->class;
127
-                $sms->nostop=$this->nostop;
128
-
129
-                $res=$sms->SmsSend();
120
+				$sms = new OvhSms($this->db);
121
+				$sms->expe = $this->addr_from;
122
+				$sms->dest = $this->addr_to;
123
+				$sms->message = $this->message;
124
+				$sms->deferred = $this->deferred;
125
+				$sms->priority = $this->priority;
126
+                $sms->class = $this->class;
127
+                $sms->nostop = $this->nostop;
128
+
129
+                $res = $sms->SmsSend();
130 130
 				if ($res <= 0)
131 131
 				{
132
-					$this->error=$sms->error;
132
+					$this->error = $sms->error;
133 133
 					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
134 134
 				}
135 135
 				else
136 136
 				{
137 137
 					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
138 138
 					//var_dump($res);        // 1973128
139
-					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
139
+					if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
140 140
 				}
141 141
 			}
142
-		    else if (! empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
142
+		    else if (!empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
143 143
 		    {
144
-		        $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
145
-		        $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
144
+		        $tmp = explode('@', $conf->global->MAIN_SMS_SENDMODE);
145
+		        $classfile = $tmp[0]; $module = (empty($tmp[1]) ? $tmp[0] : $tmp[1]);
146 146
 		        dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
147 147
 		        try
148 148
 		        {
149
-		            $classname=ucfirst($classfile);
149
+		            $classname = ucfirst($classfile);
150 150
 		            $sms = new $classname($this->db);
151
-		            $sms->expe=$this->addr_from;
152
-		            $sms->dest=$this->addr_to;
153
-		            $sms->deferred=$this->deferred;
154
-		            $sms->priority=$this->priority;
155
-		            $sms->class=$this->class;
156
-		            $sms->message=$this->message;
157
-		            $sms->nostop=$this->nostop;
158
-
159
-                    $res=$sms->SmsSend();
151
+		            $sms->expe = $this->addr_from;
152
+		            $sms->dest = $this->addr_to;
153
+		            $sms->deferred = $this->deferred;
154
+		            $sms->priority = $this->priority;
155
+		            $sms->class = $this->class;
156
+		            $sms->message = $this->message;
157
+		            $sms->nostop = $this->nostop;
158
+
159
+                    $res = $sms->SmsSend();
160 160
                     $this->error = $sms->error;
161 161
                     $this->errors = $sms->errors;
162 162
     				if ($res <= 0)
@@ -167,12 +167,12 @@  discard block
 block discarded – undo
167 167
     				{
168 168
     					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
169 169
     					//var_dump($res);        // 1973128
170
-    					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
170
+    					if (!empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
171 171
     				}
172 172
 		        }
173
-		        catch(Exception $e)
173
+		        catch (Exception $e)
174 174
 		        {
175
-		            dol_print_error('','Error to get list of senders: '.$e->getMessage());
175
+		            dol_print_error('', 'Error to get list of senders: '.$e->getMessage());
176 176
 		        }
177 177
 		    }
178 178
 			else
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 		else
187 187
 		{
188
-			$this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
188
+			$this->error = 'No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
189 189
 			dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING);
190 190
 		}
191 191
 
192
-		error_reporting($errorlevel);              // Reactive niveau erreur origine
192
+		error_reporting($errorlevel); // Reactive niveau erreur origine
193 193
 
194 194
 		return $res;
195 195
 	}
@@ -205,12 +205,12 @@  discard block
 block discarded – undo
205 205
 	function dump_sms()
206 206
 	{
207 207
         // phpcs:enable
208
-		global $conf,$dolibarr_main_data_root;
208
+		global $conf, $dolibarr_main_data_root;
209 209
 
210 210
 		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
211 211
 		{
212
-			$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
213
-			$fp = fopen($outputfile,"w");
212
+			$outputfile = $dolibarr_main_data_root."/dolibarr_sms.log";
213
+			$fp = fopen($outputfile, "w");
214 214
 
215 215
 			fputs($fp, "From: ".$this->addr_from."\n");
216 216
 			fputs($fp, "To: ".$this->addr_to."\n");
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 			fputs($fp, "Message:\n".$this->message);
222 222
 
223 223
 			fclose($fp);
224
-			if (! empty($conf->global->MAIN_UMASK))
224
+			if (!empty($conf->global->MAIN_UMASK))
225 225
 			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
226 226
 		}
227 227
 	}
@@ -237,17 +237,17 @@  discard block
 block discarded – undo
237 237
     function dump_sms_result($result)
238 238
     {
239 239
         // phpcs:enable
240
-        global $conf,$dolibarr_main_data_root;
240
+        global $conf, $dolibarr_main_data_root;
241 241
 
242 242
         if (@is_writeable($dolibarr_main_data_root))    // Avoid fatal error on fopen with open_basedir
243 243
         {
244
-        	$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
245
-            $fp = fopen($outputfile,"a+");
244
+        	$outputfile = $dolibarr_main_data_root."/dolibarr_sms.log";
245
+            $fp = fopen($outputfile, "a+");
246 246
 
247 247
             fputs($fp, "\nResult id=".$result);
248 248
 
249 249
             fclose($fp);
250
-            if (! empty($conf->global->MAIN_UMASK))
250
+            if (!empty($conf->global->MAIN_UMASK))
251 251
             @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
252 252
         }
253 253
     }
Please login to merge, or discard this patch.
Braces   +38 added lines, -24 removed lines patch added patch discarded remove patch
@@ -65,8 +65,12 @@  discard block
 block discarded – undo
65 65
 
66 66
 		// On definit fin de ligne
67 67
 		$this->eol="\n";
68
-		if (preg_match('/^win/i',PHP_OS)) $this->eol="\r\n";
69
-		if (preg_match('/^mac/i',PHP_OS)) $this->eol="\r";
68
+		if (preg_match('/^win/i',PHP_OS)) {
69
+		    $this->eol="\r\n";
70
+		}
71
+		if (preg_match('/^mac/i',PHP_OS)) {
72
+		    $this->eol="\r";
73
+		}
70 74
 
71 75
 		// If ending method not defined
72 76
 		if (empty($conf->global->MAIN_SMS_SENDMODE))
@@ -108,15 +112,19 @@  discard block
 block discarded – undo
108 112
 
109 113
         $this->message=stripslashes($this->message);
110 114
 
111
-        if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms();
115
+        if (! empty($conf->global->MAIN_SMS_DEBUG)) {
116
+            $this->dump_sms();
117
+        }
112 118
 
113 119
 		if (empty($conf->global->MAIN_DISABLE_ALL_SMS))
114 120
 		{
115 121
 
116 122
 		    // Action according to choosed sending method
117
-		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh')    // Backward compatibility    @deprecated
123
+		    if ($conf->global->MAIN_SMS_SENDMODE == 'ovh') {
124
+		        // Backward compatibility    @deprecated
118 125
 			{
119 126
 				dol_include_once('/ovh/class/ovhsms.class.php');
127
+		    }
120 128
 				$sms=new OvhSms($this->db);
121 129
 				$sms->expe=$this->addr_from;
122 130
 				$sms->dest=$this->addr_to;
@@ -131,17 +139,19 @@  discard block
 block discarded – undo
131 139
 				{
132 140
 					$this->error=$sms->error;
133 141
 					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
134
-				}
135
-				else
142
+				} else
136 143
 				{
137 144
 					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
138 145
 					//var_dump($res);        // 1973128
139
-					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
146
+					if (! empty($conf->global->MAIN_SMS_DEBUG)) {
147
+					    $this->dump_sms_result($res);
148
+					}
140 149
 				}
141
-			}
142
-		    else if (! empty($conf->global->MAIN_SMS_SENDMODE))    // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
150
+			} else if (! empty($conf->global->MAIN_SMS_SENDMODE)) {
151
+		        // $conf->global->MAIN_SMS_SENDMODE looks like a value 'class@module'
143 152
 		    {
144 153
 		        $tmp=explode('@',$conf->global->MAIN_SMS_SENDMODE);
154
+		    }
145 155
 		        $classfile=$tmp[0]; $module=(empty($tmp[1])?$tmp[0]:$tmp[1]);
146 156
 		        dol_include_once('/'.$module.'/class/'.$classfile.'.class.php');
147 157
 		        try
@@ -162,28 +172,26 @@  discard block
 block discarded – undo
162 172
     				if ($res <= 0)
163 173
     				{
164 174
     					dol_syslog("CSMSFile::sendfile: sms send error=".$this->error, LOG_ERR);
165
-    				}
166
-    				else
175
+    				} else
167 176
     				{
168 177
     					dol_syslog("CSMSFile::sendfile: sms send success with id=".$res, LOG_DEBUG);
169 178
     					//var_dump($res);        // 1973128
170
-    					if (! empty($conf->global->MAIN_SMS_DEBUG)) $this->dump_sms_result($res);
179
+    					if (! empty($conf->global->MAIN_SMS_DEBUG)) {
180
+    					    $this->dump_sms_result($res);
181
+    					}
171 182
     				}
172
-		        }
173
-		        catch(Exception $e)
183
+		        } catch(Exception $e)
174 184
 		        {
175 185
 		            dol_print_error('','Error to get list of senders: '.$e->getMessage());
176 186
 		        }
177
-		    }
178
-			else
187
+		    } else
179 188
 			{
180 189
 				// Send sms method not correctly defined
181 190
 				// --------------------------------------
182 191
 
183 192
 				return 'Bad value for MAIN_SMS_SENDMODE constant';
184 193
 			}
185
-		}
186
-		else
194
+		} else
187 195
 		{
188 196
 			$this->error='No sms sent. Feature is disabled by option MAIN_DISABLE_ALL_SMS';
189 197
 			dol_syslog("CSMSFile::sendfile: ".$this->error, LOG_WARNING);
@@ -207,9 +215,11 @@  discard block
 block discarded – undo
207 215
         // phpcs:enable
208 216
 		global $conf,$dolibarr_main_data_root;
209 217
 
210
-		if (@is_writeable($dolibarr_main_data_root))	// Avoid fatal error on fopen with open_basedir
218
+		if (@is_writeable($dolibarr_main_data_root)) {
219
+		    // Avoid fatal error on fopen with open_basedir
211 220
 		{
212 221
 			$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
222
+		}
213 223
 			$fp = fopen($outputfile,"w");
214 224
 
215 225
 			fputs($fp, "From: ".$this->addr_from."\n");
@@ -221,8 +231,9 @@  discard block
 block discarded – undo
221 231
 			fputs($fp, "Message:\n".$this->message);
222 232
 
223 233
 			fclose($fp);
224
-			if (! empty($conf->global->MAIN_UMASK))
225
-			@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
234
+			if (! empty($conf->global->MAIN_UMASK)) {
235
+						@chmod($outputfile, octdec($conf->global->MAIN_UMASK));
236
+			}
226 237
 		}
227 238
 	}
228 239
 
@@ -239,16 +250,19 @@  discard block
 block discarded – undo
239 250
         // phpcs:enable
240 251
         global $conf,$dolibarr_main_data_root;
241 252
 
242
-        if (@is_writeable($dolibarr_main_data_root))    // Avoid fatal error on fopen with open_basedir
253
+        if (@is_writeable($dolibarr_main_data_root)) {
254
+            // Avoid fatal error on fopen with open_basedir
243 255
         {
244 256
         	$outputfile=$dolibarr_main_data_root."/dolibarr_sms.log";
257
+        }
245 258
             $fp = fopen($outputfile,"a+");
246 259
 
247 260
             fputs($fp, "\nResult id=".$result);
248 261
 
249 262
             fclose($fp);
250
-            if (! empty($conf->global->MAIN_UMASK))
251
-            @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
263
+            if (! empty($conf->global->MAIN_UMASK)) {
264
+                        @chmod($outputfile, octdec($conf->global->MAIN_UMASK));
265
+            }
252 266
         }
253 267
     }
254 268
 }
Please login to merge, or discard this patch.