Passed
Push — master ( 222e44...208bd5 )
by Alxarafe
31:22
created
dolibarr/htdocs/comm/mailing/class/mailing.class.php 3 patches
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -31,694 +31,694 @@
 block discarded – undo
31 31
  */
32 32
 class Mailing extends CommonObject
33 33
 {
34
-	/**
35
-	 * @var string ID to identify managed object
36
-	 */
37
-	public $element='mailing';
34
+    /**
35
+     * @var string ID to identify managed object
36
+     */
37
+    public $element='mailing';
38 38
 
39
-	/**
40
-	 * @var string Name of table without prefix where object is stored
41
-	 */
42
-	public $table_element='mailing';
39
+    /**
40
+     * @var string Name of table without prefix where object is stored
41
+     */
42
+    public $table_element='mailing';
43 43
 
44
-	/**
45
-	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
46
-	 */
47
-	public $picto='email';
44
+    /**
45
+     * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
46
+     */
47
+    public $picto='email';
48 48
 
49
-	public $titre;
50
-	public $sujet;
51
-	public $body;
52
-	public $nbemail;
53
-	public $bgcolor;
54
-	public $bgimage;
49
+    public $titre;
50
+    public $sujet;
51
+    public $body;
52
+    public $nbemail;
53
+    public $bgcolor;
54
+    public $bgimage;
55 55
 
56
-	public $statut;       // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
56
+    public $statut;       // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
57 57
 
58
-	public $email_from;
59
-	public $email_replyto;
60
-	public $email_errorsto;
58
+    public $email_from;
59
+    public $email_replyto;
60
+    public $email_errorsto;
61 61
 
62
-	public $joined_file1;
63
-	public $joined_file2;
64
-	public $joined_file3;
65
-	public $joined_file4;
62
+    public $joined_file1;
63
+    public $joined_file2;
64
+    public $joined_file3;
65
+    public $joined_file4;
66 66
 
67
-	public $user_creat;
68
-	public $user_valid;
67
+    public $user_creat;
68
+    public $user_valid;
69 69
 
70
-	public $date_creat;
71
-	public $date_valid;
70
+    public $date_creat;
71
+    public $date_valid;
72 72
 
73
-	public $extraparams=array();
73
+    public $extraparams=array();
74 74
 
75
-	public $statut_dest=array();
76
-	public $statuts=array();
75
+    public $statut_dest=array();
76
+    public $statuts=array();
77 77
 
78 78
 
79 79
     /**
80 80
      *  Constructor
81 81
      *
82 82
      *  @param      DoliDb      $db      Database handler
83
-	 */
84
-	function __construct($db)
85
-	{
86
-		$this->db = $db;
87
-
88
-		// List of language codes for status
89
-		$this->statuts[0] = 'MailingStatusDraft';
90
-		$this->statuts[1] = 'MailingStatusValidated';
91
-		$this->statuts[2] = 'MailingStatusSentPartialy';
92
-		$this->statuts[3] = 'MailingStatusSentCompletely';
93
-
94
-		$this->statut_dest[-1] = 'MailingStatusError';
95
-		$this->statut_dest[0] = 'MailingStatusNotSent';
96
-		$this->statut_dest[1] = 'MailingStatusSent';
97
-		$this->statut_dest[2] = 'MailingStatusRead';
98
-		$this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe';    // Read but ask to not be contacted anymore
99
-	}
100
-
101
-	/**
102
-	 *  Create an EMailing
103
-	 *
104
-	 *  @param	User	$user 		Object of user making creation
105
-	 *  @return int	   				-1 if error, Id of created object if OK
106
-	 */
107
-	function create($user)
108
-	{
109
-		global $conf, $langs;
110
-
111
-		$this->db->begin();
112
-
113
-		$this->titre=trim($this->titre);
114
-		$this->email_from=trim($this->email_from);
115
-
116
-		if (! $this->email_from)
117
-		{
118
-			$this->error = $langs->trans("ErrorMailFromRequired");
119
-			return -1;
120
-		}
121
-
122
-		$now=dol_now();
123
-
124
-		$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
125
-		$sql .= " (date_creat, fk_user_creat, entity)";
126
-		$sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")";
127
-
128
-		if (! $this->titre)
129
-		{
130
-			$this->titre = $langs->trans("NoTitle");
131
-		}
132
-
133
-		dol_syslog("Mailing::Create", LOG_DEBUG);
134
-		$result=$this->db->query($sql);
135
-		if ($result)
136
-		{
137
-			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
138
-
139
-			if ($this->update($user) > 0)
140
-			{
141
-				$this->db->commit();
142
-			}
143
-			else
144
-			{
145
-				$this->error=$this->db->lasterror();
146
-				$this->db->rollback();
147
-				return -1;
148
-			}
149
-
150
-			return $this->id;
151
-		}
152
-		else
153
-		{
154
-			$this->error=$this->db->lasterror();
155
-			$this->db->rollback();
156
-			return -1;
157
-		}
158
-	}
159
-
160
-	/**
161
-	 *  Update emailing record
162
-	 *
163
-	 *  @param	User	$user 		Object of user making change
164
-	 *  @return int				    < 0 if KO, > 0 if OK
165
-	 */
166
-	function update($user)
167
-	{
168
-		$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
169
-		$sql .= " SET titre = '".$this->db->escape($this->titre)."'";
170
-		$sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
171
-		$sql .= ", body = '".$this->db->escape($this->body)."'";
172
-		$sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
173
-		$sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
174
-		$sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
175
-		$sql .= ", bgcolor = '".($this->bgcolor?$this->db->escape($this->bgcolor):null)."'";
176
-		$sql .= ", bgimage = '".($this->bgimage?$this->db->escape($this->bgimage):null)."'";
177
-		$sql .= " WHERE rowid = ".$this->id;
178
-
179
-		dol_syslog("Mailing::Update", LOG_DEBUG);
180
-		$result=$this->db->query($sql);
181
-		if ($result)
182
-		{
183
-			return 1;
184
-		}
185
-		else
186
-		{
187
-			$this->error=$this->db->lasterror();
188
-			return -1;
189
-		}
190
-	}
191
-
192
-	/**
193
-	 *	Get object from database
194
-	 *
195
-	 *	@param	int		$rowid      Id of emailing
196
-	 *	@return	int					<0 if KO, >0 if OK
197
-	 */
198
-	function fetch($rowid)
199
-	{
200
-		global $conf;
201
-
202
-		$sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage";
203
-		$sql.= ", m.email_from, m.email_replyto, m.email_errorsto";
204
-		$sql.= ", m.statut, m.nbemail";
205
-		$sql.= ", m.fk_user_creat, m.fk_user_valid";
206
-		$sql.= ", m.date_creat";
207
-		$sql.= ", m.date_valid";
208
-		$sql.= ", m.date_envoi";
209
-		$sql.= ", m.extraparams";
210
-		$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
211
-		$sql.= " WHERE m.rowid = ".(int) $rowid;
212
-
213
-		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
214
-		$result=$this->db->query($sql);
215
-		if ($result)
216
-		{
217
-			if ($this->db->num_rows($result))
218
-			{
219
-				$obj = $this->db->fetch_object($result);
220
-
221
-				$this->id				= $obj->rowid;
222
-				$this->ref				= $obj->rowid;
223
-				$this->statut			= $obj->statut;
224
-				$this->nbemail			= $obj->nbemail;
225
-				$this->titre			= $obj->titre;
226
-
227
-				$this->sujet			= $obj->sujet;
228
-				if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
229
-					$this->body				= dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
230
-				}else {
231
-					$this->body				= $obj->body;
232
-				}
233
-
234
-				$this->bgcolor			= $obj->bgcolor;
235
-				$this->bgimage			= $obj->bgimage;
236
-
237
-				$this->email_from		= $obj->email_from;
238
-				$this->email_replyto	= $obj->email_replyto;
239
-				$this->email_errorsto	= $obj->email_errorsto;
240
-
241
-				$this->user_creat		= $obj->fk_user_creat;
242
-				$this->user_valid		= $obj->fk_user_valid;
243
-
244
-				$this->date_creat		= $this->db->jdate($obj->date_creat);
245
-				$this->date_valid		= $this->db->jdate($obj->date_valid);
246
-				$this->date_envoi		= $this->db->jdate($obj->date_envoi);
247
-
248
-				$this->extraparams		= (array) json_decode($obj->extraparams, true);
249
-
250
-				return 1;
251
-			}
252
-			else
253
-			{
254
-				dol_syslog(get_class($this)."::fetch Erreur -1");
255
-				return -1;
256
-			}
257
-		}
258
-		else
259
-		{
260
-			dol_syslog(get_class($this)."::fetch Erreur -2");
261
-			return -2;
262
-		}
263
-	}
264
-
265
-
266
-	/**
267
-	 *	Load an object from its id and create a new one in database
268
-	 *
269
-	 *	@param  int		$fromid     	Id of object to clone
270
-	 *	@param	int		$option1		1=Copy content, 0=Forget content
271
-	 *	@param	int		$option2		Not used
272
-	 *	@return	int						New id of clone
273
-	 */
274
-	function createFromClone($fromid,$option1,$option2)
275
-	{
276
-		global $user,$langs;
277
-
278
-		$error=0;
279
-
280
-		$object=new Mailing($this->db);
281
-
282
-		$object->context['createfromclone']='createfromclone';
283
-
284
-		$this->db->begin();
285
-
286
-		// Load source object
287
-		$object->fetch($fromid);
288
-		$object->id=0;
289
-		$object->statut=0;
290
-
291
-		// Clear fields
292
-		$object->titre=$langs->trans("CopyOf").' '.$object->titre.' '.dol_print_date(dol_now());
293
-
294
-		// If no option copy content
295
-		if (empty($option1))
296
-		{
297
-			// Clear values
298
-			$object->nbemail            = 0;
299
-			$object->sujet              = '';
300
-			$object->body               = '';
301
-			$object->bgcolor            = '';
302
-			$object->bgimage            = '';
303
-
304
-			$object->email_from         = '';
305
-			$object->email_replyto      = '';
306
-			$object->email_errorsto     = '';
307
-
308
-			$object->user_creat         = $user->id;
309
-			$object->user_valid         = '';
310
-
311
-			$object->date_creat         = '';
312
-			$object->date_valid         = '';
313
-			$object->date_envoi         = '';
314
-		}
315
-
316
-		// Create clone
317
-		$result=$object->create($user);
318
-
319
-		// Other options
320
-		if ($result < 0)
321
-		{
322
-			$this->error=$object->error;
323
-			$error++;
324
-		}
325
-
326
-		if (! $error)
327
-		{
328
-			//Clone target
329
-			if (!empty($option2)) {
330
-
331
-				require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php';
332
-
333
-				$mailing_target = new MailingTargets($this->db);
334
-
335
-				$target_array=array();
336
-
337
-				$sql = "SELECT fk_contact, ";
338
-				$sql.=" lastname,   ";
339
-				$sql.=" firstname,";
340
-				$sql.=" email,";
341
-				$sql.=" other,";
342
-				$sql.=" source_url,";
343
-				$sql.=" source_id ,";
344
-				$sql.=" source_type ";
345
-				$sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles ";
346
-				$sql.= " WHERE fk_mailing = ".$fromid;
347
-
348
-				dol_syslog(get_class($this)."::createFromClone", LOG_DEBUG);
349
-				$result=$this->db->query($sql);
350
-				if ($result)
351
-				{
352
-					if ($this->db->num_rows($result))
353
-					{
354
-						while ($obj = $this->db->fetch_object($result)) {
355
-
356
-							$target_array[]=array('fk_contact'=>$obj->fk_contact,
357
-							'lastname'=>$obj->lastname,
358
-							'firstname'=>$obj->firstname,
359
-							'email'=>$obj->email,
360
-							'other'=>$obj->other,
361
-							'source_url'=>$obj->source_url,
362
-							'source_id'=>$obj->source_id,
363
-							'source_type'=>$obj->source_type);
364
-						}
365
-					}
366
-				}
367
-				else
368
-				{
369
-					$this->error=$this->db->lasterror();
370
-					return -1;
371
-				}
372
-
373
-				$mailing_target->add_to_target($object->id, $target_array);
374
-			}
375
-		}
376
-
377
-		unset($object->context['createfromclone']);
378
-
379
-		// End
380
-		if (! $error)
381
-		{
382
-			$this->db->commit();
383
-			return $object->id;
384
-		}
385
-		else
386
-		{
387
-			$this->db->rollback();
388
-			return -1;
389
-		}
390
-	}
391
-
392
-	/**
393
-	 *  Validate emailing
394
-	 *
395
-	 *  @param	User	$user      	Objet user qui valide
396
-	 * 	@return	int					<0 if KO, >0 if OK
397
-	 */
398
-	function valid($user)
399
-	{
400
-		$now=dol_now();
401
-
402
-		$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
403
-		$sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
404
-		$sql .= " WHERE rowid = ".$this->id;
405
-
406
-		dol_syslog("Mailing::valid", LOG_DEBUG);
407
-		if ($this->db->query($sql))
408
-		{
409
-			return 1;
410
-		}
411
-		else
412
-		{
413
-			$this->error=$this->db->lasterror();
414
-			return -1;
415
-		}
416
-	}
417
-
418
-
419
-	/**
420
-	 *  Delete emailing
421
-	 *
422
-	 *  @param	int		$rowid      id du mailing a supprimer
423
-	 *  @return int         		1 en cas de succes
424
-	 */
425
-	function delete($rowid)
426
-	{
427
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
428
-		$sql.= " WHERE rowid = ".$rowid;
429
-
430
-		dol_syslog("Mailing::delete", LOG_DEBUG);
431
-		$resql=$this->db->query($sql);
432
-		if ($resql)
433
-		{
434
-			return $this->delete_targets();
435
-		}
436
-		else
437
-		{
438
-			$this->error=$this->db->lasterror();
439
-			return -1;
440
-		}
441
-	}
83
+     */
84
+    function __construct($db)
85
+    {
86
+        $this->db = $db;
87
+
88
+        // List of language codes for status
89
+        $this->statuts[0] = 'MailingStatusDraft';
90
+        $this->statuts[1] = 'MailingStatusValidated';
91
+        $this->statuts[2] = 'MailingStatusSentPartialy';
92
+        $this->statuts[3] = 'MailingStatusSentCompletely';
93
+
94
+        $this->statut_dest[-1] = 'MailingStatusError';
95
+        $this->statut_dest[0] = 'MailingStatusNotSent';
96
+        $this->statut_dest[1] = 'MailingStatusSent';
97
+        $this->statut_dest[2] = 'MailingStatusRead';
98
+        $this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe';    // Read but ask to not be contacted anymore
99
+    }
100
+
101
+    /**
102
+     *  Create an EMailing
103
+     *
104
+     *  @param	User	$user 		Object of user making creation
105
+     *  @return int	   				-1 if error, Id of created object if OK
106
+     */
107
+    function create($user)
108
+    {
109
+        global $conf, $langs;
110
+
111
+        $this->db->begin();
112
+
113
+        $this->titre=trim($this->titre);
114
+        $this->email_from=trim($this->email_from);
115
+
116
+        if (! $this->email_from)
117
+        {
118
+            $this->error = $langs->trans("ErrorMailFromRequired");
119
+            return -1;
120
+        }
121
+
122
+        $now=dol_now();
123
+
124
+        $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
125
+        $sql .= " (date_creat, fk_user_creat, entity)";
126
+        $sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")";
127
+
128
+        if (! $this->titre)
129
+        {
130
+            $this->titre = $langs->trans("NoTitle");
131
+        }
132
+
133
+        dol_syslog("Mailing::Create", LOG_DEBUG);
134
+        $result=$this->db->query($sql);
135
+        if ($result)
136
+        {
137
+            $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
138
+
139
+            if ($this->update($user) > 0)
140
+            {
141
+                $this->db->commit();
142
+            }
143
+            else
144
+            {
145
+                $this->error=$this->db->lasterror();
146
+                $this->db->rollback();
147
+                return -1;
148
+            }
149
+
150
+            return $this->id;
151
+        }
152
+        else
153
+        {
154
+            $this->error=$this->db->lasterror();
155
+            $this->db->rollback();
156
+            return -1;
157
+        }
158
+    }
159
+
160
+    /**
161
+     *  Update emailing record
162
+     *
163
+     *  @param	User	$user 		Object of user making change
164
+     *  @return int				    < 0 if KO, > 0 if OK
165
+     */
166
+    function update($user)
167
+    {
168
+        $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
169
+        $sql .= " SET titre = '".$this->db->escape($this->titre)."'";
170
+        $sql .= ", sujet = '".$this->db->escape($this->sujet)."'";
171
+        $sql .= ", body = '".$this->db->escape($this->body)."'";
172
+        $sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
173
+        $sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
174
+        $sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
175
+        $sql .= ", bgcolor = '".($this->bgcolor?$this->db->escape($this->bgcolor):null)."'";
176
+        $sql .= ", bgimage = '".($this->bgimage?$this->db->escape($this->bgimage):null)."'";
177
+        $sql .= " WHERE rowid = ".$this->id;
178
+
179
+        dol_syslog("Mailing::Update", LOG_DEBUG);
180
+        $result=$this->db->query($sql);
181
+        if ($result)
182
+        {
183
+            return 1;
184
+        }
185
+        else
186
+        {
187
+            $this->error=$this->db->lasterror();
188
+            return -1;
189
+        }
190
+    }
191
+
192
+    /**
193
+     *	Get object from database
194
+     *
195
+     *	@param	int		$rowid      Id of emailing
196
+     *	@return	int					<0 if KO, >0 if OK
197
+     */
198
+    function fetch($rowid)
199
+    {
200
+        global $conf;
201
+
202
+        $sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage";
203
+        $sql.= ", m.email_from, m.email_replyto, m.email_errorsto";
204
+        $sql.= ", m.statut, m.nbemail";
205
+        $sql.= ", m.fk_user_creat, m.fk_user_valid";
206
+        $sql.= ", m.date_creat";
207
+        $sql.= ", m.date_valid";
208
+        $sql.= ", m.date_envoi";
209
+        $sql.= ", m.extraparams";
210
+        $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
211
+        $sql.= " WHERE m.rowid = ".(int) $rowid;
212
+
213
+        dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
214
+        $result=$this->db->query($sql);
215
+        if ($result)
216
+        {
217
+            if ($this->db->num_rows($result))
218
+            {
219
+                $obj = $this->db->fetch_object($result);
220
+
221
+                $this->id				= $obj->rowid;
222
+                $this->ref				= $obj->rowid;
223
+                $this->statut			= $obj->statut;
224
+                $this->nbemail			= $obj->nbemail;
225
+                $this->titre			= $obj->titre;
226
+
227
+                $this->sujet			= $obj->sujet;
228
+                if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
229
+                    $this->body				= dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
230
+                }else {
231
+                    $this->body				= $obj->body;
232
+                }
233
+
234
+                $this->bgcolor			= $obj->bgcolor;
235
+                $this->bgimage			= $obj->bgimage;
236
+
237
+                $this->email_from		= $obj->email_from;
238
+                $this->email_replyto	= $obj->email_replyto;
239
+                $this->email_errorsto	= $obj->email_errorsto;
240
+
241
+                $this->user_creat		= $obj->fk_user_creat;
242
+                $this->user_valid		= $obj->fk_user_valid;
243
+
244
+                $this->date_creat		= $this->db->jdate($obj->date_creat);
245
+                $this->date_valid		= $this->db->jdate($obj->date_valid);
246
+                $this->date_envoi		= $this->db->jdate($obj->date_envoi);
247
+
248
+                $this->extraparams		= (array) json_decode($obj->extraparams, true);
249
+
250
+                return 1;
251
+            }
252
+            else
253
+            {
254
+                dol_syslog(get_class($this)."::fetch Erreur -1");
255
+                return -1;
256
+            }
257
+        }
258
+        else
259
+        {
260
+            dol_syslog(get_class($this)."::fetch Erreur -2");
261
+            return -2;
262
+        }
263
+    }
264
+
265
+
266
+    /**
267
+     *	Load an object from its id and create a new one in database
268
+     *
269
+     *	@param  int		$fromid     	Id of object to clone
270
+     *	@param	int		$option1		1=Copy content, 0=Forget content
271
+     *	@param	int		$option2		Not used
272
+     *	@return	int						New id of clone
273
+     */
274
+    function createFromClone($fromid,$option1,$option2)
275
+    {
276
+        global $user,$langs;
277
+
278
+        $error=0;
279
+
280
+        $object=new Mailing($this->db);
281
+
282
+        $object->context['createfromclone']='createfromclone';
283
+
284
+        $this->db->begin();
285
+
286
+        // Load source object
287
+        $object->fetch($fromid);
288
+        $object->id=0;
289
+        $object->statut=0;
290
+
291
+        // Clear fields
292
+        $object->titre=$langs->trans("CopyOf").' '.$object->titre.' '.dol_print_date(dol_now());
293
+
294
+        // If no option copy content
295
+        if (empty($option1))
296
+        {
297
+            // Clear values
298
+            $object->nbemail            = 0;
299
+            $object->sujet              = '';
300
+            $object->body               = '';
301
+            $object->bgcolor            = '';
302
+            $object->bgimage            = '';
303
+
304
+            $object->email_from         = '';
305
+            $object->email_replyto      = '';
306
+            $object->email_errorsto     = '';
307
+
308
+            $object->user_creat         = $user->id;
309
+            $object->user_valid         = '';
310
+
311
+            $object->date_creat         = '';
312
+            $object->date_valid         = '';
313
+            $object->date_envoi         = '';
314
+        }
315
+
316
+        // Create clone
317
+        $result=$object->create($user);
318
+
319
+        // Other options
320
+        if ($result < 0)
321
+        {
322
+            $this->error=$object->error;
323
+            $error++;
324
+        }
325
+
326
+        if (! $error)
327
+        {
328
+            //Clone target
329
+            if (!empty($option2)) {
330
+
331
+                require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php';
332
+
333
+                $mailing_target = new MailingTargets($this->db);
334
+
335
+                $target_array=array();
336
+
337
+                $sql = "SELECT fk_contact, ";
338
+                $sql.=" lastname,   ";
339
+                $sql.=" firstname,";
340
+                $sql.=" email,";
341
+                $sql.=" other,";
342
+                $sql.=" source_url,";
343
+                $sql.=" source_id ,";
344
+                $sql.=" source_type ";
345
+                $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles ";
346
+                $sql.= " WHERE fk_mailing = ".$fromid;
347
+
348
+                dol_syslog(get_class($this)."::createFromClone", LOG_DEBUG);
349
+                $result=$this->db->query($sql);
350
+                if ($result)
351
+                {
352
+                    if ($this->db->num_rows($result))
353
+                    {
354
+                        while ($obj = $this->db->fetch_object($result)) {
355
+
356
+                            $target_array[]=array('fk_contact'=>$obj->fk_contact,
357
+                            'lastname'=>$obj->lastname,
358
+                            'firstname'=>$obj->firstname,
359
+                            'email'=>$obj->email,
360
+                            'other'=>$obj->other,
361
+                            'source_url'=>$obj->source_url,
362
+                            'source_id'=>$obj->source_id,
363
+                            'source_type'=>$obj->source_type);
364
+                        }
365
+                    }
366
+                }
367
+                else
368
+                {
369
+                    $this->error=$this->db->lasterror();
370
+                    return -1;
371
+                }
372
+
373
+                $mailing_target->add_to_target($object->id, $target_array);
374
+            }
375
+        }
376
+
377
+        unset($object->context['createfromclone']);
378
+
379
+        // End
380
+        if (! $error)
381
+        {
382
+            $this->db->commit();
383
+            return $object->id;
384
+        }
385
+        else
386
+        {
387
+            $this->db->rollback();
388
+            return -1;
389
+        }
390
+    }
391
+
392
+    /**
393
+     *  Validate emailing
394
+     *
395
+     *  @param	User	$user      	Objet user qui valide
396
+     * 	@return	int					<0 if KO, >0 if OK
397
+     */
398
+    function valid($user)
399
+    {
400
+        $now=dol_now();
401
+
402
+        $sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
403
+        $sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
404
+        $sql .= " WHERE rowid = ".$this->id;
405
+
406
+        dol_syslog("Mailing::valid", LOG_DEBUG);
407
+        if ($this->db->query($sql))
408
+        {
409
+            return 1;
410
+        }
411
+        else
412
+        {
413
+            $this->error=$this->db->lasterror();
414
+            return -1;
415
+        }
416
+    }
417
+
418
+
419
+    /**
420
+     *  Delete emailing
421
+     *
422
+     *  @param	int		$rowid      id du mailing a supprimer
423
+     *  @return int         		1 en cas de succes
424
+     */
425
+    function delete($rowid)
426
+    {
427
+        $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
428
+        $sql.= " WHERE rowid = ".$rowid;
429
+
430
+        dol_syslog("Mailing::delete", LOG_DEBUG);
431
+        $resql=$this->db->query($sql);
432
+        if ($resql)
433
+        {
434
+            return $this->delete_targets();
435
+        }
436
+        else
437
+        {
438
+            $this->error=$this->db->lasterror();
439
+            return -1;
440
+        }
441
+    }
442 442
 
443 443
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
444
-	/**
445
-	 *  Delete targets emailing
446
-	 *
447
-	 *  @return int       1 if OK, 0 if error
448
-	 */
449
-	function delete_targets()
450
-	{
444
+    /**
445
+     *  Delete targets emailing
446
+     *
447
+     *  @return int       1 if OK, 0 if error
448
+     */
449
+    function delete_targets()
450
+    {
451 451
         // phpcs:enable
452
-		$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
453
-		$sql.= " WHERE fk_mailing = ".$this->id;
454
-
455
-		dol_syslog("Mailing::delete_targets", LOG_DEBUG);
456
-		$resql=$this->db->query($sql);
457
-		if ($resql)
458
-		{
459
-			return 1;
460
-		}
461
-		else
462
-		{
463
-			$this->error=$this->db->lasterror();
464
-			return 0;
465
-		}
466
-	}
452
+        $sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
453
+        $sql.= " WHERE fk_mailing = ".$this->id;
454
+
455
+        dol_syslog("Mailing::delete_targets", LOG_DEBUG);
456
+        $resql=$this->db->query($sql);
457
+        if ($resql)
458
+        {
459
+            return 1;
460
+        }
461
+        else
462
+        {
463
+            $this->error=$this->db->lasterror();
464
+            return 0;
465
+        }
466
+    }
467 467
 
468 468
 
469 469
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
470
-	/**
471
-	 *  Change status of each recipient
472
-	 *
473
-	 *	@param	User	$user      	Objet user qui valide
474
-	 *  @return int         		<0 if KO, >0 if OK
475
-	 */
476
-	function reset_targets_status($user)
477
-	{
470
+    /**
471
+     *  Change status of each recipient
472
+     *
473
+     *	@param	User	$user      	Objet user qui valide
474
+     *  @return int         		<0 if KO, >0 if OK
475
+     */
476
+    function reset_targets_status($user)
477
+    {
478 478
         // phpcs:enable
479
-		$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
480
-		$sql.= " SET statut = 0";
481
-		$sql.= " WHERE fk_mailing = ".$this->id;
482
-
483
-		dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
484
-		$resql=$this->db->query($sql);
485
-		if ($resql)
486
-		{
487
-			return 1;
488
-		}
489
-		else
490
-		{
491
-			$this->error=$this->db->lasterror();
492
-			return -1;
493
-		}
494
-	}
495
-
496
-
497
-	/**
498
-	 *  Count number of target with status
499
-	 *
500
-	 *  @param  string	$mode   Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error)
501
-	 *  @return int        		Nb of target with status
502
-	 */
503
-	function countNbOfTargets($mode)
504
-	{
505
-	    $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
506
-	    $sql.= " WHERE fk_mailing = ".$this->id;
507
-	    if ($mode == 'alreadysent') $sql.= " AND statut <> 0";
508
-	    elseif ($mode == 'alreadysentok') $sql.= " AND statut > 0";
509
-	    elseif ($mode == 'alreadysentko') $sql.= " AND statut = -1";
510
-	    else
511
-	    {
512
-	        $this->error='BadValueForParameterMode';
513
-	        return -2;
514
-	    }
515
-
516
-	    $resql=$this->db->query($sql);
517
-	    if ($resql)
518
-	    {
519
-	        $obj = $this->db->fetch_object($resql);
520
-	        if ($obj) return $obj->nb;
521
-	    }
522
-	    else
523
-	    {
524
-	        $this->error=$this->db->lasterror();
525
-	        return -1;
526
-	    }
527
-	    return 0;
528
-	}
529
-
530
-
531
-	/**
532
-	 *  Return a link to the object card (with optionaly the picto)
533
-	 *
534
-	 *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
535
-	 *	@param	string	$option						On what the link point to ('nolink', ...)
536
-	 *  @param	int  	$notooltip					1=Disable tooltip
537
-	 *  @param  string  $morecss            		Add more css on link
538
-	 *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
539
-	 *	@return	string								String with URL
540
-	 */
541
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
542
-	{
543
-		global $db, $conf, $langs, $hookmanager;
544
-		global $dolibarr_main_authentication, $dolibarr_main_demo;
545
-		global $menumanager;
546
-
547
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
548
-
549
-		$result = '';
550
-		$companylink = '';
551
-
552
-		$label = '<u>' . $langs->trans("ShowEmailing") . '</u>';
553
-		$label.= '<br>';
554
-		$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
555
-
556
-		$url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
557
-
558
-		if ($option != 'nolink')
559
-		{
560
-			// Add param to save lastsearch_values or not
561
-			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
562
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
563
-			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
564
-		}
565
-
566
-		$linkclose='';
567
-		if (empty($notooltip))
568
-		{
569
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
570
-			{
571
-				$label=$langs->trans("ShowEmailing");
572
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
573
-			}
574
-			$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
575
-			$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
576
-
577
-			/*
479
+        $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
480
+        $sql.= " SET statut = 0";
481
+        $sql.= " WHERE fk_mailing = ".$this->id;
482
+
483
+        dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
484
+        $resql=$this->db->query($sql);
485
+        if ($resql)
486
+        {
487
+            return 1;
488
+        }
489
+        else
490
+        {
491
+            $this->error=$this->db->lasterror();
492
+            return -1;
493
+        }
494
+    }
495
+
496
+
497
+    /**
498
+     *  Count number of target with status
499
+     *
500
+     *  @param  string	$mode   Mode ('alreadysent' = Sent success or error, 'alreadysentok' = Sent success, 'alreadysentko' = Sent error)
501
+     *  @return int        		Nb of target with status
502
+     */
503
+    function countNbOfTargets($mode)
504
+    {
505
+        $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
506
+        $sql.= " WHERE fk_mailing = ".$this->id;
507
+        if ($mode == 'alreadysent') $sql.= " AND statut <> 0";
508
+        elseif ($mode == 'alreadysentok') $sql.= " AND statut > 0";
509
+        elseif ($mode == 'alreadysentko') $sql.= " AND statut = -1";
510
+        else
511
+        {
512
+            $this->error='BadValueForParameterMode';
513
+            return -2;
514
+        }
515
+
516
+        $resql=$this->db->query($sql);
517
+        if ($resql)
518
+        {
519
+            $obj = $this->db->fetch_object($resql);
520
+            if ($obj) return $obj->nb;
521
+        }
522
+        else
523
+        {
524
+            $this->error=$this->db->lasterror();
525
+            return -1;
526
+        }
527
+        return 0;
528
+    }
529
+
530
+
531
+    /**
532
+     *  Return a link to the object card (with optionaly the picto)
533
+     *
534
+     *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
535
+     *	@param	string	$option						On what the link point to ('nolink', ...)
536
+     *  @param	int  	$notooltip					1=Disable tooltip
537
+     *  @param  string  $morecss            		Add more css on link
538
+     *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
539
+     *	@return	string								String with URL
540
+     */
541
+    function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
542
+    {
543
+        global $db, $conf, $langs, $hookmanager;
544
+        global $dolibarr_main_authentication, $dolibarr_main_demo;
545
+        global $menumanager;
546
+
547
+        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
548
+
549
+        $result = '';
550
+        $companylink = '';
551
+
552
+        $label = '<u>' . $langs->trans("ShowEmailing") . '</u>';
553
+        $label.= '<br>';
554
+        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
555
+
556
+        $url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
557
+
558
+        if ($option != 'nolink')
559
+        {
560
+            // Add param to save lastsearch_values or not
561
+            $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
562
+            if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
563
+            if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
564
+        }
565
+
566
+        $linkclose='';
567
+        if (empty($notooltip))
568
+        {
569
+            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
570
+            {
571
+                $label=$langs->trans("ShowEmailing");
572
+                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
573
+            }
574
+            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
575
+            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
576
+
577
+            /*
578 578
 			 $hookmanager->initHooks(array('myobjectdao'));
579 579
 			 $parameters=array('id'=>$this->id);
580 580
 			 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
581 581
 			 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
582 582
 			 */
583
-		}
584
-		else $linkclose = ($morecss?' class="'.$morecss.'"':'');
585
-
586
-		$linkstart = '<a href="'.$url.'"';
587
-		$linkstart.=$linkclose.'>';
588
-		$linkend='</a>';
589
-
590
-		$result .= $linkstart;
591
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
592
-		if ($withpicto != 2) $result.= $this->ref;
593
-		$result .= $linkend;
594
-		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
595
-
596
-		global $action;
597
-		$hookmanager->initHooks(array('emailingdao'));
598
-		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
599
-		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
600
-		if ($reshook > 0) $result = $hookmanager->resPrint;
601
-		else $result .= $hookmanager->resPrint;
602
-
603
-		return $result;
604
-	}
605
-
606
-	/**
607
-	 *  Return label of status of emailing (draft, validated, ...)
608
-	 *
609
-	 *  @param	int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
610
-	 *  @return string        			Label
611
-	 */
612
-	function getLibStatut($mode=0)
613
-	{
614
-		return $this->LibStatut($this->statut,$mode);
615
-	}
583
+        }
584
+        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
585
+
586
+        $linkstart = '<a href="'.$url.'"';
587
+        $linkstart.=$linkclose.'>';
588
+        $linkend='</a>';
589
+
590
+        $result .= $linkstart;
591
+        if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
592
+        if ($withpicto != 2) $result.= $this->ref;
593
+        $result .= $linkend;
594
+        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
595
+
596
+        global $action;
597
+        $hookmanager->initHooks(array('emailingdao'));
598
+        $parameters=array('id'=>$this->id, 'getnomurl'=>$result);
599
+        $reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
600
+        if ($reshook > 0) $result = $hookmanager->resPrint;
601
+        else $result .= $hookmanager->resPrint;
602
+
603
+        return $result;
604
+    }
605
+
606
+    /**
607
+     *  Return label of status of emailing (draft, validated, ...)
608
+     *
609
+     *  @param	int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
610
+     *  @return string        			Label
611
+     */
612
+    function getLibStatut($mode=0)
613
+    {
614
+        return $this->LibStatut($this->statut,$mode);
615
+    }
616 616
 
617 617
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
618
-	/**
619
-	 *  Renvoi le libelle d'un statut donne
620
-	 *
621
-	 *  @param	int		$statut        	Id statut
622
-	 *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
623
-	 *  @return string        			Label
624
-	 */
625
-	function LibStatut($statut,$mode=0)
626
-	{
618
+    /**
619
+     *  Renvoi le libelle d'un statut donne
620
+     *
621
+     *  @param	int		$statut        	Id statut
622
+     *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
623
+     *  @return string        			Label
624
+     */
625
+    function LibStatut($statut,$mode=0)
626
+    {
627 627
         // phpcs:enable
628
-		global $langs;
629
-		$langs->load('mails');
630
-
631
-		if ($mode == 0 || $mode == 1)
632
-		{
633
-			return $langs->trans($this->statuts[$statut]);
634
-		}
635
-		elseif ($mode == 2)
636
-		{
637
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
638
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
639
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
640
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
641
-		}
642
-		elseif ($mode == 3)
643
-		{
644
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
645
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1');
646
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
647
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
648
-		}
649
-		elseif ($mode == 4)
650
-		{
651
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
652
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
653
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
654
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
655
-		}
656
-		elseif ($mode == 5)
657
-		{
658
-			if ($statut == 0)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
659
-			if ($statut == 1)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
660
-			if ($statut == 2)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
661
-			if ($statut == 3)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
662
-		}
663
-	}
664
-
665
-
666
-	/**
667
-	 *  Renvoi le libelle d'un statut donne
668
-	 *  TODO Add class mailin_target.class.php
669
-	 *
670
-	 *  @param	int		$statut        	Id statut
671
-	 *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
672
-	 *  @param	strin	$desc			Desc error
673
-	 *  @return string        			Label
674
-	 */
675
-	public static function libStatutDest($statut,$mode=0,$desc='')
676
-	{
677
-		global $langs;
678
-		$langs->load('mails');
679
-
680
-		if ($mode == 0)
681
-		{
682
-			return $langs->trans('MailingStatusError');
683
-		}
684
-		elseif ($mode == 1)
685
-		{
686
-			return $langs->trans('MailingStatusSent');
687
-		}
688
-		elseif ($mode == 2)
689
-		{
690
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
691
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
692
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
693
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
694
-		}
695
-		elseif ($mode == 3)
696
-		{
697
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
698
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
699
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
700
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
701
-		}
702
-		elseif ($mode == 4)
703
-		{
704
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
705
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
706
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
707
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
708
-		}
709
-		elseif ($mode == 5)
710
-		{
711
-		    if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
712
-		    if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
713
-		    if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
714
-		    if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
715
-		}
716
-		elseif ($mode == 6)
717
-		{
718
-		    if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
719
-		    if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
720
-		    if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
721
-		    if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
722
-		}
723
-	}
628
+        global $langs;
629
+        $langs->load('mails');
630
+
631
+        if ($mode == 0 || $mode == 1)
632
+        {
633
+            return $langs->trans($this->statuts[$statut]);
634
+        }
635
+        elseif ($mode == 2)
636
+        {
637
+            if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
638
+            if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
639
+            if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
640
+            if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
641
+        }
642
+        elseif ($mode == 3)
643
+        {
644
+            if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
645
+            if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1');
646
+            if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
647
+            if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
648
+        }
649
+        elseif ($mode == 4)
650
+        {
651
+            if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
652
+            if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
653
+            if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
654
+            if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
655
+        }
656
+        elseif ($mode == 5)
657
+        {
658
+            if ($statut == 0)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
659
+            if ($statut == 1)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
660
+            if ($statut == 2)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
661
+            if ($statut == 3)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
662
+        }
663
+    }
664
+
665
+
666
+    /**
667
+     *  Renvoi le libelle d'un statut donne
668
+     *  TODO Add class mailin_target.class.php
669
+     *
670
+     *  @param	int		$statut        	Id statut
671
+     *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
672
+     *  @param	strin	$desc			Desc error
673
+     *  @return string        			Label
674
+     */
675
+    public static function libStatutDest($statut,$mode=0,$desc='')
676
+    {
677
+        global $langs;
678
+        $langs->load('mails');
679
+
680
+        if ($mode == 0)
681
+        {
682
+            return $langs->trans('MailingStatusError');
683
+        }
684
+        elseif ($mode == 1)
685
+        {
686
+            return $langs->trans('MailingStatusSent');
687
+        }
688
+        elseif ($mode == 2)
689
+        {
690
+            if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
691
+            if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
692
+            if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
693
+            if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
694
+        }
695
+        elseif ($mode == 3)
696
+        {
697
+            if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
698
+            if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
699
+            if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
700
+            if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
701
+        }
702
+        elseif ($mode == 4)
703
+        {
704
+            if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
705
+            if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
706
+            if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
707
+            if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
708
+        }
709
+        elseif ($mode == 5)
710
+        {
711
+            if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
712
+            if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
713
+            if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
714
+            if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
715
+        }
716
+        elseif ($mode == 6)
717
+        {
718
+            if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
719
+            if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
720
+            if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
721
+            if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
722
+        }
723
+    }
724 724
 }
Please login to merge, or discard this patch.
Spacing   +146 added lines, -146 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  *	\brief      File of class to manage emailings module
24 24
  */
25 25
 
26
-require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php';
26
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 27
 
28 28
 
29 29
 /**
@@ -34,17 +34,17 @@  discard block
 block discarded – undo
34 34
 	/**
35 35
 	 * @var string ID to identify managed object
36 36
 	 */
37
-	public $element='mailing';
37
+	public $element = 'mailing';
38 38
 
39 39
 	/**
40 40
 	 * @var string Name of table without prefix where object is stored
41 41
 	 */
42
-	public $table_element='mailing';
42
+	public $table_element = 'mailing';
43 43
 
44 44
 	/**
45 45
 	 * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
46 46
 	 */
47
-	public $picto='email';
47
+	public $picto = 'email';
48 48
 
49 49
 	public $titre;
50 50
 	public $sujet;
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	public $bgcolor;
54 54
 	public $bgimage;
55 55
 
56
-	public $statut;       // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
56
+	public $statut; // Status 0=Draft, 1=Validated, 2=Sent partially, 3=Sent completely
57 57
 
58 58
 	public $email_from;
59 59
 	public $email_replyto;
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 	public $date_creat;
71 71
 	public $date_valid;
72 72
 
73
-	public $extraparams=array();
73
+	public $extraparams = array();
74 74
 
75
-	public $statut_dest=array();
76
-	public $statuts=array();
75
+	public $statut_dest = array();
76
+	public $statuts = array();
77 77
 
78 78
 
79 79
     /**
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 		$this->statut_dest[0] = 'MailingStatusNotSent';
96 96
 		$this->statut_dest[1] = 'MailingStatusSent';
97 97
 		$this->statut_dest[2] = 'MailingStatusRead';
98
-		$this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe';    // Read but ask to not be contacted anymore
98
+		$this->statut_dest[3] = 'MailingStatusReadAndUnsubscribe'; // Read but ask to not be contacted anymore
99 99
 	}
100 100
 
101 101
 	/**
@@ -110,28 +110,28 @@  discard block
 block discarded – undo
110 110
 
111 111
 		$this->db->begin();
112 112
 
113
-		$this->titre=trim($this->titre);
114
-		$this->email_from=trim($this->email_from);
113
+		$this->titre = trim($this->titre);
114
+		$this->email_from = trim($this->email_from);
115 115
 
116
-		if (! $this->email_from)
116
+		if (!$this->email_from)
117 117
 		{
118 118
 			$this->error = $langs->trans("ErrorMailFromRequired");
119 119
 			return -1;
120 120
 		}
121 121
 
122
-		$now=dol_now();
122
+		$now = dol_now();
123 123
 
124 124
 		$sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing";
125 125
 		$sql .= " (date_creat, fk_user_creat, entity)";
126 126
 		$sql .= " VALUES ('".$this->db->idate($now)."', ".$user->id.", ".$conf->entity.")";
127 127
 
128
-		if (! $this->titre)
128
+		if (!$this->titre)
129 129
 		{
130 130
 			$this->titre = $langs->trans("NoTitle");
131 131
 		}
132 132
 
133 133
 		dol_syslog("Mailing::Create", LOG_DEBUG);
134
-		$result=$this->db->query($sql);
134
+		$result = $this->db->query($sql);
135 135
 		if ($result)
136 136
 		{
137 137
 			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."mailing");
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 			}
143 143
 			else
144 144
 			{
145
-				$this->error=$this->db->lasterror();
145
+				$this->error = $this->db->lasterror();
146 146
 				$this->db->rollback();
147 147
 				return -1;
148 148
 			}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		}
152 152
 		else
153 153
 		{
154
-			$this->error=$this->db->lasterror();
154
+			$this->error = $this->db->lasterror();
155 155
 			$this->db->rollback();
156 156
 			return -1;
157 157
 		}
@@ -172,19 +172,19 @@  discard block
 block discarded – undo
172 172
 		$sql .= ", email_from = '".$this->db->escape($this->email_from)."'";
173 173
 		$sql .= ", email_replyto = '".$this->db->escape($this->email_replyto)."'";
174 174
 		$sql .= ", email_errorsto = '".$this->db->escape($this->email_errorsto)."'";
175
-		$sql .= ", bgcolor = '".($this->bgcolor?$this->db->escape($this->bgcolor):null)."'";
176
-		$sql .= ", bgimage = '".($this->bgimage?$this->db->escape($this->bgimage):null)."'";
175
+		$sql .= ", bgcolor = '".($this->bgcolor ? $this->db->escape($this->bgcolor) : null)."'";
176
+		$sql .= ", bgimage = '".($this->bgimage ? $this->db->escape($this->bgimage) : null)."'";
177 177
 		$sql .= " WHERE rowid = ".$this->id;
178 178
 
179 179
 		dol_syslog("Mailing::Update", LOG_DEBUG);
180
-		$result=$this->db->query($sql);
180
+		$result = $this->db->query($sql);
181 181
 		if ($result)
182 182
 		{
183 183
 			return 1;
184 184
 		}
185 185
 		else
186 186
 		{
187
-			$this->error=$this->db->lasterror();
187
+			$this->error = $this->db->lasterror();
188 188
 			return -1;
189 189
 		}
190 190
 	}
@@ -200,43 +200,43 @@  discard block
 block discarded – undo
200 200
 		global $conf;
201 201
 
202 202
 		$sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage";
203
-		$sql.= ", m.email_from, m.email_replyto, m.email_errorsto";
204
-		$sql.= ", m.statut, m.nbemail";
205
-		$sql.= ", m.fk_user_creat, m.fk_user_valid";
206
-		$sql.= ", m.date_creat";
207
-		$sql.= ", m.date_valid";
208
-		$sql.= ", m.date_envoi";
209
-		$sql.= ", m.extraparams";
210
-		$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
211
-		$sql.= " WHERE m.rowid = ".(int) $rowid;
203
+		$sql .= ", m.email_from, m.email_replyto, m.email_errorsto";
204
+		$sql .= ", m.statut, m.nbemail";
205
+		$sql .= ", m.fk_user_creat, m.fk_user_valid";
206
+		$sql .= ", m.date_creat";
207
+		$sql .= ", m.date_valid";
208
+		$sql .= ", m.date_envoi";
209
+		$sql .= ", m.extraparams";
210
+		$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
211
+		$sql .= " WHERE m.rowid = ".(int) $rowid;
212 212
 
213 213
 		dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
214
-		$result=$this->db->query($sql);
214
+		$result = $this->db->query($sql);
215 215
 		if ($result)
216 216
 		{
217 217
 			if ($this->db->num_rows($result))
218 218
 			{
219 219
 				$obj = $this->db->fetch_object($result);
220 220
 
221
-				$this->id				= $obj->rowid;
222
-				$this->ref				= $obj->rowid;
223
-				$this->statut			= $obj->statut;
224
-				$this->nbemail			= $obj->nbemail;
221
+				$this->id = $obj->rowid;
222
+				$this->ref = $obj->rowid;
223
+				$this->statut = $obj->statut;
224
+				$this->nbemail = $obj->nbemail;
225 225
 				$this->titre			= $obj->titre;
226 226
 
227 227
 				$this->sujet			= $obj->sujet;
228 228
 				if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
229 229
 					$this->body				= dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
230
-				}else {
230
+				} else {
231 231
 					$this->body				= $obj->body;
232 232
 				}
233 233
 
234 234
 				$this->bgcolor			= $obj->bgcolor;
235 235
 				$this->bgimage			= $obj->bgimage;
236 236
 
237
-				$this->email_from		= $obj->email_from;
238
-				$this->email_replyto	= $obj->email_replyto;
239
-				$this->email_errorsto	= $obj->email_errorsto;
237
+				$this->email_from = $obj->email_from;
238
+				$this->email_replyto = $obj->email_replyto;
239
+				$this->email_errorsto = $obj->email_errorsto;
240 240
 
241 241
 				$this->user_creat		= $obj->fk_user_creat;
242 242
 				$this->user_valid		= $obj->fk_user_valid;
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 				$this->date_valid		= $this->db->jdate($obj->date_valid);
246 246
 				$this->date_envoi		= $this->db->jdate($obj->date_envoi);
247 247
 
248
-				$this->extraparams		= (array) json_decode($obj->extraparams, true);
248
+				$this->extraparams = (array) json_decode($obj->extraparams, true);
249 249
 
250 250
 				return 1;
251 251
 			}
@@ -271,25 +271,25 @@  discard block
 block discarded – undo
271 271
 	 *	@param	int		$option2		Not used
272 272
 	 *	@return	int						New id of clone
273 273
 	 */
274
-	function createFromClone($fromid,$option1,$option2)
274
+	function createFromClone($fromid, $option1, $option2)
275 275
 	{
276
-		global $user,$langs;
276
+		global $user, $langs;
277 277
 
278
-		$error=0;
278
+		$error = 0;
279 279
 
280
-		$object=new Mailing($this->db);
280
+		$object = new Mailing($this->db);
281 281
 
282
-		$object->context['createfromclone']='createfromclone';
282
+		$object->context['createfromclone'] = 'createfromclone';
283 283
 
284 284
 		$this->db->begin();
285 285
 
286 286
 		// Load source object
287 287
 		$object->fetch($fromid);
288
-		$object->id=0;
289
-		$object->statut=0;
288
+		$object->id = 0;
289
+		$object->statut = 0;
290 290
 
291 291
 		// Clear fields
292
-		$object->titre=$langs->trans("CopyOf").' '.$object->titre.' '.dol_print_date(dol_now());
292
+		$object->titre = $langs->trans("CopyOf").' '.$object->titre.' '.dol_print_date(dol_now());
293 293
 
294 294
 		// If no option copy content
295 295
 		if (empty($option1))
@@ -314,46 +314,46 @@  discard block
 block discarded – undo
314 314
 		}
315 315
 
316 316
 		// Create clone
317
-		$result=$object->create($user);
317
+		$result = $object->create($user);
318 318
 
319 319
 		// Other options
320 320
 		if ($result < 0)
321 321
 		{
322
-			$this->error=$object->error;
322
+			$this->error = $object->error;
323 323
 			$error++;
324 324
 		}
325 325
 
326
-		if (! $error)
326
+		if (!$error)
327 327
 		{
328 328
 			//Clone target
329 329
 			if (!empty($option2)) {
330 330
 
331
-				require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php';
331
+				require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
332 332
 
333 333
 				$mailing_target = new MailingTargets($this->db);
334 334
 
335
-				$target_array=array();
335
+				$target_array = array();
336 336
 
337 337
 				$sql = "SELECT fk_contact, ";
338
-				$sql.=" lastname,   ";
339
-				$sql.=" firstname,";
340
-				$sql.=" email,";
341
-				$sql.=" other,";
342
-				$sql.=" source_url,";
343
-				$sql.=" source_id ,";
344
-				$sql.=" source_type ";
345
-				$sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles ";
346
-				$sql.= " WHERE fk_mailing = ".$fromid;
338
+				$sql .= " lastname,   ";
339
+				$sql .= " firstname,";
340
+				$sql .= " email,";
341
+				$sql .= " other,";
342
+				$sql .= " source_url,";
343
+				$sql .= " source_id ,";
344
+				$sql .= " source_type ";
345
+				$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles ";
346
+				$sql .= " WHERE fk_mailing = ".$fromid;
347 347
 
348 348
 				dol_syslog(get_class($this)."::createFromClone", LOG_DEBUG);
349
-				$result=$this->db->query($sql);
349
+				$result = $this->db->query($sql);
350 350
 				if ($result)
351 351
 				{
352 352
 					if ($this->db->num_rows($result))
353 353
 					{
354 354
 						while ($obj = $this->db->fetch_object($result)) {
355 355
 
356
-							$target_array[]=array('fk_contact'=>$obj->fk_contact,
356
+							$target_array[] = array('fk_contact'=>$obj->fk_contact,
357 357
 							'lastname'=>$obj->lastname,
358 358
 							'firstname'=>$obj->firstname,
359 359
 							'email'=>$obj->email,
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 				}
367 367
 				else
368 368
 				{
369
-					$this->error=$this->db->lasterror();
369
+					$this->error = $this->db->lasterror();
370 370
 					return -1;
371 371
 				}
372 372
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 		unset($object->context['createfromclone']);
378 378
 
379 379
 		// End
380
-		if (! $error)
380
+		if (!$error)
381 381
 		{
382 382
 			$this->db->commit();
383 383
 			return $object->id;
@@ -397,7 +397,7 @@  discard block
 block discarded – undo
397 397
 	 */
398 398
 	function valid($user)
399 399
 	{
400
-		$now=dol_now();
400
+		$now = dol_now();
401 401
 
402 402
 		$sql = "UPDATE ".MAIN_DB_PREFIX."mailing ";
403 403
 		$sql .= " SET statut = 1, date_valid = '".$this->db->idate($now)."', fk_user_valid=".$user->id;
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
 		}
411 411
 		else
412 412
 		{
413
-			$this->error=$this->db->lasterror();
413
+			$this->error = $this->db->lasterror();
414 414
 			return -1;
415 415
 		}
416 416
 	}
@@ -425,17 +425,17 @@  discard block
 block discarded – undo
425 425
 	function delete($rowid)
426 426
 	{
427 427
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing";
428
-		$sql.= " WHERE rowid = ".$rowid;
428
+		$sql .= " WHERE rowid = ".$rowid;
429 429
 
430 430
 		dol_syslog("Mailing::delete", LOG_DEBUG);
431
-		$resql=$this->db->query($sql);
431
+		$resql = $this->db->query($sql);
432 432
 		if ($resql)
433 433
 		{
434 434
 			return $this->delete_targets();
435 435
 		}
436 436
 		else
437 437
 		{
438
-			$this->error=$this->db->lasterror();
438
+			$this->error = $this->db->lasterror();
439 439
 			return -1;
440 440
 		}
441 441
 	}
@@ -450,17 +450,17 @@  discard block
 block discarded – undo
450 450
 	{
451 451
         // phpcs:enable
452 452
 		$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles";
453
-		$sql.= " WHERE fk_mailing = ".$this->id;
453
+		$sql .= " WHERE fk_mailing = ".$this->id;
454 454
 
455 455
 		dol_syslog("Mailing::delete_targets", LOG_DEBUG);
456
-		$resql=$this->db->query($sql);
456
+		$resql = $this->db->query($sql);
457 457
 		if ($resql)
458 458
 		{
459 459
 			return 1;
460 460
 		}
461 461
 		else
462 462
 		{
463
-			$this->error=$this->db->lasterror();
463
+			$this->error = $this->db->lasterror();
464 464
 			return 0;
465 465
 		}
466 466
 	}
@@ -477,18 +477,18 @@  discard block
 block discarded – undo
477 477
 	{
478 478
         // phpcs:enable
479 479
 		$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
480
-		$sql.= " SET statut = 0";
481
-		$sql.= " WHERE fk_mailing = ".$this->id;
480
+		$sql .= " SET statut = 0";
481
+		$sql .= " WHERE fk_mailing = ".$this->id;
482 482
 
483 483
 		dol_syslog("Mailing::reset_targets_status", LOG_DEBUG);
484
-		$resql=$this->db->query($sql);
484
+		$resql = $this->db->query($sql);
485 485
 		if ($resql)
486 486
 		{
487 487
 			return 1;
488 488
 		}
489 489
 		else
490 490
 		{
491
-			$this->error=$this->db->lasterror();
491
+			$this->error = $this->db->lasterror();
492 492
 			return -1;
493 493
 		}
494 494
 	}
@@ -503,17 +503,17 @@  discard block
 block discarded – undo
503 503
 	function countNbOfTargets($mode)
504 504
 	{
505 505
 	    $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
506
-	    $sql.= " WHERE fk_mailing = ".$this->id;
507
-	    if ($mode == 'alreadysent') $sql.= " AND statut <> 0";
508
-	    elseif ($mode == 'alreadysentok') $sql.= " AND statut > 0";
509
-	    elseif ($mode == 'alreadysentko') $sql.= " AND statut = -1";
506
+	    $sql .= " WHERE fk_mailing = ".$this->id;
507
+	    if ($mode == 'alreadysent') $sql .= " AND statut <> 0";
508
+	    elseif ($mode == 'alreadysentok') $sql .= " AND statut > 0";
509
+	    elseif ($mode == 'alreadysentko') $sql .= " AND statut = -1";
510 510
 	    else
511 511
 	    {
512
-	        $this->error='BadValueForParameterMode';
512
+	        $this->error = 'BadValueForParameterMode';
513 513
 	        return -2;
514 514
 	    }
515 515
 
516
-	    $resql=$this->db->query($sql);
516
+	    $resql = $this->db->query($sql);
517 517
 	    if ($resql)
518 518
 	    {
519 519
 	        $obj = $this->db->fetch_object($resql);
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
 	    }
522 522
 	    else
523 523
 	    {
524
-	        $this->error=$this->db->lasterror();
524
+	        $this->error = $this->db->lasterror();
525 525
 	        return -1;
526 526
 	    }
527 527
 	    return 0;
@@ -538,41 +538,41 @@  discard block
 block discarded – undo
538 538
 	 *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
539 539
 	 *	@return	string								String with URL
540 540
 	 */
541
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
541
+	function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
542 542
 	{
543 543
 		global $db, $conf, $langs, $hookmanager;
544 544
 		global $dolibarr_main_authentication, $dolibarr_main_demo;
545 545
 		global $menumanager;
546 546
 
547
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
547
+		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
548 548
 
549 549
 		$result = '';
550 550
 		$companylink = '';
551 551
 
552
-		$label = '<u>' . $langs->trans("ShowEmailing") . '</u>';
553
-		$label.= '<br>';
554
-		$label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
552
+		$label = '<u>'.$langs->trans("ShowEmailing").'</u>';
553
+		$label .= '<br>';
554
+		$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
555 555
 
556 556
 		$url = DOL_URL_ROOT.'/comm/mailing/card.php?id='.$this->id;
557 557
 
558 558
 		if ($option != 'nolink')
559 559
 		{
560 560
 			// Add param to save lastsearch_values or not
561
-			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
562
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
563
-			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
561
+			$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
562
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
563
+			if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
564 564
 		}
565 565
 
566
-		$linkclose='';
566
+		$linkclose = '';
567 567
 		if (empty($notooltip))
568 568
 		{
569
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
569
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
570 570
 			{
571
-				$label=$langs->trans("ShowEmailing");
572
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
571
+				$label = $langs->trans("ShowEmailing");
572
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
573 573
 			}
574
-			$linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
575
-			$linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
574
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
575
+			$linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
576 576
 
577 577
 			/*
578 578
 			 $hookmanager->initHooks(array('myobjectdao'));
@@ -581,22 +581,22 @@  discard block
 block discarded – undo
581 581
 			 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
582 582
 			 */
583 583
 		}
584
-		else $linkclose = ($morecss?' class="'.$morecss.'"':'');
584
+		else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
585 585
 
586 586
 		$linkstart = '<a href="'.$url.'"';
587
-		$linkstart.=$linkclose.'>';
588
-		$linkend='</a>';
587
+		$linkstart .= $linkclose.'>';
588
+		$linkend = '</a>';
589 589
 
590 590
 		$result .= $linkstart;
591
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
592
-		if ($withpicto != 2) $result.= $this->ref;
591
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
592
+		if ($withpicto != 2) $result .= $this->ref;
593 593
 		$result .= $linkend;
594 594
 		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
595 595
 
596 596
 		global $action;
597 597
 		$hookmanager->initHooks(array('emailingdao'));
598
-		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
599
-		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
598
+		$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
599
+		$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
600 600
 		if ($reshook > 0) $result = $hookmanager->resPrint;
601 601
 		else $result .= $hookmanager->resPrint;
602 602
 
@@ -609,9 +609,9 @@  discard block
 block discarded – undo
609 609
 	 *  @param	int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
610 610
 	 *  @return string        			Label
611 611
 	 */
612
-	function getLibStatut($mode=0)
612
+	function getLibStatut($mode = 0)
613 613
 	{
614
-		return $this->LibStatut($this->statut,$mode);
614
+		return $this->LibStatut($this->statut, $mode);
615 615
 	}
616 616
 
617 617
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 	 *  @param  int		$mode          	0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
623 623
 	 *  @return string        			Label
624 624
 	 */
625
-	function LibStatut($statut,$mode=0)
625
+	function LibStatut($statut, $mode = 0)
626 626
 	{
627 627
         // phpcs:enable
628 628
 		global $langs;
@@ -634,31 +634,31 @@  discard block
 block discarded – undo
634 634
 		}
635 635
 		elseif ($mode == 2)
636 636
 		{
637
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
638
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
639
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
640
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
637
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0').' '.$langs->trans($this->statuts[$statut]);
638
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut1').' '.$langs->trans($this->statuts[$statut]);
639
+			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]), 'statut3').' '.$langs->trans($this->statuts[$statut]);
640
+			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]), 'statut6').' '.$langs->trans($this->statuts[$statut]);
641 641
 		}
642 642
 		elseif ($mode == 3)
643 643
 		{
644
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
645
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1');
646
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
647
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
644
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0');
645
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut1');
646
+			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]), 'statut3');
647
+			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]), 'statut6');
648 648
 		}
649 649
 		elseif ($mode == 4)
650 650
 		{
651
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
652
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
653
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
654
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
651
+			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]), 'statut0').' '.$langs->trans($this->statuts[$statut]);
652
+			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]), 'statut1').' '.$langs->trans($this->statuts[$statut]);
653
+			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]), 'statut3').' '.$langs->trans($this->statuts[$statut]);
654
+			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]), 'statut6').' '.$langs->trans($this->statuts[$statut]);
655 655
 		}
656 656
 		elseif ($mode == 5)
657 657
 		{
658
-			if ($statut == 0)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
659
-			if ($statut == 1)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
660
-			if ($statut == 2)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
661
-			if ($statut == 3)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
658
+			if ($statut == 0)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut0');
659
+			if ($statut == 1)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut1');
660
+			if ($statut == 2)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut3');
661
+			if ($statut == 3)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]), 'statut6');
662 662
 		}
663 663
 	}
664 664
 
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 	 *  @param	strin	$desc			Desc error
673 673
 	 *  @return string        			Label
674 674
 	 */
675
-	public static function libStatutDest($statut,$mode=0,$desc='')
675
+	public static function libStatutDest($statut, $mode = 0, $desc = '')
676 676
 	{
677 677
 		global $langs;
678 678
 		$langs->load('mails');
@@ -687,38 +687,38 @@  discard block
 block discarded – undo
687 687
 		}
688 688
 		elseif ($mode == 2)
689 689
 		{
690
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
691
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
692
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
693
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
690
+			if ($statut == -1) return $langs->trans("MailingStatusError").' '.img_error($desc);
691
+			if ($statut == 1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"), 'statut6');
692
+			if ($statut == 2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"), 'statut4');
693
+			if ($statut == 3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"), 'statut3');
694 694
 		}
695 695
 		elseif ($mode == 3)
696 696
 		{
697
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
698
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
699
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
700
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
697
+			if ($statut == -1) return $langs->trans("MailingStatusError").' '.img_error($desc);
698
+			if ($statut == 1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"), 'statut6');
699
+			if ($statut == 2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"), 'statut4');
700
+			if ($statut == 3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"), 'statut3');
701 701
 		}
702 702
 		elseif ($mode == 4)
703 703
 		{
704
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
705
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
706
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
707
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
704
+			if ($statut == -1) return $langs->trans("MailingStatusError").' '.img_error($desc);
705
+			if ($statut == 1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"), 'statut6');
706
+			if ($statut == 2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"), 'statut4');
707
+			if ($statut == 3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"), 'statut3');
708 708
 		}
709 709
 		elseif ($mode == 5)
710 710
 		{
711
-		    if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
712
-		    if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
713
-		    if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
714
-		    if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
711
+		    if ($statut == -1) return $langs->trans("MailingStatusError").' '.img_error($desc);
712
+		    if ($statut == 1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"), 'statut6');
713
+		    if ($statut == 2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"), 'statut4');
714
+		    if ($statut == 3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"), 'statut3');
715 715
 		}
716 716
 		elseif ($mode == 6)
717 717
 		{
718
-		    if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
719
-		    if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
720
-		    if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
721
-		    if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
718
+		    if ($statut == -1) return $langs->trans("MailingStatusError").' '.img_error($desc);
719
+		    if ($statut == 1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"), 'statut6');
720
+		    if ($statut == 2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"), 'statut4');
721
+		    if ($statut == 3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"), 'statut3');
722 722
 		}
723 723
 	}
724 724
 }
Please login to merge, or discard this patch.
Braces   +166 added lines, -96 removed lines patch added patch discarded remove patch
@@ -139,8 +139,7 @@  discard block
 block discarded – undo
139 139
 			if ($this->update($user) > 0)
140 140
 			{
141 141
 				$this->db->commit();
142
-			}
143
-			else
142
+			} else
144 143
 			{
145 144
 				$this->error=$this->db->lasterror();
146 145
 				$this->db->rollback();
@@ -148,8 +147,7 @@  discard block
 block discarded – undo
148 147
 			}
149 148
 
150 149
 			return $this->id;
151
-		}
152
-		else
150
+		} else
153 151
 		{
154 152
 			$this->error=$this->db->lasterror();
155 153
 			$this->db->rollback();
@@ -181,8 +179,7 @@  discard block
 block discarded – undo
181 179
 		if ($result)
182 180
 		{
183 181
 			return 1;
184
-		}
185
-		else
182
+		} else
186 183
 		{
187 184
 			$this->error=$this->db->lasterror();
188 185
 			return -1;
@@ -227,7 +224,7 @@  discard block
 block discarded – undo
227 224
 				$this->sujet			= $obj->sujet;
228 225
 				if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) {
229 226
 					$this->body				= dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401);
230
-				}else {
227
+				} else {
231 228
 					$this->body				= $obj->body;
232 229
 				}
233 230
 
@@ -248,14 +245,12 @@  discard block
 block discarded – undo
248 245
 				$this->extraparams		= (array) json_decode($obj->extraparams, true);
249 246
 
250 247
 				return 1;
251
-			}
252
-			else
248
+			} else
253 249
 			{
254 250
 				dol_syslog(get_class($this)."::fetch Erreur -1");
255 251
 				return -1;
256 252
 			}
257
-		}
258
-		else
253
+		} else
259 254
 		{
260 255
 			dol_syslog(get_class($this)."::fetch Erreur -2");
261 256
 			return -2;
@@ -363,8 +358,7 @@  discard block
 block discarded – undo
363 358
 							'source_type'=>$obj->source_type);
364 359
 						}
365 360
 					}
366
-				}
367
-				else
361
+				} else
368 362
 				{
369 363
 					$this->error=$this->db->lasterror();
370 364
 					return -1;
@@ -381,8 +375,7 @@  discard block
 block discarded – undo
381 375
 		{
382 376
 			$this->db->commit();
383 377
 			return $object->id;
384
-		}
385
-		else
378
+		} else
386 379
 		{
387 380
 			$this->db->rollback();
388 381
 			return -1;
@@ -407,8 +400,7 @@  discard block
 block discarded – undo
407 400
 		if ($this->db->query($sql))
408 401
 		{
409 402
 			return 1;
410
-		}
411
-		else
403
+		} else
412 404
 		{
413 405
 			$this->error=$this->db->lasterror();
414 406
 			return -1;
@@ -432,8 +424,7 @@  discard block
 block discarded – undo
432 424
 		if ($resql)
433 425
 		{
434 426
 			return $this->delete_targets();
435
-		}
436
-		else
427
+		} else
437 428
 		{
438 429
 			$this->error=$this->db->lasterror();
439 430
 			return -1;
@@ -457,8 +448,7 @@  discard block
 block discarded – undo
457 448
 		if ($resql)
458 449
 		{
459 450
 			return 1;
460
-		}
461
-		else
451
+		} else
462 452
 		{
463 453
 			$this->error=$this->db->lasterror();
464 454
 			return 0;
@@ -485,8 +475,7 @@  discard block
 block discarded – undo
485 475
 		if ($resql)
486 476
 		{
487 477
 			return 1;
488
-		}
489
-		else
478
+		} else
490 479
 		{
491 480
 			$this->error=$this->db->lasterror();
492 481
 			return -1;
@@ -504,10 +493,13 @@  discard block
 block discarded – undo
504 493
 	{
505 494
 	    $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX."mailing_cibles";
506 495
 	    $sql.= " WHERE fk_mailing = ".$this->id;
507
-	    if ($mode == 'alreadysent') $sql.= " AND statut <> 0";
508
-	    elseif ($mode == 'alreadysentok') $sql.= " AND statut > 0";
509
-	    elseif ($mode == 'alreadysentko') $sql.= " AND statut = -1";
510
-	    else
496
+	    if ($mode == 'alreadysent') {
497
+	        $sql.= " AND statut <> 0";
498
+	    } elseif ($mode == 'alreadysentok') {
499
+	        $sql.= " AND statut > 0";
500
+	    } elseif ($mode == 'alreadysentko') {
501
+	        $sql.= " AND statut = -1";
502
+	    } else
511 503
 	    {
512 504
 	        $this->error='BadValueForParameterMode';
513 505
 	        return -2;
@@ -517,9 +509,10 @@  discard block
 block discarded – undo
517 509
 	    if ($resql)
518 510
 	    {
519 511
 	        $obj = $this->db->fetch_object($resql);
520
-	        if ($obj) return $obj->nb;
521
-	    }
522
-	    else
512
+	        if ($obj) {
513
+	            return $obj->nb;
514
+	        }
515
+	    } else
523 516
 	    {
524 517
 	        $this->error=$this->db->lasterror();
525 518
 	        return -1;
@@ -544,7 +537,10 @@  discard block
 block discarded – undo
544 537
 		global $dolibarr_main_authentication, $dolibarr_main_demo;
545 538
 		global $menumanager;
546 539
 
547
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
540
+		if (! empty($conf->dol_no_mouse_hover)) {
541
+		    $notooltip=1;
542
+		}
543
+		// Force disable tooltips
548 544
 
549 545
 		$result = '';
550 546
 		$companylink = '';
@@ -559,8 +555,12 @@  discard block
 block discarded – undo
559 555
 		{
560 556
 			// Add param to save lastsearch_values or not
561 557
 			$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
562
-			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
563
-			if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
558
+			if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
559
+			    $add_save_lastsearch_values=1;
560
+			}
561
+			if ($add_save_lastsearch_values) {
562
+			    $url.='&save_lastsearch_values=1';
563
+			}
564 564
 		}
565 565
 
566 566
 		$linkclose='';
@@ -580,16 +580,21 @@  discard block
 block discarded – undo
580 580
 			 $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
581 581
 			 if ($reshook > 0) $linkclose = $hookmanager->resPrint;
582 582
 			 */
583
+		} else {
584
+		    $linkclose = ($morecss?' class="'.$morecss.'"':'');
583 585
 		}
584
-		else $linkclose = ($morecss?' class="'.$morecss.'"':'');
585 586
 
586 587
 		$linkstart = '<a href="'.$url.'"';
587 588
 		$linkstart.=$linkclose.'>';
588 589
 		$linkend='</a>';
589 590
 
590 591
 		$result .= $linkstart;
591
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
592
-		if ($withpicto != 2) $result.= $this->ref;
592
+		if ($withpicto) {
593
+		    $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
594
+		}
595
+		if ($withpicto != 2) {
596
+		    $result.= $this->ref;
597
+		}
593 598
 		$result .= $linkend;
594 599
 		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
595 600
 
@@ -597,8 +602,11 @@  discard block
 block discarded – undo
597 602
 		$hookmanager->initHooks(array('emailingdao'));
598 603
 		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
599 604
 		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
600
-		if ($reshook > 0) $result = $hookmanager->resPrint;
601
-		else $result .= $hookmanager->resPrint;
605
+		if ($reshook > 0) {
606
+		    $result = $hookmanager->resPrint;
607
+		} else {
608
+		    $result .= $hookmanager->resPrint;
609
+		}
602 610
 
603 611
 		return $result;
604 612
 	}
@@ -631,34 +639,62 @@  discard block
 block discarded – undo
631 639
 		if ($mode == 0 || $mode == 1)
632 640
 		{
633 641
 			return $langs->trans($this->statuts[$statut]);
634
-		}
635
-		elseif ($mode == 2)
642
+		} elseif ($mode == 2)
636 643
 		{
637
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
638
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
639
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
640
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
641
-		}
642
-		elseif ($mode == 3)
644
+			if ($statut == 0) {
645
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
646
+			}
647
+			if ($statut == 1) {
648
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
649
+			}
650
+			if ($statut == 2) {
651
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
652
+			}
653
+			if ($statut == 3) {
654
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
655
+			}
656
+		} elseif ($mode == 3)
643 657
 		{
644
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0');
645
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1');
646
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3');
647
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6');
648
-		}
649
-		elseif ($mode == 4)
658
+			if ($statut == 0) {
659
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut0');
660
+			}
661
+			if ($statut == 1) {
662
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut1');
663
+			}
664
+			if ($statut == 2) {
665
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut3');
666
+			}
667
+			if ($statut == 3) {
668
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut6');
669
+			}
670
+		} elseif ($mode == 4)
650 671
 		{
651
-			if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
652
-			if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
653
-			if ($statut == 2) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
654
-			if ($statut == 3) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
655
-		}
656
-		elseif ($mode == 5)
672
+			if ($statut == 0) {
673
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut0').' '.$langs->trans($this->statuts[$statut]);
674
+			}
675
+			if ($statut == 1) {
676
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut1').' '.$langs->trans($this->statuts[$statut]);
677
+			}
678
+			if ($statut == 2) {
679
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]);
680
+			}
681
+			if ($statut == 3) {
682
+			    return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]);
683
+			}
684
+		} elseif ($mode == 5)
657 685
 		{
658
-			if ($statut == 0)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
659
-			if ($statut == 1)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
660
-			if ($statut == 2)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
661
-			if ($statut == 3)  return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
686
+			if ($statut == 0) {
687
+			    return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut0');
688
+			}
689
+			if ($statut == 1) {
690
+			    return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut1');
691
+			}
692
+			if ($statut == 2) {
693
+			    return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3');
694
+			}
695
+			if ($statut == 3) {
696
+			    return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6');
697
+			}
662 698
 		}
663 699
 	}
664 700
 
@@ -680,45 +716,79 @@  discard block
 block discarded – undo
680 716
 		if ($mode == 0)
681 717
 		{
682 718
 			return $langs->trans('MailingStatusError');
683
-		}
684
-		elseif ($mode == 1)
719
+		} elseif ($mode == 1)
685 720
 		{
686 721
 			return $langs->trans('MailingStatusSent');
687
-		}
688
-		elseif ($mode == 2)
689
-		{
690
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
691
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
692
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
693
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
694
-		}
695
-		elseif ($mode == 3)
696
-		{
697
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
698
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
699
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
700
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
701
-		}
702
-		elseif ($mode == 4)
722
+		} elseif ($mode == 2)
703 723
 		{
704
-			if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
705
-			if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
706
-			if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
707
-			if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
708
-		}
709
-		elseif ($mode == 5)
724
+			if ($statut==-1) {
725
+			    return $langs->trans("MailingStatusError").' '.img_error($desc);
726
+			}
727
+			if ($statut==1) {
728
+			    return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
729
+			}
730
+			if ($statut==2) {
731
+			    return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
732
+			}
733
+			if ($statut==3) {
734
+			    return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
735
+			}
736
+		} elseif ($mode == 3)
710 737
 		{
711
-		    if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
712
-		    if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
713
-		    if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
714
-		    if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
715
-		}
716
-		elseif ($mode == 6)
738
+			if ($statut==-1) {
739
+			    return $langs->trans("MailingStatusError").' '.img_error($desc);
740
+			}
741
+			if ($statut==1) {
742
+			    return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
743
+			}
744
+			if ($statut==2) {
745
+			    return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
746
+			}
747
+			if ($statut==3) {
748
+			    return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
749
+			}
750
+		} elseif ($mode == 4)
717 751
 		{
718
-		    if ($statut==-1) return $langs->trans("MailingStatusError").' '.img_error($desc);
719
-		    if ($statut==1) return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
720
-		    if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
721
-		    if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
752
+			if ($statut==-1) {
753
+			    return $langs->trans("MailingStatusError").' '.img_error($desc);
754
+			}
755
+			if ($statut==1) {
756
+			    return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
757
+			}
758
+			if ($statut==2) {
759
+			    return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
760
+			}
761
+			if ($statut==3) {
762
+			    return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
763
+			}
764
+		} elseif ($mode == 5)
765
+		{
766
+		    if ($statut==-1) {
767
+		        return $langs->trans("MailingStatusError").' '.img_error($desc);
768
+		    }
769
+		    if ($statut==1) {
770
+		        return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
771
+		    }
772
+		    if ($statut==2) {
773
+		        return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
774
+		    }
775
+		    if ($statut==3) {
776
+		        return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
777
+		    }
778
+		} elseif ($mode == 6)
779
+		{
780
+		    if ($statut==-1) {
781
+		        return $langs->trans("MailingStatusError").' '.img_error($desc);
782
+		    }
783
+		    if ($statut==1) {
784
+		        return $langs->trans("MailingStatusSent").' '.img_picto($langs->trans("MailingStatusSent"),'statut6');
785
+		    }
786
+		    if ($statut==2) {
787
+		        return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut4');
788
+		    }
789
+		    if ($statut==3) {
790
+		        return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut3');
791
+		    }
722 792
 		}
723 793
 	}
724 794
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/mailing/card.php 3 patches
Indentation   +1149 added lines, -1149 removed lines patch added patch discarded remove patch
@@ -88,621 +88,621 @@  discard block
 block discarded – undo
88 88
 
89 89
 if (empty($reshook))
90 90
 {
91
-	// Action clone object
92
-	if ($action == 'confirm_clone' && $confirm == 'yes')
93
-	{
94
-		if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
95
-		{
96
-			setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
97
-		}
98
-		else
99
-		{
100
-			$result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
101
-			if ($result > 0)
102
-			{
103
-				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
104
-				exit;
105
-			}
106
-			else
107
-			{
108
-				setEventMessages($object->error, $object->errors, 'errors');
109
-			}
110
-		}
111
-	    $action='';
112
-	}
113
-
114
-	// Action send emailing for everybody
115
-	if ($action == 'sendallconfirmed' && $confirm == 'yes')
116
-	{
117
-		if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
118
-		{
119
-			// As security measure, we don't allow send from the GUI
120
-			setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
121
-			setEventMessages('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
122
-			setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
123
-			$action='';
124
-		}
125
-		else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
126
-		{
127
-			setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings');
128
-			$action='';
129
-		}
130
-		else
131
-		{
132
-			$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
133
-
134
-			if ($object->statut == 0)
135
-			{
136
-				dol_print_error('','ErrorMailIsNotValidated');
137
-				exit;
138
-			}
139
-
140
-			$id       = $object->id;
141
-			$subject  = $object->sujet;
142
-			$message  = $object->body;
143
-			$from     = $object->email_from;
144
-			$replyto  = $object->email_replyto;
145
-			$errorsto = $object->email_errorsto;
146
-			// Le message est-il en html
147
-			$msgishtml=-1;	// Unknown by default
148
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
149
-
150
-			// Warning, we must not use begin-commit transaction here
151
-			// because we want to save update for each mail sent.
152
-
153
-			$nbok=0; $nbko=0;
154
-
155
-			// On choisit les mails non deja envoyes pour ce mailing (statut=0)
156
-			// ou envoyes en erreur (statut=-1)
157
-			$sql = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
158
-			$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
159
-			$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$object->id;
160
-			$sql .= " ORDER BY mc.statut DESC";		// first status 0, then status -1
161
-
162
-			dol_syslog("card.php: select targets", LOG_DEBUG);
163
-			$resql=$db->query($sql);
164
-			if ($resql)
165
-			{
166
-				$num = $db->num_rows($resql);	// nb of possible recipients
167
-
168
-				if ($num)
169
-				{
170
-					dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
171
-
172
-					$now=dol_now();
173
-
174
-					// Positionne date debut envoi
175
-					$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$object->id;
176
-					$resql2=$db->query($sql);
177
-					if (! $resql2)
178
-					{
179
-						dol_print_error($db);
180
-					}
181
-
182
-					// Loop on each email and send it
183
-					$i = 0;
184
-
185
-					while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
186
-					{
187
-						// Here code is common with same loop ino mailing-send.php
188
-						$res=1;
189
-						$now=dol_now();
190
-
191
-						$obj = $db->fetch_object($resql);
192
-
193
-						// sendto en RFC2822
194
-						$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
195
-
196
-						// Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
197
-						$other=explode(';',$obj->other);
198
-						$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
199
-	                    $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
200
-	                    $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
201
-	                    $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
202
-	                    $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
203
-
204
-	                    $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
205
-
206
-	                    $targetobject = null;		// Not defined with mass emailing
207
-	                    $parameters=array('mode'=>'emailing');
208
-	                    $substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $targetobject);			// Note: On mass emailing, this is null because be don't know object
209
-
210
-	                    // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
211
-						$substitutionarray['__ID__'] = $obj->source_id;
212
-						$substitutionarray['__EMAIL__'] = $obj->email;
213
-						$substitutionarray['__LASTNAME__'] = $obj->lastname;
214
-						$substitutionarray['__FIRSTNAME__'] = $obj->firstname;
215
-						$substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
216
-						$substitutionarray['__OTHER1__'] = $other1;
217
-						$substitutionarray['__OTHER2__'] = $other2;
218
-						$substitutionarray['__OTHER3__'] = $other3;
219
-						$substitutionarray['__OTHER4__'] = $other4;
220
-						$substitutionarray['__OTHER5__'] = $other5;
221
-						$substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
222
-						$substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
223
-						$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
224
-						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
225
-
226
-						$onlinepaymentenabled = 0;
227
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
228
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
229
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
230
-						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
231
-						{
232
-							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
233
-							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
234
-							{
235
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
236
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
237
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
238
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
239
-							}
240
-							else
241
-							{
242
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
243
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
244
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
245
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
246
-							}
247
-						}
248
-						/* For backward compatibility, deprecated */
249
-						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
250
-						{
251
-							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
252
-
253
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
254
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
91
+    // Action clone object
92
+    if ($action == 'confirm_clone' && $confirm == 'yes')
93
+    {
94
+        if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
95
+        {
96
+            setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
97
+        }
98
+        else
99
+        {
100
+            $result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
101
+            if ($result > 0)
102
+            {
103
+                header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
104
+                exit;
105
+            }
106
+            else
107
+            {
108
+                setEventMessages($object->error, $object->errors, 'errors');
109
+            }
110
+        }
111
+        $action='';
112
+    }
113
+
114
+    // Action send emailing for everybody
115
+    if ($action == 'sendallconfirmed' && $confirm == 'yes')
116
+    {
117
+        if (empty($conf->global->MAILING_LIMIT_SENDBYWEB))
118
+        {
119
+            // As security measure, we don't allow send from the GUI
120
+            setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
121
+            setEventMessages('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
122
+            setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
123
+            $action='';
124
+        }
125
+        else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
126
+        {
127
+            setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings');
128
+            $action='';
129
+        }
130
+        else
131
+        {
132
+            $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
133
+
134
+            if ($object->statut == 0)
135
+            {
136
+                dol_print_error('','ErrorMailIsNotValidated');
137
+                exit;
138
+            }
255 139
 
256
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
257
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
140
+            $id       = $object->id;
141
+            $subject  = $object->sujet;
142
+            $message  = $object->body;
143
+            $from     = $object->email_from;
144
+            $replyto  = $object->email_replyto;
145
+            $errorsto = $object->email_errorsto;
146
+            // Le message est-il en html
147
+            $msgishtml=-1;	// Unknown by default
148
+            if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
149
+
150
+            // Warning, we must not use begin-commit transaction here
151
+            // because we want to save update for each mail sent.
152
+
153
+            $nbok=0; $nbko=0;
154
+
155
+            // On choisit les mails non deja envoyes pour ce mailing (statut=0)
156
+            // ou envoyes en erreur (statut=-1)
157
+            $sql = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
158
+            $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
159
+            $sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$object->id;
160
+            $sql .= " ORDER BY mc.statut DESC";		// first status 0, then status -1
161
+
162
+            dol_syslog("card.php: select targets", LOG_DEBUG);
163
+            $resql=$db->query($sql);
164
+            if ($resql)
165
+            {
166
+                $num = $db->num_rows($resql);	// nb of possible recipients
258 167
 
259
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
260
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
168
+                if ($num)
169
+                {
170
+                    dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
261 171
 
262
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
263
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
264
-						}
265
-						//$substitutionisok=true;
172
+                    $now=dol_now();
266 173
 
267
-	                    complete_substitutions_array($substitutionarray, $langs);
268
-						$newsubject=make_substitutions($subject,$substitutionarray);
269
-						$newmessage=make_substitutions($message,$substitutionarray);
174
+                    // Positionne date debut envoi
175
+                    $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$object->id;
176
+                    $resql2=$db->query($sql);
177
+                    if (! $resql2)
178
+                    {
179
+                        dol_print_error($db);
180
+                    }
270 181
 
271
-						$arr_file = array();
272
-						$arr_mime = array();
273
-						$arr_name = array();
274
-						$arr_css  = array();
182
+                    // Loop on each email and send it
183
+                    $i = 0;
275 184
 
276
-						$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
277
-						if (count($listofpaths))
278
-						{
279
-							foreach($listofpaths as $key => $val)
280
-							{
281
-								$arr_file[]=$listofpaths[$key]['fullname'];
282
-								$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
283
-								$arr_name[]=$listofpaths[$key]['name'];
284
-							}
285
-						}
286
-
287
-						// Fabrication du mail
288
-						$trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
289
-						$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, '', 'emailing');
290
-
291
-						if ($mail->error)
292
-						{
293
-							$res=0;
294
-						}
295
-						/*if (! $substitutionisok)
185
+                    while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
186
+                    {
187
+                        // Here code is common with same loop ino mailing-send.php
188
+                        $res=1;
189
+                        $now=dol_now();
190
+
191
+                        $obj = $db->fetch_object($resql);
192
+
193
+                        // sendto en RFC2822
194
+                        $sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
195
+
196
+                        // Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
197
+                        $other=explode(';',$obj->other);
198
+                        $tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
199
+                        $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
200
+                        $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
201
+                        $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
202
+                        $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
203
+
204
+                        $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
205
+
206
+                        $targetobject = null;		// Not defined with mass emailing
207
+                        $parameters=array('mode'=>'emailing');
208
+                        $substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $targetobject);			// Note: On mass emailing, this is null because be don't know object
209
+
210
+                        // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
211
+                        $substitutionarray['__ID__'] = $obj->source_id;
212
+                        $substitutionarray['__EMAIL__'] = $obj->email;
213
+                        $substitutionarray['__LASTNAME__'] = $obj->lastname;
214
+                        $substitutionarray['__FIRSTNAME__'] = $obj->firstname;
215
+                        $substitutionarray['__MAILTOEMAIL__'] = '<a href="mailto:'.$obj->email.'">'.$obj->email.'</a>';
216
+                        $substitutionarray['__OTHER1__'] = $other1;
217
+                        $substitutionarray['__OTHER2__'] = $other2;
218
+                        $substitutionarray['__OTHER3__'] = $other3;
219
+                        $substitutionarray['__OTHER4__'] = $other4;
220
+                        $substitutionarray['__OTHER5__'] = $other5;
221
+                        $substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
222
+                        $substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
223
+                        $substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
224
+                        $substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
225
+
226
+                        $onlinepaymentenabled = 0;
227
+                        if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
228
+                        if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
229
+                        if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
230
+                        if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
231
+                        {
232
+                            $substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
233
+                            if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
234
+                            {
235
+                                $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
236
+                                $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
237
+                                $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
238
+                                $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
239
+                            }
240
+                            else
241
+                            {
242
+                                $substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
243
+                                $substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
244
+                                $substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
245
+                                $substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
246
+                            }
247
+                        }
248
+                        /* For backward compatibility, deprecated */
249
+                        if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
250
+                        {
251
+                            $substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
252
+
253
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
254
+                            else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
255
+
256
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
257
+                            else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
258
+
259
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
260
+                            else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
261
+
262
+                            if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
263
+                            else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
264
+                        }
265
+                        //$substitutionisok=true;
266
+
267
+                        complete_substitutions_array($substitutionarray, $langs);
268
+                        $newsubject=make_substitutions($subject,$substitutionarray);
269
+                        $newmessage=make_substitutions($message,$substitutionarray);
270
+
271
+                        $arr_file = array();
272
+                        $arr_mime = array();
273
+                        $arr_name = array();
274
+                        $arr_css  = array();
275
+
276
+                        $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
277
+                        if (count($listofpaths))
278
+                        {
279
+                            foreach($listofpaths as $key => $val)
280
+                            {
281
+                                $arr_file[]=$listofpaths[$key]['fullname'];
282
+                                $arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
283
+                                $arr_name[]=$listofpaths[$key]['name'];
284
+                            }
285
+                        }
286
+
287
+                        // Fabrication du mail
288
+                        $trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
289
+                        $mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, '', 'emailing');
290
+
291
+                        if ($mail->error)
292
+                        {
293
+                            $res=0;
294
+                        }
295
+                        /*if (! $substitutionisok)
296 296
 						{
297 297
 							$mail->error='Some substitution failed';
298 298
 							$res=0;
299 299
 						}*/
300 300
 
301
-						// Send mail
302
-						if ($res)
303
-						{
304
-							$res=$mail->sendfile();
305
-						}
301
+                        // Send mail
302
+                        if ($res)
303
+                        {
304
+                            $res=$mail->sendfile();
305
+                        }
306
+
307
+                        if ($res)
308
+                        {
309
+                            // Mail successful
310
+                            $nbok++;
311
+
312
+                            dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
313
+
314
+                            $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
315
+                            $sql.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
316
+                            $resql2=$db->query($sql);
317
+                            if (! $resql2)
318
+                            {
319
+                                dol_print_error($db);
320
+                            }
321
+                            else
322
+                            {
323
+                                //if cheack read is use then update prospect contact status
324
+                                if (strpos($message, '__CHECK_READ__') !== false)
325
+                                {
326
+                                    //Update status communication of thirdparty prospect
327
+                                    $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
328
+                                    dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
329
+                                    $resql2=$db->query($sql);
330
+                                    if (! $resql2)
331
+                                    {
332
+                                        dol_print_error($db);
333
+                                    }
334
+
335
+                                    //Update status communication of contact prospect
336
+                                    $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
337
+                                    dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
338
+
339
+                                    $resql2=$db->query($sql);
340
+                                    if (! $resql2)
341
+                                    {
342
+                                        dol_print_error($db);
343
+                                    }
344
+                                }
345
+                            }
346
+
347
+                            if (!empty($conf->global->MAILING_DELAY))
348
+                            {
349
+                                sleep($conf->global->MAILING_DELAY);
350
+                            }
351
+
352
+                            //test if CHECK READ change statut prospect contact
353
+                        }
354
+                        else
355
+                        {
356
+                            // Mail failed
357
+                            $nbko++;
358
+
359
+                            dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_WARNING);
360
+
361
+                            $sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
362
+                            $sql.=" SET statut=-1, error_text='".$db->escape($mail->error)."', date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
363
+                            $resql2=$db->query($sql);
364
+                            if (! $resql2)
365
+                            {
366
+                                dol_print_error($db);
367
+                            }
368
+                        }
369
+
370
+                        $i++;
371
+                    }
372
+                }
373
+                else
374
+                {
375
+                    setEventMessages($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"), null, 'mesgs');
376
+                }
377
+
378
+                // Loop finished, set global statut of mail
379
+                if ($nbko > 0)
380
+                {
381
+                    $statut=2;	// Status 'sent partially' (because at least one error)
382
+                    if ($nbok > 0) 	setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
383
+                    else setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
384
+                }
385
+                else
386
+                {
387
+                    if ($nbok >= $num)
388
+                    {
389
+                        $statut=3;	// Send to everybody
390
+                        setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
391
+                    }
392
+                    else
393
+                    {
394
+                        $statut=2;	// Status 'sent partially' (because not send to everybody)
395
+                        setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
396
+                    }
397
+                }
398
+
399
+                $sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
400
+                dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
401
+                $resql2=$db->query($sql);
402
+                if (! $resql2)
403
+                {
404
+                    dol_print_error($db);
405
+                }
406
+            }
407
+            else
408
+            {
409
+                dol_syslog($db->error());
410
+                dol_print_error($db);
411
+            }
306 412
 
307
-						if ($res)
308
-						{
309
-							// Mail successful
310
-							$nbok++;
311
-
312
-							dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
313
-
314
-							$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
315
-							$sql.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
316
-							$resql2=$db->query($sql);
317
-							if (! $resql2)
318
-							{
319
-								dol_print_error($db);
320
-							}
321
-							else
322
-							{
323
-								//if cheack read is use then update prospect contact status
324
-								if (strpos($message, '__CHECK_READ__') !== false)
325
-								{
326
-									//Update status communication of thirdparty prospect
327
-									$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
328
-									dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
329
-									$resql2=$db->query($sql);
330
-									if (! $resql2)
331
-									{
332
-										dol_print_error($db);
333
-									}
334
-
335
-								    //Update status communication of contact prospect
336
-									$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
337
-									dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
338
-
339
-									$resql2=$db->query($sql);
340
-									if (! $resql2)
341
-									{
342
-										dol_print_error($db);
343
-									}
344
-								}
345
-							}
346
-
347
-						    if (!empty($conf->global->MAILING_DELAY))
348
-						    {
349
-                            	sleep($conf->global->MAILING_DELAY);
350
-                        	}
351
-
352
-                        	//test if CHECK READ change statut prospect contact
353
-						}
354
-						else
355
-						{
356
-							// Mail failed
357
-							$nbko++;
358
-
359
-							dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_WARNING);
360
-
361
-							$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
362
-							$sql.=" SET statut=-1, error_text='".$db->escape($mail->error)."', date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
363
-							$resql2=$db->query($sql);
364
-							if (! $resql2)
365
-							{
366
-								dol_print_error($db);
367
-							}
368
-						}
369
-
370
-						$i++;
371
-					}
372
-				}
373
-				else
374
-				{
375
-					setEventMessages($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"), null, 'mesgs');
376
-				}
377
-
378
-				// Loop finished, set global statut of mail
379
-				if ($nbko > 0)
380
-				{
381
-					$statut=2;	// Status 'sent partially' (because at least one error)
382
-					if ($nbok > 0) 	setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
383
-					else setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
384
-				}
385
-				else
386
-				{
387
-					if ($nbok >= $num)
388
-					{
389
-						$statut=3;	// Send to everybody
390
-						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
391
-					}
392
-					else
393
-					{
394
-						$statut=2;	// Status 'sent partially' (because not send to everybody)
395
-						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
396
-					}
397
-				}
398
-
399
-				$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
400
-				dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
401
-				$resql2=$db->query($sql);
402
-				if (! $resql2)
403
-				{
404
-					dol_print_error($db);
405
-				}
406
-			}
407
-			else
408
-			{
409
-				dol_syslog($db->error());
410
-				dol_print_error($db);
411
-			}
412
-
413
-			$action = '';
414
-		}
415
-	}
416
-
417
-	// Action send test emailing
418
-	if ($action == 'send' && empty($_POST["cancel"]))
419
-	{
420
-		$error=0;
421
-
422
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
423
-
424
-		$object->sendto = $_POST["sendto"];
425
-		if (! $object->sendto)
426
-		{
427
-			setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("MailTo")), null, 'errors');
428
-			$error++;
429
-		}
430
-
431
-		if (! $error)
432
-		{
433
-			// Le message est-il en html
434
-			$msgishtml=-1;	// Inconnu par defaut
435
-			if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
436
-
437
-			// other are set at begin of page
438
-			$object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;
439
-			$object->substitutionarrayfortest['__MAILTOEMAIL__'] = '<a href="mailto:'.$object->sendto.'">'.$object->sendto.'</a>';
440
-
441
-			// Pratique les substitutions sur le sujet et message
442
-	        complete_substitutions_array($object->substitutionarrayfortest, $langs);
443
-			$tmpsujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
444
-			$tmpbody=make_substitutions($object->body,$object->substitutionarrayfortest);
445
-
446
-			$arr_file = array();
447
-			$arr_mime = array();
448
-			$arr_name = array();
449
-			$arr_css  = array();
450
-
451
-	        // Ajout CSS
452
-	        if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
453
-	        if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
454
-
455
-	        // Attached files
456
-			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
457
-			if (count($listofpaths))
458
-			{
459
-				foreach($listofpaths as $key => $val)
460
-				{
461
-					$arr_file[]=$listofpaths[$key]['fullname'];
462
-					$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
463
-					$arr_name[]=$listofpaths[$key]['name'];
464
-				}
465
-			}
466
-
467
-			$trackid='emailingtest';
468
-			$mailfile = new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $object->email_errorsto, $arr_css, $trackid, '', 'emailing');
469
-
470
-			$result=$mailfile->sendfile();
471
-			if ($result)
472
-			{
473
-				setEventMessages($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)), null, 'mesgs');
474
-			}
475
-			else
476
-			{
477
-				setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, null, 'errors');
478
-			}
479
-
480
-			$action='';
481
-		}
482
-	}
483
-
484
-	// Action add emailing
485
-	if ($action == 'add')
486
-	{
487
-		$mesgs = array();
488
-
489
-		$object->email_from     = trim($_POST["from"]);
490
-		$object->email_replyto  = trim($_POST["replyto"]);
491
-		$object->email_errorsto = trim($_POST["errorsto"]);
492
-		$object->titre          = trim($_POST["titre"]);
493
-		$object->sujet          = trim($_POST["sujet"]);
494
-		$object->body           = trim($_POST["bodyemail"]);
495
-		$object->bgcolor        = trim($_POST["bgcolor"]);
496
-		$object->bgimage        = trim($_POST["bgimage"]);
497
-
498
-		if (! $object->titre) {
499
-			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
500
-		}
501
-		if (! $object->sujet) {
502
-			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
503
-		}
504
-		if (! $object->body)  {
505
-			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
506
-		}
507
-
508
-		if (!count($mesgs))
509
-		{
510
-			if ($object->create($user) >= 0)
511
-			{
512
-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
513
-				exit;
514
-			}
515
-			$mesgs[] = $object->error;
516
-		}
517
-
518
-		setEventMessages($mesg, $mesgs, 'errors');
519
-		$action="create";
520
-	}
521
-
522
-	// Action update description of emailing
523
-	if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto')
524
-	{
525
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
526
-
527
-		if ($action == 'settitre')					$object->titre          = trim(GETPOST('titre','alpha'));
528
-		else if ($action == 'setemail_from')		$object->email_from     = trim(GETPOST('email_from','alpha'));
529
-		else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
530
-		else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
531
-		else if ($action == 'settitre' && empty($object->titre)) {
532
-			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
533
-		}
534
-		else if ($action == 'setfrom' && empty($object->email_from)) {
535
-			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
536
-		}
537
-
538
-		if (! $mesg)
539
-		{
540
-			if ($object->update($user) >= 0)
541
-			{
542
-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
543
-				exit;
544
-			}
545
-			$mesg = $object->error;
546
-		}
547
-
548
-		setEventMessages($mesg, $mesgs, 'errors');
549
-		$action="";
550
-	}
551
-
552
-	/*
413
+            $action = '';
414
+        }
415
+    }
416
+
417
+    // Action send test emailing
418
+    if ($action == 'send' && empty($_POST["cancel"]))
419
+    {
420
+        $error=0;
421
+
422
+        $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
423
+
424
+        $object->sendto = $_POST["sendto"];
425
+        if (! $object->sendto)
426
+        {
427
+            setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("MailTo")), null, 'errors');
428
+            $error++;
429
+        }
430
+
431
+        if (! $error)
432
+        {
433
+            // Le message est-il en html
434
+            $msgishtml=-1;	// Inconnu par defaut
435
+            if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
436
+
437
+            // other are set at begin of page
438
+            $object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;
439
+            $object->substitutionarrayfortest['__MAILTOEMAIL__'] = '<a href="mailto:'.$object->sendto.'">'.$object->sendto.'</a>';
440
+
441
+            // Pratique les substitutions sur le sujet et message
442
+            complete_substitutions_array($object->substitutionarrayfortest, $langs);
443
+            $tmpsujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
444
+            $tmpbody=make_substitutions($object->body,$object->substitutionarrayfortest);
445
+
446
+            $arr_file = array();
447
+            $arr_mime = array();
448
+            $arr_name = array();
449
+            $arr_css  = array();
450
+
451
+            // Ajout CSS
452
+            if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
453
+            if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
454
+
455
+            // Attached files
456
+            $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
457
+            if (count($listofpaths))
458
+            {
459
+                foreach($listofpaths as $key => $val)
460
+                {
461
+                    $arr_file[]=$listofpaths[$key]['fullname'];
462
+                    $arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
463
+                    $arr_name[]=$listofpaths[$key]['name'];
464
+                }
465
+            }
466
+
467
+            $trackid='emailingtest';
468
+            $mailfile = new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $object->email_errorsto, $arr_css, $trackid, '', 'emailing');
469
+
470
+            $result=$mailfile->sendfile();
471
+            if ($result)
472
+            {
473
+                setEventMessages($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)), null, 'mesgs');
474
+            }
475
+            else
476
+            {
477
+                setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, null, 'errors');
478
+            }
479
+
480
+            $action='';
481
+        }
482
+    }
483
+
484
+    // Action add emailing
485
+    if ($action == 'add')
486
+    {
487
+        $mesgs = array();
488
+
489
+        $object->email_from     = trim($_POST["from"]);
490
+        $object->email_replyto  = trim($_POST["replyto"]);
491
+        $object->email_errorsto = trim($_POST["errorsto"]);
492
+        $object->titre          = trim($_POST["titre"]);
493
+        $object->sujet          = trim($_POST["sujet"]);
494
+        $object->body           = trim($_POST["bodyemail"]);
495
+        $object->bgcolor        = trim($_POST["bgcolor"]);
496
+        $object->bgimage        = trim($_POST["bgimage"]);
497
+
498
+        if (! $object->titre) {
499
+            $mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
500
+        }
501
+        if (! $object->sujet) {
502
+            $mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
503
+        }
504
+        if (! $object->body)  {
505
+            $mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
506
+        }
507
+
508
+        if (!count($mesgs))
509
+        {
510
+            if ($object->create($user) >= 0)
511
+            {
512
+                header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
513
+                exit;
514
+            }
515
+            $mesgs[] = $object->error;
516
+        }
517
+
518
+        setEventMessages($mesg, $mesgs, 'errors');
519
+        $action="create";
520
+    }
521
+
522
+    // Action update description of emailing
523
+    if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto')
524
+    {
525
+        $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
526
+
527
+        if ($action == 'settitre')					$object->titre          = trim(GETPOST('titre','alpha'));
528
+        else if ($action == 'setemail_from')		$object->email_from     = trim(GETPOST('email_from','alpha'));
529
+        else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
530
+        else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
531
+        else if ($action == 'settitre' && empty($object->titre)) {
532
+            $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
533
+        }
534
+        else if ($action == 'setfrom' && empty($object->email_from)) {
535
+            $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
536
+        }
537
+
538
+        if (! $mesg)
539
+        {
540
+            if ($object->update($user) >= 0)
541
+            {
542
+                header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
543
+                exit;
544
+            }
545
+            $mesg = $object->error;
546
+        }
547
+
548
+        setEventMessages($mesg, $mesgs, 'errors');
549
+        $action="";
550
+    }
551
+
552
+    /*
553 553
 	 * Add file in email form
554 554
 	 */
555
-	if (! empty($_POST['addfile']))
556
-	{
557
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
558
-
559
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
560
-
561
-	    // Set tmp user directory
562
-	    dol_add_file_process($upload_dir,0,0);
563
-
564
-		$action="edit";
565
-	}
566
-
567
-	// Action remove file
568
-	if (! empty($_POST["removedfile"]))
569
-	{
570
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
571
-
572
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
573
-
574
-	    dol_remove_file_process($_POST['removedfile'],0,0);    // We really delete file linked to mailing
575
-
576
-		$action="edit";
577
-	}
578
-
579
-	// Action update emailing
580
-	if ($action == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"]))
581
-	{
582
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
583
-
584
-		$isupload=0;
585
-
586
-		if (! $isupload)
587
-		{
588
-			$mesgs = array();
589
-
590
-			$object->sujet          = trim($_POST["sujet"]);
591
-			$object->body           = trim($_POST["bodyemail"]);
592
-			$object->bgcolor        = trim($_POST["bgcolor"]);
593
-			$object->bgimage        = trim($_POST["bgimage"]);
594
-
595
-			if (! $object->sujet) {
596
-				$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
597
-			}
598
-			if (! $object->body) {
599
-				$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
600
-			}
601
-
602
-			if (!count($mesgs))
603
-			{
604
-				if ($object->update($user) >= 0)
605
-				{
606
-					header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
607
-					exit;
608
-				}
609
-				$mesgs[] =$object->error;
610
-			}
611
-
612
-			setEventMessages($mesg, $mesgs, 'errors');
613
-			$action="edit";
614
-		}
615
-		else
616
-		{
617
-			$action="edit";
618
-		}
619
-	}
620
-
621
-	// Action confirmation validation
622
-	if ($action == 'confirm_valid' && $confirm == 'yes')
623
-	{
624
-		if ($object->id > 0)
625
-		{
626
-			$object->valid($user);
627
-			setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
628
-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
629
-			exit;
630
-		}
631
-		else
632
-		{
633
-			dol_print_error($db);
634
-		}
635
-	}
636
-
637
-	// Action confirmation validation
638
-	if ($action == 'confirm_settodraft' && $confirm == 'yes')
639
-	{
640
-		if ($object->id > 0)
641
-		{
642
-			$result = $object->setStatut(0);
555
+    if (! empty($_POST['addfile']))
556
+    {
557
+        $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
558
+
559
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
560
+
561
+        // Set tmp user directory
562
+        dol_add_file_process($upload_dir,0,0);
563
+
564
+        $action="edit";
565
+    }
566
+
567
+    // Action remove file
568
+    if (! empty($_POST["removedfile"]))
569
+    {
570
+        $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
571
+
572
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
573
+
574
+        dol_remove_file_process($_POST['removedfile'],0,0);    // We really delete file linked to mailing
575
+
576
+        $action="edit";
577
+    }
578
+
579
+    // Action update emailing
580
+    if ($action == 'update' && empty($_POST["removedfile"]) && empty($_POST["cancel"]))
581
+    {
582
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
583
+
584
+        $isupload=0;
585
+
586
+        if (! $isupload)
587
+        {
588
+            $mesgs = array();
589
+
590
+            $object->sujet          = trim($_POST["sujet"]);
591
+            $object->body           = trim($_POST["bodyemail"]);
592
+            $object->bgcolor        = trim($_POST["bgcolor"]);
593
+            $object->bgimage        = trim($_POST["bgimage"]);
594
+
595
+            if (! $object->sujet) {
596
+                $mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
597
+            }
598
+            if (! $object->body) {
599
+                $mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
600
+            }
601
+
602
+            if (!count($mesgs))
603
+            {
604
+                if ($object->update($user) >= 0)
605
+                {
606
+                    header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
607
+                    exit;
608
+                }
609
+                $mesgs[] =$object->error;
610
+            }
611
+
612
+            setEventMessages($mesg, $mesgs, 'errors');
613
+            $action="edit";
614
+        }
615
+        else
616
+        {
617
+            $action="edit";
618
+        }
619
+    }
620
+
621
+    // Action confirmation validation
622
+    if ($action == 'confirm_valid' && $confirm == 'yes')
623
+    {
624
+        if ($object->id > 0)
625
+        {
626
+            $object->valid($user);
627
+            setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
628
+            header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
629
+            exit;
630
+        }
631
+        else
632
+        {
633
+            dol_print_error($db);
634
+        }
635
+    }
636
+
637
+    // Action confirmation validation
638
+    if ($action == 'confirm_settodraft' && $confirm == 'yes')
639
+    {
640
+        if ($object->id > 0)
641
+        {
642
+            $result = $object->setStatut(0);
643
+            if ($result > 0)
644
+            {
645
+                //setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
646
+                header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
647
+                exit;
648
+            }
649
+            else
650
+            {
651
+                setEventMessages($object->error, $object->errors, 'errors');
652
+            }
653
+        }
654
+        else
655
+        {
656
+            dol_print_error($db);
657
+        }
658
+    }
659
+
660
+    // Resend
661
+    if ($action == 'confirm_reset' && $confirm == 'yes')
662
+    {
663
+        if ($object->id > 0)
664
+        {
665
+            $db->begin();
666
+
667
+            $result=$object->valid($user);
643 668
             if ($result > 0)
644 669
             {
645
-    			//setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
646
-    			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
647
-    			exit;
670
+                $result=$object->reset_targets_status($user);
671
+            }
672
+
673
+            if ($result > 0)
674
+            {
675
+                $db->commit();
676
+                header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
677
+                exit;
648 678
             }
649 679
             else
650 680
             {
651 681
                 setEventMessages($object->error, $object->errors, 'errors');
682
+                $db->rollback();
652 683
             }
653
-		}
654
-		else
655
-		{
656
-			dol_print_error($db);
657
-		}
658
-	}
659
-
660
-	// Resend
661
-	if ($action == 'confirm_reset' && $confirm == 'yes')
662
-	{
663
-		if ($object->id > 0)
664
-		{
665
-			$db->begin();
666
-
667
-			$result=$object->valid($user);
668
-			if ($result > 0)
669
-			{
670
-				$result=$object->reset_targets_status($user);
671
-			}
672
-
673
-			if ($result > 0)
674
-			{
675
-				$db->commit();
676
-				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
677
-				exit;
678
-			}
679
-			else
680
-			{
681
-				setEventMessages($object->error, $object->errors, 'errors');
682
-				$db->rollback();
683
-			}
684
-		}
685
-		else
686
-		{
687
-			dol_print_error($db);
688
-		}
689
-	}
690
-
691
-	// Action confirmation suppression
692
-	if ($action == 'confirm_delete' && $confirm == 'yes')
693
-	{
694
-		if ($object->delete($object->id))
695
-		{
696
-			$url= (! empty($urlfrom) ? $urlfrom : 'list.php');
697
-			header("Location: ".$url);
698
-			exit;
699
-		}
700
-	}
701
-
702
-	if (! empty($_POST["cancel"]))
703
-	{
704
-		$action = '';
705
-	}
684
+        }
685
+        else
686
+        {
687
+            dol_print_error($db);
688
+        }
689
+    }
690
+
691
+    // Action confirmation suppression
692
+    if ($action == 'confirm_delete' && $confirm == 'yes')
693
+    {
694
+        if ($object->delete($object->id))
695
+        {
696
+            $url= (! empty($urlfrom) ? $urlfrom : 'list.php');
697
+            header("Location: ".$url);
698
+            exit;
699
+        }
700
+    }
701
+
702
+    if (! empty($_POST["cancel"]))
703
+    {
704
+        $action = '';
705
+    }
706 706
 }
707 707
 
708 708
 
@@ -715,646 +715,646 @@  discard block
 block discarded – undo
715 715
 
716 716
 $help_url='EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
717 717
 llxHeader('', $langs->trans("Mailing"), $help_url, '', 0, 0,
718
-	array(
719
-	'/includes/ace/ace.js',
720
-	'/includes/ace/ext-statusbar.js',
721
-	'/includes/ace/ext-language_tools.js',
722
-	//'/includes/ace/ext-chromevox.js'
723
-	), array());
718
+    array(
719
+    '/includes/ace/ace.js',
720
+    '/includes/ace/ext-statusbar.js',
721
+    '/includes/ace/ext-language_tools.js',
722
+    //'/includes/ace/ext-chromevox.js'
723
+    ), array());
724 724
 
725 725
 if ($action == 'create')
726 726
 {
727
-	// EMailing in creation mode
728
-	print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
729
-	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
730
-	print '<input type="hidden" name="action" value="add">';
727
+    // EMailing in creation mode
728
+    print '<form name="new_mailing" action="'.$_SERVER['PHP_SELF'].'" method="POST">'."\n";
729
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
730
+    print '<input type="hidden" name="action" value="add">';
731 731
 
732
-	$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
733
-	foreach($object->substitutionarray as $key => $val)
734
-	{
735
-		$htmltext.=$key.' = '.$langs->trans($val).'<br>';
736
-	}
737
-	$htmltext.='</i>';
732
+    $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
733
+    foreach($object->substitutionarray as $key => $val)
734
+    {
735
+        $htmltext.=$key.' = '.$langs->trans($val).'<br>';
736
+    }
737
+    $htmltext.='</i>';
738 738
 
739 739
 
740
-	$availablelink=$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
741
-	//print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>';
740
+    $availablelink=$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
741
+    //print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>';
742 742
 
743 743
 
744
-	// Print mail form
745
-	print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'title_generic');
744
+    // Print mail form
745
+    print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'title_generic');
746 746
 
747
-	dol_fiche_head();
747
+    dol_fiche_head();
748 748
 
749
-	print '<table class="border" width="100%">';
750
-	print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTitle").'</td><td><input class="flat minwidth300" name="titre" value="'.dol_escape_htmltag(GETPOST('titre')).'" autofocus="autofocus"></td></tr>';
751
-	print '<tr><td class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat minwidth200" name="from" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
752
-	print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td><input class="flat minwidth200" name="errorsto" value="'.(!empty($conf->global->MAILING_EMAIL_ERRORSTO)?$conf->global->MAILING_EMAIL_ERRORSTO:$conf->global->MAIN_MAIL_ERRORS_TO).'"></td></tr>';
749
+    print '<table class="border" width="100%">';
750
+    print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTitle").'</td><td><input class="flat minwidth300" name="titre" value="'.dol_escape_htmltag(GETPOST('titre')).'" autofocus="autofocus"></td></tr>';
751
+    print '<tr><td class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat minwidth200" name="from" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
752
+    print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td><input class="flat minwidth200" name="errorsto" value="'.(!empty($conf->global->MAILING_EMAIL_ERRORSTO)?$conf->global->MAILING_EMAIL_ERRORSTO:$conf->global->MAIN_MAIL_ERRORS_TO).'"></td></tr>';
753 753
 
754
-	// Other attributes
755
-	$parameters=array();
756
-	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
754
+    // Other attributes
755
+    $parameters=array();
756
+    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
757 757
     print $hookmanager->resPrint;
758
-	if (empty($reshook))
759
-	{
760
-		print $object->showOptionals($extrafields,'edit');
761
-	}
758
+    if (empty($reshook))
759
+    {
760
+        print $object->showOptionals($extrafields,'edit');
761
+    }
762 762
 
763
-	print '</table>';
764
-	print '</br><br>';
763
+    print '</table>';
764
+    print '</br><br>';
765 765
 
766
-	print '<table class="border" width="100%">';
767
-	print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTopic").'</td><td><input class="flat minwidth200 quatrevingtpercent" name="sujet" value="'.dol_escape_htmltag(GETPOST('sujet')).'"></td></tr>';
768
-	print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
769
-	print $htmlother->selectColor($_POST['bgcolor'],'bgcolor','',0);
770
-	print '</td></tr>';
766
+    print '<table class="border" width="100%">';
767
+    print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTopic").'</td><td><input class="flat minwidth200 quatrevingtpercent" name="sujet" value="'.dol_escape_htmltag(GETPOST('sujet')).'"></td></tr>';
768
+    print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
769
+    print $htmlother->selectColor($_POST['bgcolor'],'bgcolor','',0);
770
+    print '</td></tr>';
771 771
 
772
-	print '</table>';
772
+    print '</table>';
773 773
 
774
-	print '<div style="padding-top: 10px">';
775
-	// Editeur wysiwyg
776
-	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
777
-	$doleditor=new DolEditor('bodyemail',GETPOST('bodyemail','none'),'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
778
-	$doleditor->Create();
779
-	print '</div>';
774
+    print '<div style="padding-top: 10px">';
775
+    // Editeur wysiwyg
776
+    require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
777
+    $doleditor=new DolEditor('bodyemail',GETPOST('bodyemail','none'),'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
778
+    $doleditor->Create();
779
+    print '</div>';
780 780
 
781
-	dol_fiche_end();
781
+    dol_fiche_end();
782 782
 
783
-	print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("CreateMailing").'"></div>';
783
+    print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("CreateMailing").'"></div>';
784 784
 
785
-	print '</form>';
785
+    print '</form>';
786 786
 }
787 787
 else
788 788
 {
789
-	if ($object->id > 0)
790
-	{
791
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
792
-
793
-		$head = emailing_prepare_head($object);
794
-
795
-		// Confirmation back to draft
796
-		if ($action == 'settodraft')
797
-		{
798
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("SetToDraft"),$langs->trans("ConfirmUnvalidateEmailing"),"confirm_settodraft",'','',1);
799
-		}
800
-		// Confirmation validation of mailing
801
-		if ($action == 'valid')
802
-		{
803
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ValidMailing"),$langs->trans("ConfirmValidMailing"),"confirm_valid",'','',1);
804
-		}
805
-		// Confirm reset
806
-		else if ($action == 'reset')
807
-		{
808
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ResetMailing"),$langs->trans("ConfirmResetMailing",$object->ref),"confirm_reset",'','',2);
809
-		}
810
-		// Confirm delete
811
-		else if ($action == 'delete')
812
-		{
813
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(! empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''),$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete",'','',1);
814
-		}
815
-
816
-
817
-		if ($action != 'edit' && $action != 'edithtml')
818
-		{
819
-			dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
820
-
821
-			/*
789
+    if ($object->id > 0)
790
+    {
791
+        $upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
792
+
793
+        $head = emailing_prepare_head($object);
794
+
795
+        // Confirmation back to draft
796
+        if ($action == 'settodraft')
797
+        {
798
+            print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("SetToDraft"),$langs->trans("ConfirmUnvalidateEmailing"),"confirm_settodraft",'','',1);
799
+        }
800
+        // Confirmation validation of mailing
801
+        if ($action == 'valid')
802
+        {
803
+            print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ValidMailing"),$langs->trans("ConfirmValidMailing"),"confirm_valid",'','',1);
804
+        }
805
+        // Confirm reset
806
+        else if ($action == 'reset')
807
+        {
808
+            print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ResetMailing"),$langs->trans("ConfirmResetMailing",$object->ref),"confirm_reset",'','',2);
809
+        }
810
+        // Confirm delete
811
+        else if ($action == 'delete')
812
+        {
813
+            print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(! empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''),$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete",'','',1);
814
+        }
815
+
816
+
817
+        if ($action != 'edit' && $action != 'edithtml')
818
+        {
819
+            dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
820
+
821
+            /*
822 822
 			 * Mailing en mode visu
823 823
 			 */
824
-			if ($action == 'sendall')
825
-			{
824
+            if ($action == 'sendall')
825
+            {
826 826
                 // Define message to recommand from command line
827
-				$sendingmode=$conf->global->EMAILING_MAIL_SENDMODE;
828
-				if (empty($sendingmode)) $sendingmode=$conf->global->MAIN_MAIL_SENDMODE;
829
-				if (empty($sendingmode)) $sendingmode='mail';	// If not defined, we use php mail function
830
-
831
-				// MAILING_NO_USING_PHPMAIL may be defined or not.
832
-				// MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
833
-				// MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
834
-				if (! empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail')
835
-				{
836
-					// EMailing feature may be a spam problem, so when you host several users/instance, having this option may force each user to use their own SMTP agent.
837
-					// You ensure that every user is using its own SMTP server when using the mass emailing module.
838
-					$linktoadminemailbefore='<a href="'.DOL_URL_ROOT.'/admin/mails.php">';
839
-					$linktoadminemailend='</a>';
840
-					setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
841
-					setEventMessages($langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']), null, 'warnings');
842
-					if (! empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
843
-					$_GET["action"]='';
844
-				}
845
-				else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
846
-				{
847
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
848
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
849
-
850
-					// The feature is forbidden from GUI, we show just message to use from command line.
851
-				    setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
852
-					setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
853
-					if ($conf->file->mailing_limit_sendbyweb != '-1')  // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
854
-					{
855
-					   setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');  // You can send online with constant...
856
-					}
857
-					$_GET["action"]='';
858
-				}
859
-				else
860
-				{
861
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
862
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
863
-
864
-				    $text='';
865
-				    if ($conf->global->MAILING_LIMIT_SENDBYCLI >= 0)
827
+                $sendingmode=$conf->global->EMAILING_MAIL_SENDMODE;
828
+                if (empty($sendingmode)) $sendingmode=$conf->global->MAIN_MAIL_SENDMODE;
829
+                if (empty($sendingmode)) $sendingmode='mail';	// If not defined, we use php mail function
830
+
831
+                // MAILING_NO_USING_PHPMAIL may be defined or not.
832
+                // MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
833
+                // MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
834
+                if (! empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail')
835
+                {
836
+                    // EMailing feature may be a spam problem, so when you host several users/instance, having this option may force each user to use their own SMTP agent.
837
+                    // You ensure that every user is using its own SMTP server when using the mass emailing module.
838
+                    $linktoadminemailbefore='<a href="'.DOL_URL_ROOT.'/admin/mails.php">';
839
+                    $linktoadminemailend='</a>';
840
+                    setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
841
+                    setEventMessages($langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']), null, 'warnings');
842
+                    if (! empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
843
+                    $_GET["action"]='';
844
+                }
845
+                else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
846
+                {
847
+                    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
848
+                    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
849
+
850
+                    // The feature is forbidden from GUI, we show just message to use from command line.
851
+                    setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
852
+                    setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
853
+                    if ($conf->file->mailing_limit_sendbyweb != '-1')  // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
854
+                    {
855
+                        setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');  // You can send online with constant...
856
+                    }
857
+                    $_GET["action"]='';
858
+                }
859
+                else
860
+                {
861
+                    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
862
+                    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
863
+
864
+                    $text='';
865
+                    if ($conf->global->MAILING_LIMIT_SENDBYCLI >= 0)
866 866
                     {
867
-                    	$text.=$langs->trans("MailingNeedCommand");
868
-                    	$text.='<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
869
-                    	$text.='<br><br>';
867
+                        $text.=$langs->trans("MailingNeedCommand");
868
+                        $text.='<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
869
+                        $text.='<br><br>';
870 870
                     }
871
-				    $text.=$langs->trans('ConfirmSendingEmailing').'<br>';
872
-					$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
873
-					print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('SendMailing'),$text,'sendallconfirmed',$formquestion,'',1,300);
874
-				}
875
-			}
871
+                    $text.=$langs->trans('ConfirmSendingEmailing').'<br>';
872
+                    $text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
873
+                    print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('SendMailing'),$text,'sendallconfirmed',$formquestion,'',1,300);
874
+                }
875
+            }
876 876
 
877
-			$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
877
+            $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
878 878
 
879
-			$morehtmlright='';
880
-			$nbtry = $nbok = 0;
881
-			if ($object->statut == 2 || $object->statut == 3)
882
-			{
883
-				$nbtry = $object->countNbOfTargets('alreadysent');
884
-				$nbko  = $object->countNbOfTargets('alreadysentko');
879
+            $morehtmlright='';
880
+            $nbtry = $nbok = 0;
881
+            if ($object->statut == 2 || $object->statut == 3)
882
+            {
883
+                $nbtry = $object->countNbOfTargets('alreadysent');
884
+                $nbko  = $object->countNbOfTargets('alreadysentko');
885 885
 
886
-				$morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
887
-				if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
888
-				$morehtmlright.=') &nbsp; ';
889
-			}
886
+                $morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
887
+                if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
888
+                $morehtmlright.=') &nbsp; ';
889
+            }
890 890
 
891
-			dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
891
+            dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
892 892
 
893
-			print '<div class="fichecenter">';
894
-			print '<div class="underbanner clearboth"></div>';
893
+            print '<div class="fichecenter">';
894
+            print '<div class="underbanner clearboth"></div>';
895 895
 
896
-			print '<table class="border" width="100%">';
896
+            print '<table class="border" width="100%">';
897 897
 
898
-			// Description
899
-			print '<tr><td class="titlefield">'.$form->editfieldkey("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
900
-			print $form->editfieldval("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
901
-			print '</td></tr>';
898
+            // Description
899
+            print '<tr><td class="titlefield">'.$form->editfieldkey("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
900
+            print $form->editfieldval("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
901
+            print '</td></tr>';
902 902
 
903
-			// From
904
-			print '<tr><td>'.$form->editfieldkey("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
905
-			print $form->editfieldval("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
906
-			print '</td></tr>';
903
+            // From
904
+            print '<tr><td>'.$form->editfieldkey("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
905
+            print $form->editfieldval("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
906
+            print '</td></tr>';
907 907
 
908
-			// Errors to
909
-			print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
910
-			print $form->editfieldval("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
911
-			print '</td></tr>';
908
+            // Errors to
909
+            print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
910
+            print $form->editfieldval("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
911
+            print '</td></tr>';
912 912
 
913
-			// Nb of distinct emails
914
-			print '<tr><td>';
915
-			print $langs->trans("TotalNbOfDistinctRecipients");
916
-			print '</td><td colspan="3">';
917
-			$nbemail = ($object->nbemail?$object->nbemail:0);
918
-			if (is_numeric($nbemail))
919
-			{
920
-			    $text='';
921
-			    if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
922
-			    {
923
-    				if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
924
-    				{
925
-    					$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
926
-    				}
927
-    				else
928
-    				{
929
-    					$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
930
-    				}
931
-			    }
932
-			    if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
933
-				if ($text)
934
-    			{
935
-    			    print $form->textwithpicto($nbemail,$text,1,'warning');
936
-    			}
937
-    			else
938
-    			{
939
-    				print $nbemail;
940
-    			}
941
-			}
942
-			print '</td></tr>';
913
+            // Nb of distinct emails
914
+            print '<tr><td>';
915
+            print $langs->trans("TotalNbOfDistinctRecipients");
916
+            print '</td><td colspan="3">';
917
+            $nbemail = ($object->nbemail?$object->nbemail:0);
918
+            if (is_numeric($nbemail))
919
+            {
920
+                $text='';
921
+                if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
922
+                {
923
+                    if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
924
+                    {
925
+                        $text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
926
+                    }
927
+                    else
928
+                    {
929
+                        $text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
930
+                    }
931
+                }
932
+                if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
933
+                if ($text)
934
+                {
935
+                    print $form->textwithpicto($nbemail,$text,1,'warning');
936
+                }
937
+                else
938
+                {
939
+                    print $nbemail;
940
+                }
941
+            }
942
+            print '</td></tr>';
943 943
 
944
-			// Other attributes
945
-			include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
944
+            // Other attributes
945
+            include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
946 946
 
947
-			print '</table>';
947
+            print '</table>';
948 948
 
949
-			print "</div>";
949
+            print "</div>";
950 950
 
951
-			dol_fiche_end();
951
+            dol_fiche_end();
952 952
 
953 953
 
954
-			// Clone confirmation
955
-			if ($action == 'clone')
956
-			{
957
-				// Create an array for form
958
-				$formquestion=array(
959
-					'text' => $langs->trans("ConfirmClone"),
960
-				array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneContent"),   'value' => 1),
961
-				array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
962
-				);
963
-				// Paiement incomplet. On demande si motif = escompte ou autre
964
-				print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes',2,240);
965
-			}
954
+            // Clone confirmation
955
+            if ($action == 'clone')
956
+            {
957
+                // Create an array for form
958
+                $formquestion=array(
959
+                    'text' => $langs->trans("ConfirmClone"),
960
+                array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneContent"),   'value' => 1),
961
+                array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
962
+                );
963
+                // Paiement incomplet. On demande si motif = escompte ou autre
964
+                print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes',2,240);
965
+            }
966 966
 
967
-			/*
967
+            /*
968 968
 			 * Boutons d'action
969 969
 			 */
970 970
 
971
-			if (GETPOST('cancel','alpha') || $confirm=='no' || $action == '' || in_array($action,array('settodraft','valid','delete','sendall','clone','test')))
972
-			{
973
-				print "\n\n<div class=\"tabsAction\">\n";
974
-
975
-				if (($object->statut == 1) && ($user->rights->mailing->valider || $object->fk_user_valid == $user->id))
976
-				{
977
-					print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=settodraft&amp;id='.$object->id.'">'.$langs->trans("SetToDraft").'</a>';
978
-				}
979
-
980
-				if (($object->statut == 0 || $object->statut == 1) && $user->rights->mailing->creer)
981
-				{
982
-					if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_MAILING))
983
-					{
984
-						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
985
-					}
986
-					else
987
-					{
988
-						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
989
-					}
990
-
991
-					if (! empty($conf->use_javascript_ajax)) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
992
-				}
993
-
994
-				//print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
995
-
996
-				if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
997
-				{
998
-					print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
999
-				}
1000
-				else
1001
-				{
1002
-					print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&amp;id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
1003
-				}
1004
-
1005
-				if ($object->statut == 0)
1006
-				{
1007
-					if ($object->nbemail <= 0)
1008
-					{
1009
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
1010
-					}
1011
-					else if (empty($user->rights->mailing->valider))
1012
-					{
1013
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
1014
-					}
1015
-					else
1016
-					{
1017
-						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
1018
-					}
1019
-				}
1020
-
1021
-				if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->rights->mailing->valider)
1022
-				{
1023
-					if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
1024
-					{
1025
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
1026
-					}
1027
-					else if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1028
-					{
1029
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
1030
-					}
1031
-					else
1032
-					{
1033
-						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
1034
-					}
1035
-				}
1036
-
1037
-				if ($user->rights->mailing->creer)
1038
-				{
1039
-					print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
1040
-				}
1041
-
1042
-				if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider)
1043
-				{
1044
-					if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1045
-					{
1046
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
1047
-					}
1048
-					else
1049
-					{
1050
-						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
1051
-					}
1052
-				}
1053
-
1054
-				if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer)
1055
-				{
1056
-					if ($object->statut > 0 && (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->delete))
1057
-					{
1058
-						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
1059
-					}
1060
-					else
1061
-					{
1062
-						print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
1063
-					}
1064
-				}
1065
-
1066
-				print '</div>';
1067
-			}
1068
-
1069
-			// Affichage formulaire de TEST
1070
-			if ($action == 'test')
1071
-			{
1072
-			    print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1073
-			    print load_fiche_titre($langs->trans("TestMailing"));
1074
-
1075
-			    dol_fiche_head(null, '', '', -1);
1076
-
1077
-			    // Create l'objet formulaire mail
1078
-				include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1079
-				$formmail = new FormMail($db);
1080
-				$formmail->fromname = $object->email_from;
1081
-				$formmail->frommail = $object->email_from;
1082
-				$formmail->withsubstit=1;
1083
-				$formmail->withfrom=0;
1084
-				$formmail->withto=$user->email?$user->email:1;
1085
-				$formmail->withtocc=0;
1086
-				$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
1087
-				$formmail->withtopic=0;
1088
-				$formmail->withtopicreadonly=1;
1089
-				$formmail->withfile=0;
1090
-				$formmail->withbody=0;
1091
-				$formmail->withbodyreadonly=1;
1092
-				$formmail->withcancel=1;
1093
-				$formmail->withdeliveryreceipt=0;
1094
-				// Tableau des substitutions
1095
-				$formmail->substit=$object->substitutionarrayfortest;
1096
-				// Tableau des parametres complementaires du post
1097
-				$formmail->param["action"]="send";
1098
-				$formmail->param["models"]='none';
1099
-				$formmail->param["mailid"]=$object->id;
1100
-				$formmail->param["returnurl"]=$_SERVER['PHP_SELF']."?id=".$object->id;
1101
-
1102
-				print $formmail->get_form();
1103
-
1104
-				print '<br>';
1105
-
1106
-				dol_fiche_end();
1107
-
1108
-				print dol_set_focus('#sendto');
1109
-			}
1110
-
1111
-
1112
-			$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1113
-			foreach($object->substitutionarray as $key => $val)
1114
-			{
1115
-				$htmltext.=$key.' = '.$langs->trans($val).'<br>';
1116
-			}
1117
-			$htmltext.='</i>';
1118
-
1119
-			// Print mail content
1120
-			print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto('<span class="hideonsmartphone">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
1121
-
1122
-			dol_fiche_head('', '', '', -1);
1123
-
1124
-			print '<table class="bordernooddeven" width="100%">';
1125
-
1126
-			// Subject
1127
-			print '<tr><td class="titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
1128
-
1129
-			// Joined files
1130
-			print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
1131
-			// List of files
1132
-			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
1133
-			if (count($listofpaths))
1134
-			{
1135
-				foreach($listofpaths as $key => $val)
1136
-				{
1137
-					print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1138
-					print '<br>';
1139
-				}
1140
-			}
1141
-			else
1142
-			{
1143
-				print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1144
-			}
1145
-			print '</td></tr>';
971
+            if (GETPOST('cancel','alpha') || $confirm=='no' || $action == '' || in_array($action,array('settodraft','valid','delete','sendall','clone','test')))
972
+            {
973
+                print "\n\n<div class=\"tabsAction\">\n";
974
+
975
+                if (($object->statut == 1) && ($user->rights->mailing->valider || $object->fk_user_valid == $user->id))
976
+                {
977
+                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=settodraft&amp;id='.$object->id.'">'.$langs->trans("SetToDraft").'</a>';
978
+                }
979
+
980
+                if (($object->statut == 0 || $object->statut == 1) && $user->rights->mailing->creer)
981
+                {
982
+                    if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_MAILING))
983
+                    {
984
+                        print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
985
+                    }
986
+                    else
987
+                    {
988
+                        print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
989
+                    }
990
+
991
+                    if (! empty($conf->use_javascript_ajax)) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
992
+                }
993
+
994
+                //print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
995
+
996
+                if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
997
+                {
998
+                    print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
999
+                }
1000
+                else
1001
+                {
1002
+                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&amp;id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
1003
+                }
1004
+
1005
+                if ($object->statut == 0)
1006
+                {
1007
+                    if ($object->nbemail <= 0)
1008
+                    {
1009
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
1010
+                    }
1011
+                    else if (empty($user->rights->mailing->valider))
1012
+                    {
1013
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
1014
+                    }
1015
+                    else
1016
+                    {
1017
+                        print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
1018
+                    }
1019
+                }
1020
+
1021
+                if (($object->statut == 1 || $object->statut == 2) && $object->nbemail > 0 && $user->rights->mailing->valider)
1022
+                {
1023
+                    if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
1024
+                    {
1025
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
1026
+                    }
1027
+                    else if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1028
+                    {
1029
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
1030
+                    }
1031
+                    else
1032
+                    {
1033
+                        print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
1034
+                    }
1035
+                }
1036
+
1037
+                if ($user->rights->mailing->creer)
1038
+                {
1039
+                    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=clone&amp;object=emailing&amp;id='.$object->id.'">'.$langs->trans("ToClone").'</a>';
1040
+                }
1041
+
1042
+                if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider)
1043
+                {
1044
+                    if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1045
+                    {
1046
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
1047
+                    }
1048
+                    else
1049
+                    {
1050
+                        print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
1051
+                    }
1052
+                }
1053
+
1054
+                if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer)
1055
+                {
1056
+                    if ($object->statut > 0 && (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->delete))
1057
+                    {
1058
+                        print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
1059
+                    }
1060
+                    else
1061
+                    {
1062
+                        print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
1063
+                    }
1064
+                }
1065
+
1066
+                print '</div>';
1067
+            }
1068
+
1069
+            // Affichage formulaire de TEST
1070
+            if ($action == 'test')
1071
+            {
1072
+                print '<div id="formmailbeforetitle" name="formmailbeforetitle"></div>';
1073
+                print load_fiche_titre($langs->trans("TestMailing"));
1074
+
1075
+                dol_fiche_head(null, '', '', -1);
1076
+
1077
+                // Create l'objet formulaire mail
1078
+                include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1079
+                $formmail = new FormMail($db);
1080
+                $formmail->fromname = $object->email_from;
1081
+                $formmail->frommail = $object->email_from;
1082
+                $formmail->withsubstit=1;
1083
+                $formmail->withfrom=0;
1084
+                $formmail->withto=$user->email?$user->email:1;
1085
+                $formmail->withtocc=0;
1086
+                $formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
1087
+                $formmail->withtopic=0;
1088
+                $formmail->withtopicreadonly=1;
1089
+                $formmail->withfile=0;
1090
+                $formmail->withbody=0;
1091
+                $formmail->withbodyreadonly=1;
1092
+                $formmail->withcancel=1;
1093
+                $formmail->withdeliveryreceipt=0;
1094
+                // Tableau des substitutions
1095
+                $formmail->substit=$object->substitutionarrayfortest;
1096
+                // Tableau des parametres complementaires du post
1097
+                $formmail->param["action"]="send";
1098
+                $formmail->param["models"]='none';
1099
+                $formmail->param["mailid"]=$object->id;
1100
+                $formmail->param["returnurl"]=$_SERVER['PHP_SELF']."?id=".$object->id;
1101
+
1102
+                print $formmail->get_form();
1103
+
1104
+                print '<br>';
1105
+
1106
+                dol_fiche_end();
1107
+
1108
+                print dol_set_focus('#sendto');
1109
+            }
1110
+
1111
+
1112
+            $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1113
+            foreach($object->substitutionarray as $key => $val)
1114
+            {
1115
+                $htmltext.=$key.' = '.$langs->trans($val).'<br>';
1116
+            }
1117
+            $htmltext.='</i>';
1118
+
1119
+            // Print mail content
1120
+            print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto('<span class="hideonsmartphone">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
1121
+
1122
+            dol_fiche_head('', '', '', -1);
1123
+
1124
+            print '<table class="bordernooddeven" width="100%">';
1125
+
1126
+            // Subject
1127
+            print '<tr><td class="titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3">'.$object->sujet.'</td></tr>';
1128
+
1129
+            // Joined files
1130
+            print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
1131
+            // List of files
1132
+            $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
1133
+            if (count($listofpaths))
1134
+            {
1135
+                foreach($listofpaths as $key => $val)
1136
+                {
1137
+                    print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1138
+                    print '<br>';
1139
+                }
1140
+            }
1141
+            else
1142
+            {
1143
+                print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1144
+            }
1145
+            print '</td></tr>';
1146 1146
 
1147 1147
             // Background color
1148 1148
             /*print '<tr><td width="15%">'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1149 1149
             print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
1150 1150
             print '</td></tr>';*/
1151 1151
 
1152
-			print '</table>';
1153
-
1154
-		    // Message
1155
-			print '<div style="padding-top: 10px; background: '.($object->bgcolor?(preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor:'white').'">';
1156
-			if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff')	// CKEditor does not apply the color of the div into its content area
1157
-			{
1158
-				$readonly=1;
1159
-				// Editeur wysiwyg
1160
-				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1161
-				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',false,true,empty($conf->global->FCKEDITOR_ENABLE_MAILING)?0:1,20,'90%',$readonly);
1162
-				$doleditor->Create();
1163
-			}
1164
-			else print dol_htmlentitiesbr($object->body);
1165
-			print '</div>';
1166
-
1167
-			dol_fiche_end();
1168
-		}
1169
-		else
1170
-		{
1171
-			/*
1152
+            print '</table>';
1153
+
1154
+            // Message
1155
+            print '<div style="padding-top: 10px; background: '.($object->bgcolor?(preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor:'white').'">';
1156
+            if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff')	// CKEditor does not apply the color of the div into its content area
1157
+            {
1158
+                $readonly=1;
1159
+                // Editeur wysiwyg
1160
+                require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1161
+                $doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',false,true,empty($conf->global->FCKEDITOR_ENABLE_MAILING)?0:1,20,'90%',$readonly);
1162
+                $doleditor->Create();
1163
+            }
1164
+            else print dol_htmlentitiesbr($object->body);
1165
+            print '</div>';
1166
+
1167
+            dol_fiche_end();
1168
+        }
1169
+        else
1170
+        {
1171
+            /*
1172 1172
 			 * Mailing en mode edition (CKeditor or HTML source)
1173 1173
 			 */
1174 1174
 
1175
-			dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
1175
+            dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email');
1176 1176
 
1177
-			$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
1177
+            $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
1178 1178
 
1179
-			$morehtmlright='';
1180
-			if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1179
+            $morehtmlright='';
1180
+            if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1181 1181
 
1182
-			dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
1182
+            dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
1183 1183
 
1184
-			print '<div class="fichecenter">';
1185
-			print '<div class="underbanner clearboth"></div>';
1184
+            print '<div class="fichecenter">';
1185
+            print '<div class="underbanner clearboth"></div>';
1186 1186
 
1187
-			print '<table class="border" width="100%">';
1187
+            print '<table class="border" width="100%">';
1188 1188
 
1189
-			/*
1189
+            /*
1190 1190
 			print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td>';
1191 1191
 			print '<td colspan="3">';
1192 1192
 			print $form->showrefnav($object,'id', $linkback);
1193 1193
 			print '</td></tr>';
1194 1194
 			*/
1195 1195
 
1196
-			// Topic
1197
-			print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
1198
-			// From
1199
-			print '<tr><td class="titlefield">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
1200
-			// To
1201
-			print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1).'</td></tr>';
1202
-
1203
-			// Nb of distinct emails
1204
-			print '<tr><td>';
1205
-			print $langs->trans("TotalNbOfDistinctRecipients");
1206
-			print '</td><td colspan="3">';
1207
-			$nbemail = ($object->nbemail?$object->nbemail:0);
1208
-			if (is_numeric($nbemail))
1209
-			{
1210
-				$text='';
1211
-				if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2))
1212
-				{
1213
-					if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
1214
-					{
1215
-						$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
1216
-					}
1217
-					else
1218
-					{
1219
-						$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
1220
-					}
1221
-				}
1222
-				if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
1223
-				if ($text)
1224
-				{
1225
-					print $form->textwithpicto($nbemail,$text,1,'warning');
1226
-				}
1227
-				else
1228
-				{
1229
-					print $nbemail;
1230
-				}
1231
-			}
1232
-			print '</td></tr>';
1196
+            // Topic
1197
+            print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
1198
+            // From
1199
+            print '<tr><td class="titlefield">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
1200
+            // To
1201
+            print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1).'</td></tr>';
1202
+
1203
+            // Nb of distinct emails
1204
+            print '<tr><td>';
1205
+            print $langs->trans("TotalNbOfDistinctRecipients");
1206
+            print '</td><td colspan="3">';
1207
+            $nbemail = ($object->nbemail?$object->nbemail:0);
1208
+            if (is_numeric($nbemail))
1209
+            {
1210
+                $text='';
1211
+                if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2))
1212
+                {
1213
+                    if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
1214
+                    {
1215
+                        $text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
1216
+                    }
1217
+                    else
1218
+                    {
1219
+                        $text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
1220
+                    }
1221
+                }
1222
+                if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
1223
+                if ($text)
1224
+                {
1225
+                    print $form->textwithpicto($nbemail,$text,1,'warning');
1226
+                }
1227
+                else
1228
+                {
1229
+                    print $nbemail;
1230
+                }
1231
+            }
1232
+            print '</td></tr>';
1233 1233
 
1234
-			// Other attributes
1235
-			$parameters=array();
1236
-			$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1234
+            // Other attributes
1235
+            $parameters=array();
1236
+            $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1237 1237
             print $hookmanager->resPrint;
1238
-			if (empty($reshook))
1239
-			{
1240
-				print $object->showOptionals($extrafields,'edit');
1241
-			}
1238
+            if (empty($reshook))
1239
+            {
1240
+                print $object->showOptionals($extrafields,'edit');
1241
+            }
1242
+
1243
+            print '</table>';
1244
+            print '</div>';
1242 1245
 
1243
-			print '</table>';
1244
-			print '</div>';
1246
+            dol_fiche_end();
1245 1247
 
1246
-			dol_fiche_end();
1247 1248
 
1248 1249
 
1250
+            print "<br>\n";
1249 1251
 
1250
-			print "<br>\n";
1252
+            print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'."\n";
1253
+            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1254
+            print '<input type="hidden" name="action" value="update">';
1255
+            print '<input type="hidden" name="id" value="'.$object->id.'">';
1251 1256
 
1252
-			print '<form name="edit_mailing" action="card.php" method="post" enctype="multipart/form-data">'."\n";
1253
-			print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1254
-			print '<input type="hidden" name="action" value="update">';
1255
-			print '<input type="hidden" name="id" value="'.$object->id.'">';
1257
+            $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1258
+            foreach($object->substitutionarray as $key => $val)
1259
+            {
1260
+                $htmltext.=$key.' = '.$langs->trans($val).'<br>';
1261
+            }
1262
+            $htmltext.='</i>';
1263
+
1264
+            // Print mail content
1265
+            print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
1266
+
1267
+            dol_fiche_head(null, '', '', -1);
1268
+
1269
+            print '<table class="bordernooddeven" width="100%">';
1270
+
1271
+            // Subject
1272
+            print '<tr><td class="fieldrequired titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="'.$object->sujet.'"></td></tr>';
1273
+
1274
+            $trackid=''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
1275
+            dol_init_file_process($upload_dir, $trackid);
1276
+
1277
+            // Joined files
1278
+            $addfileaction='addfile';
1279
+            print '<tr><td>'.$langs->trans("MailFile").'</td>';
1280
+            print '<td colspan="3">';
1281
+            // List of files
1282
+            $listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
1283
+
1284
+            // TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
1285
+            $out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
1286
+            $out.= '<script type="text/javascript" language="javascript">';
1287
+            $out.= 'jQuery(document).ready(function () {';
1288
+            $out.= '    jQuery(".removedfile").click(function() {';
1289
+            $out.= '        jQuery(".removedfilehidden").val(jQuery(this).val());';
1290
+            $out.= '    });';
1291
+            $out.= '})';
1292
+            $out.= '</script>'."\n";
1293
+            if (count($listofpaths))
1294
+            {
1295
+                foreach($listofpaths as $key => $val)
1296
+                {
1297
+                    $out.= '<div id="attachfile_'.$key.'">';
1298
+                    $out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1299
+                    $out.= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"),'delete.png','','',1).'" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
1300
+                    $out.= '<br></div>';
1301
+                }
1302
+            }
1303
+            else
1304
+            {
1305
+                $out.= $langs->trans("NoAttachedFiles").'<br>';
1306
+            }
1307
+            // Add link to add file
1308
+            $out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
1309
+            $out.= ' ';
1310
+            $out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
1311
+            print $out;
1312
+            print '</td></tr>';
1256 1313
 
1257
-			$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1258
-			foreach($object->substitutionarray as $key => $val)
1259
-			{
1260
-				$htmltext.=$key.' = '.$langs->trans($val).'<br>';
1261
-			}
1262
-			$htmltext.='</i>';
1314
+            // Background color
1315
+            print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1316
+            print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
1317
+            print '</td></tr>';
1263 1318
 
1264
-			// Print mail content
1265
-			print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
1319
+            print '</table>';
1266 1320
 
1267
-			dol_fiche_head(null, '', '', -1);
1321
+            // Message
1322
+            print '<div style="padding-top: 10px">';
1268 1323
 
1269
-			print '<table class="bordernooddeven" width="100%">';
1324
+            if ($action == 'edit')
1325
+            {
1326
+                // Editeur wysiwyg
1327
+                require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1328
+                $doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
1329
+                $doleditor->Create();
1330
+            }
1331
+            if ($action == 'edithtml')
1332
+            {
1333
+                // Editor HTML source
1334
+                require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1335
+                $doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,'ace',20,'90%');
1336
+                $doleditor->Create(0, '', false, 'HTML Source', 'php');
1337
+            }
1270 1338
 
1271
-			// Subject
1272
-			print '<tr><td class="fieldrequired titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="'.$object->sujet.'"></td></tr>';
1339
+            print '</div>';
1273 1340
 
1274
-			$trackid=''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
1275
-			dol_init_file_process($upload_dir, $trackid);
1276 1341
 
1277
-			// Joined files
1278
-			$addfileaction='addfile';
1279
-			print '<tr><td>'.$langs->trans("MailFile").'</td>';
1280
-			print '<td colspan="3">';
1281
-			// List of files
1282
-			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
1283
-
1284
-			// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
1285
-			$out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
1286
-			$out.= '<script type="text/javascript" language="javascript">';
1287
-			$out.= 'jQuery(document).ready(function () {';
1288
-			$out.= '    jQuery(".removedfile").click(function() {';
1289
-			$out.= '        jQuery(".removedfilehidden").val(jQuery(this).val());';
1290
-			$out.= '    });';
1291
-			$out.= '})';
1292
-			$out.= '</script>'."\n";
1293
-			if (count($listofpaths))
1294
-			{
1295
-				foreach($listofpaths as $key => $val)
1296
-				{
1297
-					$out.= '<div id="attachfile_'.$key.'">';
1298
-					$out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1299
-					$out.= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"),'delete.png','','',1).'" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
1300
-					$out.= '<br></div>';
1301
-				}
1302
-			}
1303
-			else
1304
-			{
1305
-				$out.= $langs->trans("NoAttachedFiles").'<br>';
1306
-			}
1307
-			// Add link to add file
1308
-			$out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
1309
-			$out.= ' ';
1310
-			$out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
1311
-			print $out;
1312
-			print '</td></tr>';
1342
+            dol_fiche_end();
1313 1343
 
1314
-		    // Background color
1315
-			print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1316
-			print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
1317
-			print '</td></tr>';
1344
+            print '<div class="center">';
1345
+            print '<input type="submit" class="button buttonforacesave" value="'.$langs->trans("Save").'" name="save">';
1346
+            print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1347
+            print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
1348
+            print '</div>';
1318 1349
 
1319
-			print '</table>';
1320
-
1321
-			// Message
1322
-			print '<div style="padding-top: 10px">';
1323
-
1324
-			if ($action == 'edit')
1325
-			{
1326
-				// Editeur wysiwyg
1327
-				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1328
-				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
1329
-				$doleditor->Create();
1330
-			}
1331
-			if ($action == 'edithtml')
1332
-			{
1333
-				// Editor HTML source
1334
-				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1335
-				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,'ace',20,'90%');
1336
-				$doleditor->Create(0, '', false, 'HTML Source', 'php');
1337
-			}
1338
-
1339
-			print '</div>';
1340
-
1341
-
1342
-			dol_fiche_end();
1343
-
1344
-			print '<div class="center">';
1345
-			print '<input type="submit" class="button buttonforacesave" value="'.$langs->trans("Save").'" name="save">';
1346
-			print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1347
-			print '<input type="submit" class="button" value="'.$langs->trans("Cancel").'" name="cancel">';
1348
-			print '</div>';
1349
-
1350
-			print '</form>';
1351
-			print '<br>';
1352
-		}
1353
-	}
1354
-	else
1355
-	{
1356
-		dol_print_error($db,$object->error);
1357
-	}
1350
+            print '</form>';
1351
+            print '<br>';
1352
+        }
1353
+    }
1354
+    else
1355
+    {
1356
+        dol_print_error($db,$object->error);
1357
+    }
1358 1358
 }
1359 1359
 
1360 1360
 // End of page
Please login to merge, or discard this patch.
Braces   +149 added lines, -117 removed lines patch added patch discarded remove patch
@@ -23,7 +23,9 @@  discard block
 block discarded – undo
23 23
  *       \brief      Fiche mailing, onglet general
24 24
  */
25 25
 
26
-if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1');
26
+if (! defined('NOSTYLECHECK')) {
27
+    define('NOSTYLECHECK','1');
28
+}
27 29
 
28 30
 
29 31
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
@@ -41,7 +43,9 @@  discard block
 block discarded – undo
41 43
 // Load translation files required by the page
42 44
 $langs->load("mails");
43 45
 
44
-if (! $user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->societe_id > 0)) accessforbidden();
46
+if (! $user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->societe_id > 0)) {
47
+    accessforbidden();
48
+}
45 49
 
46 50
 $id=(GETPOST('mailid','int') ? GETPOST('mailid','int') : GETPOST('id','int'));
47 51
 $action=GETPOST('action','alpha');
@@ -87,7 +91,9 @@  discard block
 block discarded – undo
87 91
 
88 92
 $parameters=array();
89 93
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
90
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
94
+if ($reshook < 0) {
95
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
96
+}
91 97
 
92 98
 if (empty($reshook))
93 99
 {
@@ -97,16 +103,14 @@  discard block
 block discarded – undo
97 103
 		if (empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
98 104
 		{
99 105
 			setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
100
-		}
101
-		else
106
+		} else
102 107
 		{
103 108
 			$result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
104 109
 			if ($result > 0)
105 110
 			{
106 111
 				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
107 112
 				exit;
108
-			}
109
-			else
113
+			} else
110 114
 			{
111 115
 				setEventMessages($object->error, $object->errors, 'errors');
112 116
 			}
@@ -124,13 +128,11 @@  discard block
 block discarded – undo
124 128
 			setEventMessages('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
125 129
 			setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
126 130
 			$action='';
127
-		}
128
-		else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
131
+		} else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
129 132
 		{
130 133
 			setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings');
131 134
 			$action='';
132
-		}
133
-		else
135
+		} else
134 136
 		{
135 137
 			$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
136 138
 
@@ -148,7 +150,9 @@  discard block
 block discarded – undo
148 150
 			$errorsto = $object->email_errorsto;
149 151
 			// Le message est-il en html
150 152
 			$msgishtml=-1;	// Unknown by default
151
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
153
+			if (preg_match('/[\s\t]*<html>/i',$message)) {
154
+			    $msgishtml=1;
155
+			}
152 156
 
153 157
 			// Warning, we must not use begin-commit transaction here
154 158
 			// because we want to save update for each mail sent.
@@ -227,9 +231,15 @@  discard block
 block discarded – undo
227 231
 						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
228 232
 
229 233
 						$onlinepaymentenabled = 0;
230
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
231
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
232
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
234
+						if (! empty($conf->paypal->enabled)) {
235
+						    $onlinepaymentenabled++;
236
+						}
237
+						if (! empty($conf->paybox->enabled)) {
238
+						    $onlinepaymentenabled++;
239
+						}
240
+						if (! empty($conf->stripe->enabled)) {
241
+						    $onlinepaymentenabled++;
242
+						}
233 243
 						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
234 244
 						{
235 245
 							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
@@ -239,8 +249,7 @@  discard block
 block discarded – undo
239 249
 								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
240 250
 								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
241 251
 								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
242
-							}
243
-							else
252
+							} else
244 253
 							{
245 254
 								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
246 255
 								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
@@ -253,17 +262,29 @@  discard block
 block discarded – undo
253 262
 						{
254 263
 							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
255 264
 
256
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
257
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
265
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
266
+							    $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
267
+							} else {
268
+							    $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
269
+							}
258 270
 
259
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
260
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
271
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
272
+							    $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
273
+							} else {
274
+							    $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
275
+							}
261 276
 
262
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
263
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
277
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
278
+							    $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
279
+							} else {
280
+							    $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
281
+							}
264 282
 
265
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
266
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
283
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) {
284
+							    $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
285
+							} else {
286
+							    $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
287
+							}
267 288
 						}
268 289
 						//$substitutionisok=true;
269 290
 
@@ -320,8 +341,7 @@  discard block
 block discarded – undo
320 341
 							if (! $resql2)
321 342
 							{
322 343
 								dol_print_error($db);
323
-							}
324
-							else
344
+							} else
325 345
 							{
326 346
 								//if cheack read is use then update prospect contact status
327 347
 								if (strpos($message, '__CHECK_READ__') !== false)
@@ -353,8 +373,7 @@  discard block
 block discarded – undo
353 373
                         	}
354 374
 
355 375
                         	//test if CHECK READ change statut prospect contact
356
-						}
357
-						else
376
+						} else
358 377
 						{
359 378
 							// Mail failed
360 379
 							$nbko++;
@@ -372,8 +391,7 @@  discard block
 block discarded – undo
372 391
 
373 392
 						$i++;
374 393
 					}
375
-				}
376
-				else
394
+				} else
377 395
 				{
378 396
 					setEventMessages($langs->transnoentitiesnoconv("NoMoreRecipientToSendTo"), null, 'mesgs');
379 397
 				}
@@ -382,17 +400,18 @@  discard block
 block discarded – undo
382 400
 				if ($nbko > 0)
383 401
 				{
384 402
 					$statut=2;	// Status 'sent partially' (because at least one error)
385
-					if ($nbok > 0) 	setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
386
-					else setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
387
-				}
388
-				else
403
+					if ($nbok > 0) {
404
+					    setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
405
+					} else {
406
+					    setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
407
+					}
408
+				} else
389 409
 				{
390 410
 					if ($nbok >= $num)
391 411
 					{
392 412
 						$statut=3;	// Send to everybody
393 413
 						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
394
-					}
395
-					else
414
+					} else
396 415
 					{
397 416
 						$statut=2;	// Status 'sent partially' (because not send to everybody)
398 417
 						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
@@ -406,8 +425,7 @@  discard block
 block discarded – undo
406 425
 				{
407 426
 					dol_print_error($db);
408 427
 				}
409
-			}
410
-			else
428
+			} else
411 429
 			{
412 430
 				dol_syslog($db->error());
413 431
 				dol_print_error($db);
@@ -435,7 +453,9 @@  discard block
 block discarded – undo
435 453
 		{
436 454
 			// Le message est-il en html
437 455
 			$msgishtml=-1;	// Inconnu par defaut
438
-			if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
456
+			if (preg_match('/[\s\t]*<html>/i',$object->body)) {
457
+			    $msgishtml=1;
458
+			}
439 459
 
440 460
 			// other are set at begin of page
441 461
 			$object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;
@@ -452,8 +472,12 @@  discard block
 block discarded – undo
452 472
 			$arr_css  = array();
453 473
 
454 474
 	        // Ajout CSS
455
-	        if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
456
-	        if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
475
+	        if (!empty($object->bgcolor)) {
476
+	            $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
477
+	        }
478
+	        if (!empty($object->bgimage)) {
479
+	            $arr_css['bgimage'] = $object->bgimage;
480
+	        }
457 481
 
458 482
 	        // Attached files
459 483
 			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
@@ -474,8 +498,7 @@  discard block
 block discarded – undo
474 498
 			if ($result)
475 499
 			{
476 500
 				setEventMessages($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)), null, 'mesgs');
477
-			}
478
-			else
501
+			} else
479 502
 			{
480 503
 				setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, null, 'errors');
481 504
 			}
@@ -527,14 +550,17 @@  discard block
 block discarded – undo
527 550
 	{
528 551
 		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
529 552
 
530
-		if ($action == 'settitre')					$object->titre          = trim(GETPOST('titre','alpha'));
531
-		else if ($action == 'setemail_from')		$object->email_from     = trim(GETPOST('email_from','alpha'));
532
-		else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
533
-		else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
534
-		else if ($action == 'settitre' && empty($object->titre)) {
553
+		if ($action == 'settitre') {
554
+		    $object->titre          = trim(GETPOST('titre','alpha'));
555
+		} else if ($action == 'setemail_from') {
556
+		    $object->email_from     = trim(GETPOST('email_from','alpha'));
557
+		} else if ($action == 'setemail_replyto') {
558
+		    $object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
559
+		} else if ($action == 'setemail_errorsto') {
560
+		    $object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
561
+		} else if ($action == 'settitre' && empty($object->titre)) {
535 562
 			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
536
-		}
537
-		else if ($action == 'setfrom' && empty($object->email_from)) {
563
+		} else if ($action == 'setfrom' && empty($object->email_from)) {
538 564
 			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
539 565
 		}
540 566
 
@@ -614,8 +640,7 @@  discard block
 block discarded – undo
614 640
 
615 641
 			setEventMessages($mesg, $mesgs, 'errors');
616 642
 			$action="edit";
617
-		}
618
-		else
643
+		} else
619 644
 		{
620 645
 			$action="edit";
621 646
 		}
@@ -630,8 +655,7 @@  discard block
 block discarded – undo
630 655
 			setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
631 656
 			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
632 657
 			exit;
633
-		}
634
-		else
658
+		} else
635 659
 		{
636 660
 			dol_print_error($db);
637 661
 		}
@@ -648,13 +672,11 @@  discard block
 block discarded – undo
648 672
     			//setEventMessages($langs->trans("MailingSuccessfullyValidated"), null, 'mesgs');
649 673
     			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
650 674
     			exit;
651
-            }
652
-            else
675
+            } else
653 676
             {
654 677
                 setEventMessages($object->error, $object->errors, 'errors');
655 678
             }
656
-		}
657
-		else
679
+		} else
658 680
 		{
659 681
 			dol_print_error($db);
660 682
 		}
@@ -678,14 +700,12 @@  discard block
 block discarded – undo
678 700
 				$db->commit();
679 701
 				header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
680 702
 				exit;
681
-			}
682
-			else
703
+			} else
683 704
 			{
684 705
 				setEventMessages($object->error, $object->errors, 'errors');
685 706
 				$db->rollback();
686 707
 			}
687
-		}
688
-		else
708
+		} else
689 709
 		{
690 710
 			dol_print_error($db);
691 711
 		}
@@ -786,8 +806,7 @@  discard block
 block discarded – undo
786 806
 	print '<div class="center"><input type="submit" class="button" value="'.$langs->trans("CreateMailing").'"></div>';
787 807
 
788 808
 	print '</form>';
789
-}
790
-else
809
+} else
791 810
 {
792 811
 	if ($object->id > 0)
793 812
 	{
@@ -828,8 +847,13 @@  discard block
 block discarded – undo
828 847
 			{
829 848
                 // Define message to recommand from command line
830 849
 				$sendingmode=$conf->global->EMAILING_MAIL_SENDMODE;
831
-				if (empty($sendingmode)) $sendingmode=$conf->global->MAIN_MAIL_SENDMODE;
832
-				if (empty($sendingmode)) $sendingmode='mail';	// If not defined, we use php mail function
850
+				if (empty($sendingmode)) {
851
+				    $sendingmode=$conf->global->MAIN_MAIL_SENDMODE;
852
+				}
853
+				if (empty($sendingmode)) {
854
+				    $sendingmode='mail';
855
+				}
856
+				// If not defined, we use php mail function
833 857
 
834 858
 				// MAILING_NO_USING_PHPMAIL may be defined or not.
835 859
 				// MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
@@ -842,27 +866,38 @@  discard block
 block discarded – undo
842 866
 					$linktoadminemailend='</a>';
843 867
 					setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
844 868
 					setEventMessages($langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']), null, 'warnings');
845
-					if (! empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
869
+					if (! empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) {
870
+					    setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
871
+					}
846 872
 					$_GET["action"]='';
847
-				}
848
-				else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
873
+				} else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
849 874
 				{
850
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
851
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
875
+				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
876
+				        setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
877
+				    }
878
+				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
879
+				        setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
880
+				    }
852 881
 
853 882
 					// The feature is forbidden from GUI, we show just message to use from command line.
854 883
 				    setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
855 884
 					setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
856
-					if ($conf->file->mailing_limit_sendbyweb != '-1')  // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
885
+					if ($conf->file->mailing_limit_sendbyweb != '-1') {
886
+					    // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
857 887
 					{
858
-					   setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');  // You can send online with constant...
888
+					   setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
889
+					}
890
+					// You can send online with constant...
859 891
 					}
860 892
 					$_GET["action"]='';
861
-				}
862
-				else
893
+				} else
863 894
 				{
864
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
865
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
895
+				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') {
896
+				        setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
897
+				    }
898
+				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') {
899
+				        setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
900
+				    }
866 901
 
867 902
 				    $text='';
868 903
 				    if ($conf->global->MAILING_LIMIT_SENDBYCLI >= 0)
@@ -887,7 +922,9 @@  discard block
 block discarded – undo
887 922
 				$nbko  = $object->countNbOfTargets('alreadysentko');
888 923
 
889 924
 				$morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
890
-				if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
925
+				if ($nbko) {
926
+				    $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
927
+				}
891 928
 				$morehtmlright.=') &nbsp; ';
892 929
 			}
893 930
 
@@ -926,18 +963,18 @@  discard block
 block discarded – undo
926 963
     				if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
927 964
     				{
928 965
     					$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
929
-    				}
930
-    				else
966
+    				} else
931 967
     				{
932 968
     					$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
933 969
     				}
934 970
 			    }
935
-			    if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
971
+			    if (empty($nbemail)) {
972
+			        $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
973
+			    }
936 974
 				if ($text)
937 975
     			{
938 976
     			    print $form->textwithpicto($nbemail,$text,1,'warning');
939
-    			}
940
-    			else
977
+    			} else
941 978
     			{
942 979
     				print $nbemail;
943 980
     			}
@@ -985,13 +1022,14 @@  discard block
 block discarded – undo
985 1022
 					if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_MAILING))
986 1023
 					{
987 1024
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
988
-					}
989
-					else
1025
+					} else
990 1026
 					{
991 1027
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
992 1028
 					}
993 1029
 
994
-					if (! empty($conf->use_javascript_ajax)) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
1030
+					if (! empty($conf->use_javascript_ajax)) {
1031
+					    print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
1032
+					}
995 1033
 				}
996 1034
 
997 1035
 				//print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
@@ -999,8 +1037,7 @@  discard block
 block discarded – undo
999 1037
 				if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1000 1038
 				{
1001 1039
 					print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
1002
-				}
1003
-				else
1040
+				} else
1004 1041
 				{
1005 1042
 					print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=test&amp;id='.$object->id.'">'.$langs->trans("TestMailing").'</a>';
1006 1043
 				}
@@ -1010,12 +1047,10 @@  discard block
 block discarded – undo
1010 1047
 					if ($object->nbemail <= 0)
1011 1048
 					{
1012 1049
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NoTargetYet")).'">'.$langs->trans("ValidMailing").'</a>';
1013
-					}
1014
-					else if (empty($user->rights->mailing->valider))
1050
+					} else if (empty($user->rights->mailing->valider))
1015 1051
 					{
1016 1052
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ValidMailing").'</a>';
1017
-					}
1018
-					else
1053
+					} else
1019 1054
 					{
1020 1055
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=valid&amp;id='.$object->id.'">'.$langs->trans("ValidMailing").'</a>';
1021 1056
 					}
@@ -1026,12 +1061,10 @@  discard block
 block discarded – undo
1026 1061
 					if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
1027 1062
 					{
1028 1063
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
1029
-					}
1030
-					else if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1064
+					} else if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1031 1065
 					{
1032 1066
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
1033
-					}
1034
-					else
1067
+					} else
1035 1068
 					{
1036 1069
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=sendall&amp;id='.$object->id.'">'.$langs->trans("SendMailing").'</a>';
1037 1070
 					}
@@ -1047,8 +1080,7 @@  discard block
 block discarded – undo
1047 1080
 					if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1048 1081
 					{
1049 1082
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
1050
-					}
1051
-					else
1083
+					} else
1052 1084
 					{
1053 1085
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=reset&amp;id='.$object->id.'">'.$langs->trans("ResetMailing").'</a>';
1054 1086
 					}
@@ -1059,8 +1091,7 @@  discard block
 block discarded – undo
1059 1091
 					if ($object->statut > 0 && (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->delete))
1060 1092
 					{
1061 1093
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
1062
-					}
1063
-					else
1094
+					} else
1064 1095
 					{
1065 1096
 						print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
1066 1097
 					}
@@ -1140,8 +1171,7 @@  discard block
 block discarded – undo
1140 1171
 					print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1141 1172
 					print '<br>';
1142 1173
 				}
1143
-			}
1144
-			else
1174
+			} else
1145 1175
 			{
1146 1176
 				print '<span class="opacitymedium">'.$langs->trans("NoAttachedFiles").'</span><br>';
1147 1177
 			}
@@ -1156,20 +1186,22 @@  discard block
 block discarded – undo
1156 1186
 
1157 1187
 		    // Message
1158 1188
 			print '<div style="padding-top: 10px; background: '.($object->bgcolor?(preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor:'white').'">';
1159
-			if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff')	// CKEditor does not apply the color of the div into its content area
1189
+			if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff') {
1190
+			    // CKEditor does not apply the color of the div into its content area
1160 1191
 			{
1161 1192
 				$readonly=1;
1193
+			}
1162 1194
 				// Editeur wysiwyg
1163 1195
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1164 1196
 				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',false,true,empty($conf->global->FCKEDITOR_ENABLE_MAILING)?0:1,20,'90%',$readonly);
1165 1197
 				$doleditor->Create();
1198
+			} else {
1199
+			    print dol_htmlentitiesbr($object->body);
1166 1200
 			}
1167
-			else print dol_htmlentitiesbr($object->body);
1168 1201
 			print '</div>';
1169 1202
 
1170 1203
 			dol_fiche_end();
1171
-		}
1172
-		else
1204
+		} else
1173 1205
 		{
1174 1206
 			/*
1175 1207
 			 * Mailing en mode edition (CKeditor or HTML source)
@@ -1180,7 +1212,9 @@  discard block
 block discarded – undo
1180 1212
 			$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
1181 1213
 
1182 1214
 			$morehtmlright='';
1183
-			if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1215
+			if ($object->statut == 2) {
1216
+			    $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1217
+			}
1184 1218
 
1185 1219
 			dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
1186 1220
 
@@ -1216,18 +1250,18 @@  discard block
 block discarded – undo
1216 1250
 					if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
1217 1251
 					{
1218 1252
 						$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
1219
-					}
1220
-					else
1253
+					} else
1221 1254
 					{
1222 1255
 						$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
1223 1256
 					}
1224 1257
 				}
1225
-				if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
1258
+				if (empty($nbemail)) {
1259
+				    $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
1260
+				}
1226 1261
 				if ($text)
1227 1262
 				{
1228 1263
 					print $form->textwithpicto($nbemail,$text,1,'warning');
1229
-				}
1230
-				else
1264
+				} else
1231 1265
 				{
1232 1266
 					print $nbemail;
1233 1267
 				}
@@ -1302,8 +1336,7 @@  discard block
 block discarded – undo
1302 1336
 					$out.= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"),'delete.png','','',1).'" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
1303 1337
 					$out.= '<br></div>';
1304 1338
 				}
1305
-			}
1306
-			else
1339
+			} else
1307 1340
 			{
1308 1341
 				$out.= $langs->trans("NoAttachedFiles").'<br>';
1309 1342
 			}
@@ -1353,8 +1386,7 @@  discard block
 block discarded – undo
1353 1386
 			print '</form>';
1354 1387
 			print '<br>';
1355 1388
 		}
1356
-	}
1357
-	else
1389
+	} else
1358 1390
 	{
1359 1391
 		dol_print_error($db,$object->error);
1360 1392
 	}
Please login to merge, or discard this patch.
Spacing   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -23,12 +23,12 @@  discard block
 block discarded – undo
23 23
  *       \brief      Fiche mailing, onglet general
24 24
  */
25 25
 
26
-if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1');
26
+if (!defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1');
27 27
 
28 28
 
29 29
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
30 30
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
31
-require DOL_BASE_PATH . '/main.inc.php';
31
+require DOL_BASE_PATH.'/main.inc.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
@@ -41,43 +41,43 @@  discard block
 block discarded – undo
41 41
 // Load translation files required by the page
42 42
 $langs->load("mails");
43 43
 
44
-if (! $user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->societe_id > 0)) accessforbidden();
44
+if (!$user->rights->mailing->lire || (empty($conf->global->EXTERNAL_USERS_ARE_AUTHORIZED) && $user->societe_id > 0)) accessforbidden();
45 45
 
46
-$id=(GETPOST('mailid','int') ? GETPOST('mailid','int') : GETPOST('id','int'));
47
-$action=GETPOST('action','alpha');
48
-$confirm=GETPOST('confirm','alpha');
49
-$urlfrom=GETPOST('urlfrom');
46
+$id = (GETPOST('mailid', 'int') ? GETPOST('mailid', 'int') : GETPOST('id', 'int'));
47
+$action = GETPOST('action', 'alpha');
48
+$confirm = GETPOST('confirm', 'alpha');
49
+$urlfrom = GETPOST('urlfrom');
50 50
 
51
-$object=new Mailing($db);
52
-$result=$object->fetch($id);
51
+$object = new Mailing($db);
52
+$result = $object->fetch($id);
53 53
 
54 54
 $extrafields = new ExtraFields($db);
55 55
 
56 56
 // fetch optionals attributes and labels
57
-$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
57
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
58 58
 
59 59
 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
60
-$hookmanager->initHooks(array('mailingcard','globalcard'));
60
+$hookmanager->initHooks(array('mailingcard', 'globalcard'));
61 61
 
62 62
 // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
63
-$object->substitutionarray=FormMail::getAvailableSubstitKey('emailing');
63
+$object->substitutionarray = FormMail::getAvailableSubstitKey('emailing');
64 64
 
65 65
 
66 66
 // Set $object->substitutionarrayfortest
67
-$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
67
+$signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
68 68
 
69
-$targetobject = null;		// Not defined with mass emailing
69
+$targetobject = null; // Not defined with mass emailing
70 70
 
71
-$parameters=array('mode'=>'emailing');
72
-$substitutionarray=FormMail::getAvailableSubstitKey('emailing', $targetobject);
71
+$parameters = array('mode'=>'emailing');
72
+$substitutionarray = FormMail::getAvailableSubstitKey('emailing', $targetobject);
73 73
 
74 74
 $object->substitutionarrayfortest = $substitutionarray;
75 75
 
76 76
 // List of sending methods
77
-$listofmethods=array();
78
-$listofmethods['mail']='PHP mail function';
77
+$listofmethods = array();
78
+$listofmethods['mail'] = 'PHP mail function';
79 79
 //$listofmethods['simplemail']='Simplemail class';
80
-$listofmethods['smtps']='SMTP/SMTPS socket library';
80
+$listofmethods['smtps'] = 'SMTP/SMTPS socket library';
81 81
 
82 82
 
83 83
 
@@ -85,8 +85,8 @@  discard block
 block discarded – undo
85 85
  * Actions
86 86
  */
87 87
 
88
-$parameters=array();
89
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
88
+$parameters = array();
89
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
90 90
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
91 91
 
92 92
 if (empty($reshook))
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		}
101 101
 		else
102 102
 		{
103
-			$result=$object->createFromClone($object->id,$_REQUEST["clone_content"],$_REQUEST["clone_receivers"]);
103
+			$result = $object->createFromClone($object->id, $_REQUEST["clone_content"], $_REQUEST["clone_receivers"]);
104 104
 			if ($result > 0)
105 105
 			{
106 106
 				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 				setEventMessages($object->error, $object->errors, 'errors');
112 112
 			}
113 113
 		}
114
-	    $action='';
114
+	    $action = '';
115 115
 	}
116 116
 
117 117
 	// Action send emailing for everybody
@@ -123,20 +123,20 @@  discard block
 block discarded – undo
123 123
 			setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
124 124
 			setEventMessages('<textarea cols="70" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
125 125
 			setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');
126
-			$action='';
126
+			$action = '';
127 127
 		}
128 128
 		else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
129 129
 		{
130 130
 			setEventMessages($langs->trans("NotEnoughPermissions"), null, 'warnings');
131
-			$action='';
131
+			$action = '';
132 132
 		}
133 133
 		else
134 134
 		{
135
-			$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
135
+			$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
136 136
 
137 137
 			if ($object->statut == 0)
138 138
 			{
139
-				dol_print_error('','ErrorMailIsNotValidated');
139
+				dol_print_error('', 'ErrorMailIsNotValidated');
140 140
 				exit;
141 141
 			}
142 142
 
@@ -147,37 +147,37 @@  discard block
 block discarded – undo
147 147
 			$replyto  = $object->email_replyto;
148 148
 			$errorsto = $object->email_errorsto;
149 149
 			// Le message est-il en html
150
-			$msgishtml=-1;	// Unknown by default
151
-			if (preg_match('/[\s\t]*<html>/i',$message)) $msgishtml=1;
150
+			$msgishtml = -1; // Unknown by default
151
+			if (preg_match('/[\s\t]*<html>/i', $message)) $msgishtml = 1;
152 152
 
153 153
 			// Warning, we must not use begin-commit transaction here
154 154
 			// because we want to save update for each mail sent.
155 155
 
156
-			$nbok=0; $nbko=0;
156
+			$nbok = 0; $nbko = 0;
157 157
 
158 158
 			// On choisit les mails non deja envoyes pour ce mailing (statut=0)
159 159
 			// ou envoyes en erreur (statut=-1)
160 160
 			$sql = "SELECT mc.rowid, mc.fk_mailing, mc.lastname, mc.firstname, mc.email, mc.other, mc.source_url, mc.source_id, mc.source_type, mc.tag";
161 161
 			$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
162 162
 			$sql .= " WHERE mc.statut < 1 AND mc.fk_mailing = ".$object->id;
163
-			$sql .= " ORDER BY mc.statut DESC";		// first status 0, then status -1
163
+			$sql .= " ORDER BY mc.statut DESC"; // first status 0, then status -1
164 164
 
165 165
 			dol_syslog("card.php: select targets", LOG_DEBUG);
166
-			$resql=$db->query($sql);
166
+			$resql = $db->query($sql);
167 167
 			if ($resql)
168 168
 			{
169
-				$num = $db->num_rows($resql);	// nb of possible recipients
169
+				$num = $db->num_rows($resql); // nb of possible recipients
170 170
 
171 171
 				if ($num)
172 172
 				{
173 173
 					dol_syslog("comm/mailing/card.php: nb of targets = ".$num, LOG_DEBUG);
174 174
 
175
-					$now=dol_now();
175
+					$now = dol_now();
176 176
 
177 177
 					// Positionne date debut envoi
178
-					$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$object->id;
179
-					$resql2=$db->query($sql);
180
-					if (! $resql2)
178
+					$sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET date_envoi='".$db->idate($now)."' WHERE rowid=".$object->id;
179
+					$resql2 = $db->query($sql);
180
+					if (!$resql2)
181 181
 					{
182 182
 						dol_print_error($db);
183 183
 					}
@@ -188,27 +188,27 @@  discard block
 block discarded – undo
188 188
 					while ($i < $num && $i < $conf->global->MAILING_LIMIT_SENDBYWEB)
189 189
 					{
190 190
 						// Here code is common with same loop ino mailing-send.php
191
-						$res=1;
192
-						$now=dol_now();
191
+						$res = 1;
192
+						$now = dol_now();
193 193
 
194 194
 						$obj = $db->fetch_object($resql);
195 195
 
196 196
 						// sendto en RFC2822
197
-						$sendto = str_replace(',',' ',dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
197
+						$sendto = str_replace(',', ' ', dolGetFirstLastname($obj->firstname, $obj->lastname))." <".$obj->email.">";
198 198
 
199 199
 						// Make substitutions on topic and body. From (AA=YY;BB=CC;...) we keep YY, CC, ...
200
-						$other=explode(';',$obj->other);
201
-						$tmpfield=explode('=',$other[0],2); $other1=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
202
-	                    $tmpfield=explode('=',$other[1],2); $other2=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
203
-	                    $tmpfield=explode('=',$other[2],2); $other3=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
204
-	                    $tmpfield=explode('=',$other[3],2); $other4=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
205
-	                    $tmpfield=explode('=',$other[4],2); $other5=(isset($tmpfield[1])?$tmpfield[1]:$tmpfield[0]);
200
+						$other = explode(';', $obj->other);
201
+						$tmpfield = explode('=', $other[0], 2); $other1 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
202
+	                    $tmpfield = explode('=', $other[1], 2); $other2 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
203
+	                    $tmpfield = explode('=', $other[2], 2); $other3 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
204
+	                    $tmpfield = explode('=', $other[3], 2); $other4 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
205
+	                    $tmpfield = explode('=', $other[4], 2); $other5 = (isset($tmpfield[1]) ? $tmpfield[1] : $tmpfield[0]);
206 206
 
207
-	                    $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN))?$user->signature:'');
207
+	                    $signature = ((!empty($user->signature) && empty($conf->global->MAIN_MAIL_DO_NOT_USE_SIGN)) ? $user->signature : '');
208 208
 
209
-	                    $targetobject = null;		// Not defined with mass emailing
210
-	                    $parameters=array('mode'=>'emailing');
211
-	                    $substitutionarray=getCommonSubstitutionArray($langs, 0, array('object','objectamount'), $targetobject);			// Note: On mass emailing, this is null because be don't know object
209
+	                    $targetobject = null; // Not defined with mass emailing
210
+	                    $parameters = array('mode'=>'emailing');
211
+	                    $substitutionarray = getCommonSubstitutionArray($langs, 0, array('object', 'objectamount'), $targetobject); // Note: On mass emailing, this is null because be don't know object
212 212
 
213 213
 	                    // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions)
214 214
 						$substitutionarray['__ID__'] = $obj->source_id;
@@ -221,79 +221,79 @@  discard block
 block discarded – undo
221 221
 						$substitutionarray['__OTHER3__'] = $other3;
222 222
 						$substitutionarray['__OTHER4__'] = $other4;
223 223
 						$substitutionarray['__OTHER5__'] = $other5;
224
-						$substitutionarray['__USER_SIGNATURE__'] = $signature;	// Signature is empty when ran from command line or taken from user in parameter)
225
-						$substitutionarray['__SIGNATURE__'] = $signature;	// For backward compatibility
224
+						$substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter)
225
+						$substitutionarray['__SIGNATURE__'] = $signature; // For backward compatibility
226 226
 						$substitutionarray['__CHECK_READ__'] = '<img src="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-read.php?tag='.$obj->tag.'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
227 227
 						$substitutionarray['__UNSUBSCRIBE__'] = '<a href="'.DOL_MAIN_URL_ROOT.'/public/emailing/mailing-unsubscribe.php?tag='.$obj->tag.'&unsuscrib=1&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).'" target="_blank">'.$langs->trans("MailUnsubcribe").'</a>';
228 228
 
229 229
 						$onlinepaymentenabled = 0;
230
-						if (! empty($conf->paypal->enabled)) $onlinepaymentenabled++;
231
-						if (! empty($conf->paybox->enabled)) $onlinepaymentenabled++;
232
-						if (! empty($conf->stripe->enabled)) $onlinepaymentenabled++;
233
-						if ($onlinepaymentenabled && ! empty($conf->global->PAYMENT_SECURITY_TOKEN))
230
+						if (!empty($conf->paypal->enabled)) $onlinepaymentenabled++;
231
+						if (!empty($conf->paybox->enabled)) $onlinepaymentenabled++;
232
+						if (!empty($conf->stripe->enabled)) $onlinepaymentenabled++;
233
+						if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN))
234 234
 						{
235
-							$substitutionarray['__SECUREKEYPAYMENT__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
235
+							$substitutionarray['__SECUREKEYPAYMENT__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
236 236
 							if (empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE))
237 237
 							{
238
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
239
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
240
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
241
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
238
+								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
239
+								$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
240
+								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
241
+								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN, 2);
242 242
 							}
243 243
 							else
244 244
 							{
245
-								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
246
-								$substitutionarray['__SECUREKEYPAYMENT_ORDER__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
247
-								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
248
-								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__']=dol_hash($conf->global->PAYMENT_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
245
+								$substitutionarray['__SECUREKEYPAYMENT_MEMBER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2);
246
+								$substitutionarray['__SECUREKEYPAYMENT_ORDER__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'order'.$obj->source_id, 2);
247
+								$substitutionarray['__SECUREKEYPAYMENT_INVOICE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
248
+								$substitutionarray['__SECUREKEYPAYMENT_CONTRACTLINE__'] = dol_hash($conf->global->PAYMENT_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
249 249
 							}
250 250
 						}
251 251
 						/* For backward compatibility, deprecated */
252
-						if (! empty($conf->paypal->enabled) && ! empty($conf->global->PAYPAL_SECURITY_TOKEN))
252
+						if (!empty($conf->paypal->enabled) && !empty($conf->global->PAYPAL_SECURITY_TOKEN))
253 253
 						{
254
-							$substitutionarray['__SECUREKEYPAYPAL__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
254
+							$substitutionarray['__SECUREKEYPAYPAL__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
255 255
 
256
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
257
-							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'membersubscription' . $obj->source_id, 2);
256
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
257
+							else $substitutionarray['__SECUREKEYPAYPAL_MEMBER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'membersubscription'.$obj->source_id, 2);
258 258
 
259
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
260
-							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2);
259
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
260
+							else $substitutionarray['__SECUREKEYPAYPAL_ORDER__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'order'.$obj->source_id, 2);
261 261
 
262
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
263
-							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2);
262
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
263
+							else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'invoice'.$obj->source_id, 2);
264 264
 
265
-							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
266
-							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2);
265
+							if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2);
266
+							else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__'] = dol_hash($conf->global->PAYPAL_SECURITY_TOKEN.'contractline'.$obj->source_id, 2);
267 267
 						}
268 268
 						//$substitutionisok=true;
269 269
 
270 270
 	                    complete_substitutions_array($substitutionarray, $langs);
271
-						$newsubject=make_substitutions($subject,$substitutionarray);
272
-						$newmessage=make_substitutions($message,$substitutionarray);
271
+						$newsubject = make_substitutions($subject, $substitutionarray);
272
+						$newmessage = make_substitutions($message, $substitutionarray);
273 273
 
274 274
 						$arr_file = array();
275 275
 						$arr_mime = array();
276 276
 						$arr_name = array();
277 277
 						$arr_css  = array();
278 278
 
279
-						$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
279
+						$listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
280 280
 						if (count($listofpaths))
281 281
 						{
282
-							foreach($listofpaths as $key => $val)
282
+							foreach ($listofpaths as $key => $val)
283 283
 							{
284
-								$arr_file[]=$listofpaths[$key]['fullname'];
285
-								$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
286
-								$arr_name[]=$listofpaths[$key]['name'];
284
+								$arr_file[] = $listofpaths[$key]['fullname'];
285
+								$arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
286
+								$arr_name[] = $listofpaths[$key]['name'];
287 287
 							}
288 288
 						}
289 289
 
290 290
 						// Fabrication du mail
291
-						$trackid='emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
291
+						$trackid = 'emailing-'.$obj->fk_mailing.'-'.$obj->rowid;
292 292
 						$mail = new CMailFile($newsubject, $sendto, $from, $newmessage, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $errorsto, $arr_css, $trackid, '', 'emailing');
293 293
 
294 294
 						if ($mail->error)
295 295
 						{
296
-							$res=0;
296
+							$res = 0;
297 297
 						}
298 298
 						/*if (! $substitutionisok)
299 299
 						{
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 						// Send mail
305 305
 						if ($res)
306 306
 						{
307
-							$res=$mail->sendfile();
307
+							$res = $mail->sendfile();
308 308
 						}
309 309
 
310 310
 						if ($res)
@@ -312,12 +312,12 @@  discard block
 block discarded – undo
312 312
 							// Mail successful
313 313
 							$nbok++;
314 314
 
315
-							dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG);
315
+							dol_syslog("comm/mailing/card.php: ok for #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_DEBUG);
316 316
 
317
-							$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
318
-							$sql.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
319
-							$resql2=$db->query($sql);
320
-							if (! $resql2)
317
+							$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
318
+							$sql .= " SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
319
+							$resql2 = $db->query($sql);
320
+							if (!$resql2)
321 321
 							{
322 322
 								dol_print_error($db);
323 323
 							}
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 									//Update status communication of thirdparty prospect
330 330
 									$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$obj->rowid.")";
331 331
 									dol_syslog("card.php: set prospect thirdparty status", LOG_DEBUG);
332
-									$resql2=$db->query($sql);
333
-									if (! $resql2)
332
+									$resql2 = $db->query($sql);
333
+									if (!$resql2)
334 334
 									{
335 335
 										dol_print_error($db);
336 336
 									}
@@ -339,8 +339,8 @@  discard block
 block discarded – undo
339 339
 									$sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=2 WHERE rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.rowid=".$obj->rowid." AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)";
340 340
 									dol_syslog("card.php: set prospect contact status", LOG_DEBUG);
341 341
 
342
-									$resql2=$db->query($sql);
343
-									if (! $resql2)
342
+									$resql2 = $db->query($sql);
343
+									if (!$resql2)
344 344
 									{
345 345
 										dol_print_error($db);
346 346
 									}
@@ -359,12 +359,12 @@  discard block
 block discarded – undo
359 359
 							// Mail failed
360 360
 							$nbko++;
361 361
 
362
-							dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error?' - '.$mail->error:''), LOG_WARNING);
362
+							dol_syslog("comm/mailing/card.php: error for #".$i.($mail->error ? ' - '.$mail->error : ''), LOG_WARNING);
363 363
 
364
-							$sql="UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
365
-							$sql.=" SET statut=-1, error_text='".$db->escape($mail->error)."', date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
366
-							$resql2=$db->query($sql);
367
-							if (! $resql2)
364
+							$sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles";
365
+							$sql .= " SET statut=-1, error_text='".$db->escape($mail->error)."', date_envoi='".$db->idate($now)."' WHERE rowid=".$obj->rowid;
366
+							$resql2 = $db->query($sql);
367
+							if (!$resql2)
368 368
 							{
369 369
 								dol_print_error($db);
370 370
 							}
@@ -381,28 +381,28 @@  discard block
 block discarded – undo
381 381
 				// Loop finished, set global statut of mail
382 382
 				if ($nbko > 0)
383 383
 				{
384
-					$statut=2;	// Status 'sent partially' (because at least one error)
385
-					if ($nbok > 0) 	setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
386
-					else setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
384
+					$statut = 2; // Status 'sent partially' (because at least one error)
385
+					if ($nbok > 0) 	setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
386
+					else setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
387 387
 				}
388 388
 				else
389 389
 				{
390 390
 					if ($nbok >= $num)
391 391
 					{
392
-						$statut=3;	// Send to everybody
393
-						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
392
+						$statut = 3; // Send to everybody
393
+						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
394 394
 					}
395 395
 					else
396 396
 					{
397
-						$statut=2;	// Status 'sent partially' (because not send to everybody)
398
-						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients",$nbok), null, 'mesgs');
397
+						$statut = 2; // Status 'sent partially' (because not send to everybody)
398
+						setEventMessages($langs->transnoentitiesnoconv("EMailSentToNRecipients", $nbok), null, 'mesgs');
399 399
 					}
400 400
 				}
401 401
 
402
-				$sql="UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
402
+				$sql = "UPDATE ".MAIN_DB_PREFIX."mailing SET statut=".$statut." WHERE rowid=".$object->id;
403 403
 				dol_syslog("comm/mailing/card.php: update global status", LOG_DEBUG);
404
-				$resql2=$db->query($sql);
405
-				if (! $resql2)
404
+				$resql2 = $db->query($sql);
405
+				if (!$resql2)
406 406
 				{
407 407
 					dol_print_error($db);
408 408
 				}
@@ -420,22 +420,22 @@  discard block
 block discarded – undo
420 420
 	// Action send test emailing
421 421
 	if ($action == 'send' && empty($_POST["cancel"]))
422 422
 	{
423
-		$error=0;
423
+		$error = 0;
424 424
 
425
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
425
+		$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
426 426
 
427 427
 		$object->sendto = $_POST["sendto"];
428
-		if (! $object->sendto)
428
+		if (!$object->sendto)
429 429
 		{
430 430
 			setEventMessages($langs->trans("ErrorFieldRequired", $langs->trans("MailTo")), null, 'errors');
431 431
 			$error++;
432 432
 		}
433 433
 
434
-		if (! $error)
434
+		if (!$error)
435 435
 		{
436 436
 			// Le message est-il en html
437
-			$msgishtml=-1;	// Inconnu par defaut
438
-			if (preg_match('/[\s\t]*<html>/i',$object->body)) $msgishtml=1;
437
+			$msgishtml = -1; // Inconnu par defaut
438
+			if (preg_match('/[\s\t]*<html>/i', $object->body)) $msgishtml = 1;
439 439
 
440 440
 			// other are set at begin of page
441 441
 			$object->substitutionarrayfortest['__EMAIL__'] = $object->sendto;
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 
444 444
 			// Pratique les substitutions sur le sujet et message
445 445
 	        complete_substitutions_array($object->substitutionarrayfortest, $langs);
446
-			$tmpsujet=make_substitutions($object->sujet,$object->substitutionarrayfortest);
447
-			$tmpbody=make_substitutions($object->body,$object->substitutionarrayfortest);
446
+			$tmpsujet = make_substitutions($object->sujet, $object->substitutionarrayfortest);
447
+			$tmpbody = make_substitutions($object->body, $object->substitutionarrayfortest);
448 448
 
449 449
 			$arr_file = array();
450 450
 			$arr_mime = array();
@@ -452,35 +452,35 @@  discard block
 block discarded – undo
452 452
 			$arr_css  = array();
453 453
 
454 454
 	        // Ajout CSS
455
-	        if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor;
455
+	        if (!empty($object->bgcolor)) $arr_css['bgcolor'] = (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor;
456 456
 	        if (!empty($object->bgimage)) $arr_css['bgimage'] = $object->bgimage;
457 457
 
458 458
 	        // Attached files
459
-			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
459
+			$listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
460 460
 			if (count($listofpaths))
461 461
 			{
462
-				foreach($listofpaths as $key => $val)
462
+				foreach ($listofpaths as $key => $val)
463 463
 				{
464
-					$arr_file[]=$listofpaths[$key]['fullname'];
465
-					$arr_mime[]=dol_mimetype($listofpaths[$key]['name']);
466
-					$arr_name[]=$listofpaths[$key]['name'];
464
+					$arr_file[] = $listofpaths[$key]['fullname'];
465
+					$arr_mime[] = dol_mimetype($listofpaths[$key]['name']);
466
+					$arr_name[] = $listofpaths[$key]['name'];
467 467
 				}
468 468
 			}
469 469
 
470
-			$trackid='emailingtest';
470
+			$trackid = 'emailingtest';
471 471
 			$mailfile = new CMailFile($tmpsujet, $object->sendto, $object->email_from, $tmpbody, $arr_file, $arr_mime, $arr_name, '', '', 0, $msgishtml, $object->email_errorsto, $arr_css, $trackid, '', 'emailing');
472 472
 
473
-			$result=$mailfile->sendfile();
473
+			$result = $mailfile->sendfile();
474 474
 			if ($result)
475 475
 			{
476
-				setEventMessages($langs->trans("MailSuccessfulySent",$mailfile->getValidAddress($object->email_from,2),$mailfile->getValidAddress($object->sendto,2)), null, 'mesgs');
476
+				setEventMessages($langs->trans("MailSuccessfulySent", $mailfile->getValidAddress($object->email_from, 2), $mailfile->getValidAddress($object->sendto, 2)), null, 'mesgs');
477 477
 			}
478 478
 			else
479 479
 			{
480 480
 				setEventMessages($langs->trans("ResultKo").'<br>'.$mailfile->error.' '.$result, null, 'errors');
481 481
 			}
482 482
 
483
-			$action='';
483
+			$action = '';
484 484
 		}
485 485
 	}
486 486
 
@@ -498,14 +498,14 @@  discard block
 block discarded – undo
498 498
 		$object->bgcolor        = trim($_POST["bgcolor"]);
499 499
 		$object->bgimage        = trim($_POST["bgimage"]);
500 500
 
501
-		if (! $object->titre) {
502
-			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
501
+		if (!$object->titre) {
502
+			$mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
503 503
 		}
504
-		if (! $object->sujet) {
505
-			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
504
+		if (!$object->sujet) {
505
+			$mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
506 506
 		}
507
-		if (! $object->body)  {
508
-			$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
507
+		if (!$object->body) {
508
+			$mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
509 509
 		}
510 510
 
511 511
 		if (!count($mesgs))
@@ -519,26 +519,26 @@  discard block
 block discarded – undo
519 519
 		}
520 520
 
521 521
 		setEventMessages($mesg, $mesgs, 'errors');
522
-		$action="create";
522
+		$action = "create";
523 523
 	}
524 524
 
525 525
 	// Action update description of emailing
526 526
 	if ($action == 'settitre' || $action == 'setemail_from' || $action == 'setreplyto' || $action == 'setemail_errorsto')
527 527
 	{
528
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
528
+		$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
529 529
 
530
-		if ($action == 'settitre')					$object->titre          = trim(GETPOST('titre','alpha'));
531
-		else if ($action == 'setemail_from')		$object->email_from     = trim(GETPOST('email_from','alpha'));
532
-		else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto','alpha'));
533
-		else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto','alpha'));
530
+		if ($action == 'settitre')					$object->titre = trim(GETPOST('titre', 'alpha'));
531
+		else if ($action == 'setemail_from')		$object->email_from = trim(GETPOST('email_from', 'alpha'));
532
+		else if ($action == 'setemail_replyto')		$object->email_replyto  = trim(GETPOST('email_replyto', 'alpha'));
533
+		else if ($action == 'setemail_errorsto')	$object->email_errorsto = trim(GETPOST('email_errorsto', 'alpha'));
534 534
 		else if ($action == 'settitre' && empty($object->titre)) {
535
-			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTitle"));
535
+			$mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTitle"));
536 536
 		}
537 537
 		else if ($action == 'setfrom' && empty($object->email_from)) {
538
-			$mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailFrom"));
538
+			$mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailFrom"));
539 539
 		}
540 540
 
541
-		if (! $mesg)
541
+		if (!$mesg)
542 542
 		{
543 543
 			if ($object->update($user) >= 0)
544 544
 			{
@@ -549,34 +549,34 @@  discard block
 block discarded – undo
549 549
 		}
550 550
 
551 551
 		setEventMessages($mesg, $mesgs, 'errors');
552
-		$action="";
552
+		$action = "";
553 553
 	}
554 554
 
555 555
 	/*
556 556
 	 * Add file in email form
557 557
 	 */
558
-	if (! empty($_POST['addfile']))
558
+	if (!empty($_POST['addfile']))
559 559
 	{
560
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
560
+		$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
561 561
 
562 562
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
563 563
 
564 564
 	    // Set tmp user directory
565
-	    dol_add_file_process($upload_dir,0,0);
565
+	    dol_add_file_process($upload_dir, 0, 0);
566 566
 
567
-		$action="edit";
567
+		$action = "edit";
568 568
 	}
569 569
 
570 570
 	// Action remove file
571
-	if (! empty($_POST["removedfile"]))
571
+	if (!empty($_POST["removedfile"]))
572 572
 	{
573
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
573
+		$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
574 574
 
575 575
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
576 576
 
577
-	    dol_remove_file_process($_POST['removedfile'],0,0);    // We really delete file linked to mailing
577
+	    dol_remove_file_process($_POST['removedfile'], 0, 0); // We really delete file linked to mailing
578 578
 
579
-		$action="edit";
579
+		$action = "edit";
580 580
 	}
581 581
 
582 582
 	// Action update emailing
@@ -584,9 +584,9 @@  discard block
 block discarded – undo
584 584
 	{
585 585
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
586 586
 
587
-		$isupload=0;
587
+		$isupload = 0;
588 588
 
589
-		if (! $isupload)
589
+		if (!$isupload)
590 590
 		{
591 591
 			$mesgs = array();
592 592
 
@@ -595,11 +595,11 @@  discard block
 block discarded – undo
595 595
 			$object->bgcolor        = trim($_POST["bgcolor"]);
596 596
 			$object->bgimage        = trim($_POST["bgimage"]);
597 597
 
598
-			if (! $object->sujet) {
599
-				$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailTopic"));
598
+			if (!$object->sujet) {
599
+				$mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailTopic"));
600 600
 			}
601
-			if (! $object->body) {
602
-				$mesgs[] = $langs->trans("ErrorFieldRequired",$langs->transnoentities("MailMessage"));
601
+			if (!$object->body) {
602
+				$mesgs[] = $langs->trans("ErrorFieldRequired", $langs->transnoentities("MailMessage"));
603 603
 			}
604 604
 
605 605
 			if (!count($mesgs))
@@ -609,15 +609,15 @@  discard block
 block discarded – undo
609 609
 					header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
610 610
 					exit;
611 611
 				}
612
-				$mesgs[] =$object->error;
612
+				$mesgs[] = $object->error;
613 613
 			}
614 614
 
615 615
 			setEventMessages($mesg, $mesgs, 'errors');
616
-			$action="edit";
616
+			$action = "edit";
617 617
 		}
618 618
 		else
619 619
 		{
620
-			$action="edit";
620
+			$action = "edit";
621 621
 		}
622 622
 	}
623 623
 
@@ -667,10 +667,10 @@  discard block
 block discarded – undo
667 667
 		{
668 668
 			$db->begin();
669 669
 
670
-			$result=$object->valid($user);
670
+			$result = $object->valid($user);
671 671
 			if ($result > 0)
672 672
 			{
673
-				$result=$object->reset_targets_status($user);
673
+				$result = $object->reset_targets_status($user);
674 674
 			}
675 675
 
676 676
 			if ($result > 0)
@@ -696,13 +696,13 @@  discard block
 block discarded – undo
696 696
 	{
697 697
 		if ($object->delete($object->id))
698 698
 		{
699
-			$url= (! empty($urlfrom) ? $urlfrom : 'list.php');
699
+			$url = (!empty($urlfrom) ? $urlfrom : 'list.php');
700 700
 			header("Location: ".$url);
701 701
 			exit;
702 702
 		}
703 703
 	}
704 704
 
705
-	if (! empty($_POST["cancel"]))
705
+	if (!empty($_POST["cancel"]))
706 706
 	{
707 707
 		$action = '';
708 708
 	}
@@ -716,7 +716,7 @@  discard block
 block discarded – undo
716 716
 $form = new Form($db);
717 717
 $htmlother = new FormOther($db);
718 718
 
719
-$help_url='EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
719
+$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
720 720
 llxHeader('', $langs->trans("Mailing"), $help_url, '', 0, 0,
721 721
 	array(
722 722
 	'/includes/ace/ace.js',
@@ -733,14 +733,14 @@  discard block
 block discarded – undo
733 733
 	print '<input type="hidden" name="action" value="add">';
734 734
 
735 735
 	$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
736
-	foreach($object->substitutionarray as $key => $val)
736
+	foreach ($object->substitutionarray as $key => $val)
737 737
 	{
738
-		$htmltext.=$key.' = '.$langs->trans($val).'<br>';
738
+		$htmltext .= $key.' = '.$langs->trans($val).'<br>';
739 739
 	}
740
-	$htmltext.='</i>';
740
+	$htmltext .= '</i>';
741 741
 
742 742
 
743
-	$availablelink=$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
743
+	$availablelink = $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar');
744 744
 	//print '<a href="javascript:document_preview(\''.DOL_URL_ROOT.'/admin/modulehelp.php?id='.$objMod->numero.'\',\'text/html\',\''.dol_escape_js($langs->trans("Module")).'\')">'.img_picto($langs->trans("ClickToShowDescription"), $imginfo).'</a>';
745 745
 
746 746
 
@@ -752,15 +752,15 @@  discard block
 block discarded – undo
752 752
 	print '<table class="border" width="100%">';
753 753
 	print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTitle").'</td><td><input class="flat minwidth300" name="titre" value="'.dol_escape_htmltag(GETPOST('titre')).'" autofocus="autofocus"></td></tr>';
754 754
 	print '<tr><td class="fieldrequired">'.$langs->trans("MailFrom").'</td><td><input class="flat minwidth200" name="from" value="'.$conf->global->MAILING_EMAIL_FROM.'"></td></tr>';
755
-	print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td><input class="flat minwidth200" name="errorsto" value="'.(!empty($conf->global->MAILING_EMAIL_ERRORSTO)?$conf->global->MAILING_EMAIL_ERRORSTO:$conf->global->MAIN_MAIL_ERRORS_TO).'"></td></tr>';
755
+	print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td><input class="flat minwidth200" name="errorsto" value="'.(!empty($conf->global->MAILING_EMAIL_ERRORSTO) ? $conf->global->MAILING_EMAIL_ERRORSTO : $conf->global->MAIN_MAIL_ERRORS_TO).'"></td></tr>';
756 756
 
757 757
 	// Other attributes
758
-	$parameters=array();
759
-	$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
758
+	$parameters = array();
759
+	$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
760 760
     print $hookmanager->resPrint;
761 761
 	if (empty($reshook))
762 762
 	{
763
-		print $object->showOptionals($extrafields,'edit');
763
+		print $object->showOptionals($extrafields, 'edit');
764 764
 	}
765 765
 
766 766
 	print '</table>';
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	print '<table class="border" width="100%">';
770 770
 	print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("MailTopic").'</td><td><input class="flat minwidth200 quatrevingtpercent" name="sujet" value="'.dol_escape_htmltag(GETPOST('sujet')).'"></td></tr>';
771 771
 	print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
772
-	print $htmlother->selectColor($_POST['bgcolor'],'bgcolor','',0);
772
+	print $htmlother->selectColor($_POST['bgcolor'], 'bgcolor', '', 0);
773 773
 	print '</td></tr>';
774 774
 
775 775
 	print '</table>';
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	print '<div style="padding-top: 10px">';
778 778
 	// Editeur wysiwyg
779 779
 	require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
780
-	$doleditor=new DolEditor('bodyemail',GETPOST('bodyemail','none'),'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
780
+	$doleditor = new DolEditor('bodyemail', GETPOST('bodyemail', 'none'), '', 600, 'dolibarr_mailings', '', true, true, $conf->global->FCKEDITOR_ENABLE_MAILING, 20, '90%');
781 781
 	$doleditor->Create();
782 782
 	print '</div>';
783 783
 
@@ -791,29 +791,29 @@  discard block
 block discarded – undo
791 791
 {
792 792
 	if ($object->id > 0)
793 793
 	{
794
-		$upload_dir = $conf->mailing->dir_output . "/" . get_exdir($object->id,2,0,1,$object,'mailing');
794
+		$upload_dir = $conf->mailing->dir_output."/".get_exdir($object->id, 2, 0, 1, $object, 'mailing');
795 795
 
796 796
 		$head = emailing_prepare_head($object);
797 797
 
798 798
 		// Confirmation back to draft
799 799
 		if ($action == 'settodraft')
800 800
 		{
801
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("SetToDraft"),$langs->trans("ConfirmUnvalidateEmailing"),"confirm_settodraft",'','',1);
801
+			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("SetToDraft"), $langs->trans("ConfirmUnvalidateEmailing"), "confirm_settodraft", '', '', 1);
802 802
 		}
803 803
 		// Confirmation validation of mailing
804 804
 		if ($action == 'valid')
805 805
 		{
806
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ValidMailing"),$langs->trans("ConfirmValidMailing"),"confirm_valid",'','',1);
806
+			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ValidMailing"), $langs->trans("ConfirmValidMailing"), "confirm_valid", '', '', 1);
807 807
 		}
808 808
 		// Confirm reset
809 809
 		else if ($action == 'reset')
810 810
 		{
811
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id,$langs->trans("ResetMailing"),$langs->trans("ConfirmResetMailing",$object->ref),"confirm_reset",'','',2);
811
+			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans("ResetMailing"), $langs->trans("ConfirmResetMailing", $object->ref), "confirm_reset", '', '', 2);
812 812
 		}
813 813
 		// Confirm delete
814 814
 		else if ($action == 'delete')
815 815
 		{
816
-			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(! empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''),$langs->trans("DeleteAMailing"),$langs->trans("ConfirmDeleteMailing"),"confirm_delete",'','',1);
816
+			print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id.(!empty($urlfrom) ? '&urlfrom='.urlencode($urlfrom) : ''), $langs->trans("DeleteAMailing"), $langs->trans("ConfirmDeleteMailing"), "confirm_delete", '', '', 1);
817 817
 		}
818 818
 
819 819
 
@@ -827,68 +827,68 @@  discard block
 block discarded – undo
827 827
 			if ($action == 'sendall')
828 828
 			{
829 829
                 // Define message to recommand from command line
830
-				$sendingmode=$conf->global->EMAILING_MAIL_SENDMODE;
831
-				if (empty($sendingmode)) $sendingmode=$conf->global->MAIN_MAIL_SENDMODE;
832
-				if (empty($sendingmode)) $sendingmode='mail';	// If not defined, we use php mail function
830
+				$sendingmode = $conf->global->EMAILING_MAIL_SENDMODE;
831
+				if (empty($sendingmode)) $sendingmode = $conf->global->MAIN_MAIL_SENDMODE;
832
+				if (empty($sendingmode)) $sendingmode = 'mail'; // If not defined, we use php mail function
833 833
 
834 834
 				// MAILING_NO_USING_PHPMAIL may be defined or not.
835 835
 				// MAILING_LIMIT_SENDBYWEB is always defined to something != 0 (-1=forbidden).
836 836
 				// MAILING_LIMIT_SENDBYCLI may be defined ot not (-1=forbidden, 0 or undefined=no limit).
837
-				if (! empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail')
837
+				if (!empty($conf->global->MAILING_NO_USING_PHPMAIL) && $sendingmode == 'mail')
838 838
 				{
839 839
 					// EMailing feature may be a spam problem, so when you host several users/instance, having this option may force each user to use their own SMTP agent.
840 840
 					// You ensure that every user is using its own SMTP server when using the mass emailing module.
841
-					$linktoadminemailbefore='<a href="'.DOL_URL_ROOT.'/admin/mails.php">';
842
-					$linktoadminemailend='</a>';
841
+					$linktoadminemailbefore = '<a href="'.DOL_URL_ROOT.'/admin/mails.php">';
842
+					$linktoadminemailend = '</a>';
843 843
 					setEventMessages($langs->trans("MailSendSetupIs", $listofmethods[$sendingmode]), null, 'warnings');
844 844
 					setEventMessages($langs->trans("MailSendSetupIs2", $linktoadminemailbefore, $linktoadminemailend, $langs->transnoentitiesnoconv("MAIN_MAIL_SENDMODE"), $listofmethods['smtps']), null, 'warnings');
845
-					if (! empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
846
-					$_GET["action"]='';
845
+					if (!empty($conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS)) setEventMessages($langs->trans("MailSendSetupIs3", $conf->global->MAILING_SMTP_SETUP_EMAILS_FOR_QUESTIONS), null, 'warnings');
846
+					$_GET["action"] = '';
847 847
 				}
848 848
 				else if ($conf->global->MAILING_LIMIT_SENDBYWEB < 0)
849 849
 				{
850
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
851
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
850
+				    if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
851
+				    if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
852 852
 
853 853
 					// The feature is forbidden from GUI, we show just message to use from command line.
854 854
 				    setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings');
855 855
 					setEventMessages('<textarea cols="60" rows="'.ROWS_1.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.'</textarea>', null, 'warnings');
856 856
 					if ($conf->file->mailing_limit_sendbyweb != '-1')  // MAILING_LIMIT_SENDBYWEB was set to -1 in database, but it is allowed ot increase it.
857 857
 					{
858
-					   setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings');  // You can send online with constant...
858
+					   setEventMessages($langs->trans("MailingNeedCommand2"), null, 'warnings'); // You can send online with constant...
859 859
 					}
860
-					$_GET["action"]='';
860
+					$_GET["action"] = '';
861 861
 				}
862 862
 				else
863 863
 				{
864
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
865
-				    if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
864
+				    if (!empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings');
865
+				    if (!empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings');
866 866
 
867
-				    $text='';
867
+				    $text = '';
868 868
 				    if ($conf->global->MAILING_LIMIT_SENDBYCLI >= 0)
869 869
                     {
870
-                    	$text.=$langs->trans("MailingNeedCommand");
871
-                    	$text.='<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
872
-                    	$text.='<br><br>';
870
+                    	$text .= $langs->trans("MailingNeedCommand");
871
+                    	$text .= '<br><textarea cols="60" rows="'.ROWS_2.'" wrap="soft">php ./scripts/emailings/mailing-send.php '.$object->id.' '.$user->login.'</textarea>';
872
+                    	$text .= '<br><br>';
873 873
                     }
874
-				    $text.=$langs->trans('ConfirmSendingEmailing').'<br>';
875
-					$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
876
-					print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id,$langs->trans('SendMailing'),$text,'sendallconfirmed',$formquestion,'',1,300);
874
+				    $text .= $langs->trans('ConfirmSendingEmailing').'<br>';
875
+					$text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
876
+					print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('SendMailing'), $text, 'sendallconfirmed', $formquestion, '', 1, 300);
877 877
 				}
878 878
 			}
879 879
 
880 880
 			$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
881 881
 
882
-			$morehtmlright='';
882
+			$morehtmlright = '';
883 883
 			$nbtry = $nbok = 0;
884 884
 			if ($object->statut == 2 || $object->statut == 3)
885 885
 			{
886 886
 				$nbtry = $object->countNbOfTargets('alreadysent');
887 887
 				$nbko  = $object->countNbOfTargets('alreadysentko');
888 888
 
889
-				$morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
890
-				if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
891
-				$morehtmlright.=') &nbsp; ';
889
+				$morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
890
+				if ($nbko) $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
891
+				$morehtmlright .= ') &nbsp; ';
892 892
 			}
893 893
 
894 894
 			dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
@@ -899,43 +899,43 @@  discard block
 block discarded – undo
899 899
 			print '<table class="border" width="100%">';
900 900
 
901 901
 			// Description
902
-			print '<tr><td class="titlefield">'.$form->editfieldkey("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
903
-			print $form->editfieldval("MailTitle",'titre',$object->titre,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
902
+			print '<tr><td class="titlefield">'.$form->editfieldkey("MailTitle", 'titre', $object->titre, $object, $user->rights->mailing->creer && $object->statut < 3, 'string').'</td><td colspan="3">';
903
+			print $form->editfieldval("MailTitle", 'titre', $object->titre, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
904 904
 			print '</td></tr>';
905 905
 
906 906
 			// From
907
-			print '<tr><td>'.$form->editfieldkey("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
908
-			print $form->editfieldval("MailFrom",'email_from',$object->email_from,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
907
+			print '<tr><td>'.$form->editfieldkey("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string').'</td><td colspan="3">';
908
+			print $form->editfieldval("MailFrom", 'email_from', $object->email_from, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
909 909
 			print '</td></tr>';
910 910
 
911 911
 			// Errors to
912
-			print '<tr><td>'.$form->editfieldkey("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string').'</td><td colspan="3">';
913
-			print $form->editfieldval("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string');
912
+			print '<tr><td>'.$form->editfieldkey("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string').'</td><td colspan="3">';
913
+			print $form->editfieldval("MailErrorsTo", 'email_errorsto', $object->email_errorsto, $object, $user->rights->mailing->creer && $object->statut < 3, 'string');
914 914
 			print '</td></tr>';
915 915
 
916 916
 			// Nb of distinct emails
917 917
 			print '<tr><td>';
918 918
 			print $langs->trans("TotalNbOfDistinctRecipients");
919 919
 			print '</td><td colspan="3">';
920
-			$nbemail = ($object->nbemail?$object->nbemail:0);
920
+			$nbemail = ($object->nbemail ? $object->nbemail : 0);
921 921
 			if (is_numeric($nbemail))
922 922
 			{
923
-			    $text='';
924
-			    if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
923
+			    $text = '';
924
+			    if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
925 925
 			    {
926 926
     				if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
927 927
     				{
928
-    					$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
928
+    					$text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
929 929
     				}
930 930
     				else
931 931
     				{
932
-    					$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
932
+    					$text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
933 933
     				}
934 934
 			    }
935
-			    if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
935
+			    if (empty($nbemail)) $nbemail .= ' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
936 936
 				if ($text)
937 937
     			{
938
-    			    print $form->textwithpicto($nbemail,$text,1,'warning');
938
+    			    print $form->textwithpicto($nbemail, $text, 1, 'warning');
939 939
     			}
940 940
     			else
941 941
     			{
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 			print '</td></tr>';
946 946
 
947 947
 			// Other attributes
948
-			include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php';
948
+			include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
949 949
 
950 950
 			print '</table>';
951 951
 
@@ -958,20 +958,20 @@  discard block
 block discarded – undo
958 958
 			if ($action == 'clone')
959 959
 			{
960 960
 				// Create an array for form
961
-				$formquestion=array(
961
+				$formquestion = array(
962 962
 					'text' => $langs->trans("ConfirmClone"),
963
-				array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneContent"),   'value' => 1),
963
+				array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneContent"), 'value' => 1),
964 964
 				array('type' => 'checkbox', 'name' => 'clone_receivers', 'label' => $langs->trans("CloneReceivers"), 'value' => 0)
965 965
 				);
966 966
 				// Paiement incomplet. On demande si motif = escompte ou autre
967
-				print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneEMailing'),$langs->trans('ConfirmCloneEMailing',$object->ref),'confirm_clone',$formquestion,'yes',2,240);
967
+				print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('CloneEMailing'), $langs->trans('ConfirmCloneEMailing', $object->ref), 'confirm_clone', $formquestion, 'yes', 2, 240);
968 968
 			}
969 969
 
970 970
 			/*
971 971
 			 * Boutons d'action
972 972
 			 */
973 973
 
974
-			if (GETPOST('cancel','alpha') || $confirm=='no' || $action == '' || in_array($action,array('settodraft','valid','delete','sendall','clone','test')))
974
+			if (GETPOST('cancel', 'alpha') || $confirm == 'no' || $action == '' || in_array($action, array('settodraft', 'valid', 'delete', 'sendall', 'clone', 'test')))
975 975
 			{
976 976
 				print "\n\n<div class=\"tabsAction\">\n";
977 977
 
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 
983 983
 				if (($object->statut == 0 || $object->statut == 1) && $user->rights->mailing->creer)
984 984
 				{
985
-					if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_MAILING))
985
+					if (!empty($conf->fckeditor->enabled) && !empty($conf->global->FCKEDITOR_ENABLE_MAILING))
986 986
 					{
987 987
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithEditor").'</a>';
988 988
 					}
@@ -991,12 +991,12 @@  discard block
 block discarded – undo
991 991
 						print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&amp;id='.$object->id.'">'.$langs->trans("EditWithTextEditor").'</a>';
992 992
 					}
993 993
 
994
-					if (! empty($conf->use_javascript_ajax)) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
994
+					if (!empty($conf->use_javascript_ajax)) print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edithtml&amp;id='.$object->id.'">'.$langs->trans("EditHTMLSource").'</a>';
995 995
 				}
996 996
 
997 997
 				//print '<a class="butAction" href="card.php?action=test&amp;id='.$object->id.'">'.$langs->trans("PreviewMailing").'</a>';
998 998
 
999
-				if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
999
+				if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send)
1000 1000
 				{
1001 1001
 					print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("TestMailing").'</a>';
1002 1002
 				}
@@ -1027,7 +1027,7 @@  discard block
 block discarded – undo
1027 1027
 					{
1028 1028
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("SendingFromWebInterfaceIsNotAllowed")).'">'.$langs->trans("SendMailing").'</a>';
1029 1029
 					}
1030
-					else if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1030
+					else if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send)
1031 1031
 					{
1032 1032
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("SendMailing").'</a>';
1033 1033
 					}
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
 
1045 1045
 				if (($object->statut == 2 || $object->statut == 3) && $user->rights->mailing->valider)
1046 1046
 				{
1047
-					if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->send)
1047
+					if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->send)
1048 1048
 					{
1049 1049
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("ResetMailing").'</a>';
1050 1050
 					}
@@ -1056,13 +1056,13 @@  discard block
 block discarded – undo
1056 1056
 
1057 1057
 				if (($object->statut <= 1 && $user->rights->mailing->creer) || $user->rights->mailing->supprimer)
1058 1058
 				{
1059
-					if ($object->statut > 0 && (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! $user->rights->mailing->mailing_advance->delete))
1059
+					if ($object->statut > 0 && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !$user->rights->mailing->mailing_advance->delete))
1060 1060
 					{
1061 1061
 						print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("DeleteMailing").'</a>';
1062 1062
 					}
1063 1063
 					else
1064 1064
 					{
1065
-						print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(! empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
1065
+						print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.(!empty($urlfrom) ? '&urlfrom='.$urlfrom : '').'">'.$langs->trans("DeleteMailing").'</a>';
1066 1066
 					}
1067 1067
 				}
1068 1068
 
@@ -1082,25 +1082,25 @@  discard block
 block discarded – undo
1082 1082
 				$formmail = new FormMail($db);
1083 1083
 				$formmail->fromname = $object->email_from;
1084 1084
 				$formmail->frommail = $object->email_from;
1085
-				$formmail->withsubstit=1;
1086
-				$formmail->withfrom=0;
1087
-				$formmail->withto=$user->email?$user->email:1;
1088
-				$formmail->withtocc=0;
1089
-				$formmail->withtoccc=$conf->global->MAIN_EMAIL_USECCC;
1090
-				$formmail->withtopic=0;
1091
-				$formmail->withtopicreadonly=1;
1092
-				$formmail->withfile=0;
1093
-				$formmail->withbody=0;
1094
-				$formmail->withbodyreadonly=1;
1095
-				$formmail->withcancel=1;
1096
-				$formmail->withdeliveryreceipt=0;
1085
+				$formmail->withsubstit = 1;
1086
+				$formmail->withfrom = 0;
1087
+				$formmail->withto = $user->email ? $user->email : 1;
1088
+				$formmail->withtocc = 0;
1089
+				$formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC;
1090
+				$formmail->withtopic = 0;
1091
+				$formmail->withtopicreadonly = 1;
1092
+				$formmail->withfile = 0;
1093
+				$formmail->withbody = 0;
1094
+				$formmail->withbodyreadonly = 1;
1095
+				$formmail->withcancel = 1;
1096
+				$formmail->withdeliveryreceipt = 0;
1097 1097
 				// Tableau des substitutions
1098
-				$formmail->substit=$object->substitutionarrayfortest;
1098
+				$formmail->substit = $object->substitutionarrayfortest;
1099 1099
 				// Tableau des parametres complementaires du post
1100
-				$formmail->param["action"]="send";
1101
-				$formmail->param["models"]='none';
1102
-				$formmail->param["mailid"]=$object->id;
1103
-				$formmail->param["returnurl"]=$_SERVER['PHP_SELF']."?id=".$object->id;
1100
+				$formmail->param["action"] = "send";
1101
+				$formmail->param["models"] = 'none';
1102
+				$formmail->param["mailid"] = $object->id;
1103
+				$formmail->param["returnurl"] = $_SERVER['PHP_SELF']."?id=".$object->id;
1104 1104
 
1105 1105
 				print $formmail->get_form();
1106 1106
 
@@ -1113,11 +1113,11 @@  discard block
 block discarded – undo
1113 1113
 
1114 1114
 
1115 1115
 			$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1116
-			foreach($object->substitutionarray as $key => $val)
1116
+			foreach ($object->substitutionarray as $key => $val)
1117 1117
 			{
1118
-				$htmltext.=$key.' = '.$langs->trans($val).'<br>';
1118
+				$htmltext .= $key.' = '.$langs->trans($val).'<br>';
1119 1119
 			}
1120
-			$htmltext.='</i>';
1120
+			$htmltext .= '</i>';
1121 1121
 
1122 1122
 			// Print mail content
1123 1123
 			print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto('<span class="hideonsmartphone">'.$langs->trans("AvailableVariables").'</span>', $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
@@ -1132,10 +1132,10 @@  discard block
 block discarded – undo
1132 1132
 			// Joined files
1133 1133
 			print '<tr><td>'.$langs->trans("MailFile").'</td><td colspan="3">';
1134 1134
 			// List of files
1135
-			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
1135
+			$listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
1136 1136
 			if (count($listofpaths))
1137 1137
 			{
1138
-				foreach($listofpaths as $key => $val)
1138
+				foreach ($listofpaths as $key => $val)
1139 1139
 				{
1140 1140
 					print img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1141 1141
 					print '<br>';
@@ -1155,13 +1155,13 @@  discard block
 block discarded – undo
1155 1155
 			print '</table>';
1156 1156
 
1157 1157
 		    // Message
1158
-			print '<div style="padding-top: 10px; background: '.($object->bgcolor?(preg_match('/^#/',$object->bgcolor)?'':'#').$object->bgcolor:'white').'">';
1158
+			print '<div style="padding-top: 10px; background: '.($object->bgcolor ? (preg_match('/^#/', $object->bgcolor) ? '' : '#').$object->bgcolor : 'white').'">';
1159 1159
 			if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff')	// CKEditor does not apply the color of the div into its content area
1160 1160
 			{
1161
-				$readonly=1;
1161
+				$readonly = 1;
1162 1162
 				// Editeur wysiwyg
1163 1163
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1164
-				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',false,true,empty($conf->global->FCKEDITOR_ENABLE_MAILING)?0:1,20,'90%',$readonly);
1164
+				$doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', false, true, empty($conf->global->FCKEDITOR_ENABLE_MAILING) ? 0 : 1, 20, '90%', $readonly);
1165 1165
 				$doleditor->Create();
1166 1166
 			}
1167 1167
 			else print dol_htmlentitiesbr($object->body);
@@ -1179,8 +1179,8 @@  discard block
 block discarded – undo
1179 1179
 
1180 1180
 			$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
1181 1181
 
1182
-			$morehtmlright='';
1183
-			if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1182
+			$morehtmlright = '';
1183
+			if ($object->statut == 2) $morehtmlright .= ' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
1184 1184
 
1185 1185
 			dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
1186 1186
 
@@ -1199,33 +1199,33 @@  discard block
 block discarded – undo
1199 1199
 			// Topic
1200 1200
 			print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
1201 1201
 			// From
1202
-			print '<tr><td class="titlefield">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
1202
+			print '<tr><td class="titlefield">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'</td></tr>';
1203 1203
 			// To
1204
-			print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1).'</td></tr>';
1204
+			print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1).'</td></tr>';
1205 1205
 
1206 1206
 			// Nb of distinct emails
1207 1207
 			print '<tr><td>';
1208 1208
 			print $langs->trans("TotalNbOfDistinctRecipients");
1209 1209
 			print '</td><td colspan="3">';
1210
-			$nbemail = ($object->nbemail?$object->nbemail:0);
1210
+			$nbemail = ($object->nbemail ? $object->nbemail : 0);
1211 1211
 			if (is_numeric($nbemail))
1212 1212
 			{
1213
-				$text='';
1214
-				if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2))
1213
+				$text = '';
1214
+				if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || $object->statut == 2))
1215 1215
 				{
1216 1216
 					if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
1217 1217
 					{
1218
-						$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
1218
+						$text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
1219 1219
 					}
1220 1220
 					else
1221 1221
 					{
1222
-						$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
1222
+						$text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
1223 1223
 					}
1224 1224
 				}
1225
-				if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
1225
+				if (empty($nbemail)) $nbemail .= ' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
1226 1226
 				if ($text)
1227 1227
 				{
1228
-					print $form->textwithpicto($nbemail,$text,1,'warning');
1228
+					print $form->textwithpicto($nbemail, $text, 1, 'warning');
1229 1229
 				}
1230 1230
 				else
1231 1231
 				{
@@ -1235,12 +1235,12 @@  discard block
 block discarded – undo
1235 1235
 			print '</td></tr>';
1236 1236
 
1237 1237
 			// Other attributes
1238
-			$parameters=array();
1239
-			$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1238
+			$parameters = array();
1239
+			$reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1240 1240
             print $hookmanager->resPrint;
1241 1241
 			if (empty($reshook))
1242 1242
 			{
1243
-				print $object->showOptionals($extrafields,'edit');
1243
+				print $object->showOptionals($extrafields, 'edit');
1244 1244
 			}
1245 1245
 
1246 1246
 			print '</table>';
@@ -1258,11 +1258,11 @@  discard block
 block discarded – undo
1258 1258
 			print '<input type="hidden" name="id" value="'.$object->id.'">';
1259 1259
 
1260 1260
 			$htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1261
-			foreach($object->substitutionarray as $key => $val)
1261
+			foreach ($object->substitutionarray as $key => $val)
1262 1262
 			{
1263
-				$htmltext.=$key.' = '.$langs->trans($val).'<br>';
1263
+				$htmltext .= $key.' = '.$langs->trans($val).'<br>';
1264 1264
 			}
1265
-			$htmltext.='</i>';
1265
+			$htmltext .= '</i>';
1266 1266
 
1267 1267
 			// Print mail content
1268 1268
 			print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic');
@@ -1274,49 +1274,49 @@  discard block
 block discarded – undo
1274 1274
 			// Subject
1275 1275
 			print '<tr><td class="fieldrequired titlefield">'.$langs->trans("MailTopic").'</td><td colspan="3"><input class="flat quatrevingtpercent" type="text" name="sujet" value="'.$object->sujet.'"></td></tr>';
1276 1276
 
1277
-			$trackid=''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
1277
+			$trackid = ''; // TODO To avoid conflicts with 2 mass emailing, we should set a trackid here, even if we use another one into email header.
1278 1278
 			dol_init_file_process($upload_dir, $trackid);
1279 1279
 
1280 1280
 			// Joined files
1281
-			$addfileaction='addfile';
1281
+			$addfileaction = 'addfile';
1282 1282
 			print '<tr><td>'.$langs->trans("MailFile").'</td>';
1283 1283
 			print '<td colspan="3">';
1284 1284
 			// List of files
1285
-			$listofpaths=dol_dir_list($upload_dir,'all',0,'','','name',SORT_ASC,0);
1285
+			$listofpaths = dol_dir_list($upload_dir, 'all', 0, '', '', 'name', SORT_ASC, 0);
1286 1286
 
1287 1287
 			// TODO Trick to have param removedfile containing nb of image to delete. But this does not works without javascript
1288
-			$out.= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
1289
-			$out.= '<script type="text/javascript" language="javascript">';
1290
-			$out.= 'jQuery(document).ready(function () {';
1291
-			$out.= '    jQuery(".removedfile").click(function() {';
1292
-			$out.= '        jQuery(".removedfilehidden").val(jQuery(this).val());';
1293
-			$out.= '    });';
1294
-			$out.= '})';
1295
-			$out.= '</script>'."\n";
1288
+			$out .= '<input type="hidden" class="removedfilehidden" name="removedfile" value="">'."\n";
1289
+			$out .= '<script type="text/javascript" language="javascript">';
1290
+			$out .= 'jQuery(document).ready(function () {';
1291
+			$out .= '    jQuery(".removedfile").click(function() {';
1292
+			$out .= '        jQuery(".removedfilehidden").val(jQuery(this).val());';
1293
+			$out .= '    });';
1294
+			$out .= '})';
1295
+			$out .= '</script>'."\n";
1296 1296
 			if (count($listofpaths))
1297 1297
 			{
1298
-				foreach($listofpaths as $key => $val)
1298
+				foreach ($listofpaths as $key => $val)
1299 1299
 				{
1300
-					$out.= '<div id="attachfile_'.$key.'">';
1301
-					$out.= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1302
-					$out.= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"),'delete.png','','',1).'" value="'.($key+1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
1303
-					$out.= '<br></div>';
1300
+					$out .= '<div id="attachfile_'.$key.'">';
1301
+					$out .= img_mime($listofpaths[$key]['name']).' '.$listofpaths[$key]['name'];
1302
+					$out .= ' <input type="image" style="border: 0px;" src="'.img_picto($langs->trans("Search"), 'delete.png', '', '', 1).'" value="'.($key + 1).'" class="removedfile" id="removedfile_'.$key.'" name="removedfile_'.$key.'" />';
1303
+					$out .= '<br></div>';
1304 1304
 				}
1305 1305
 			}
1306 1306
 			else
1307 1307
 			{
1308
-				$out.= $langs->trans("NoAttachedFiles").'<br>';
1308
+				$out .= $langs->trans("NoAttachedFiles").'<br>';
1309 1309
 			}
1310 1310
 			// Add link to add file
1311
-			$out.= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
1312
-			$out.= ' ';
1313
-			$out.= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
1311
+			$out .= '<input type="file" class="flat" id="addedfile" name="addedfile" value="'.$langs->trans("Upload").'" />';
1312
+			$out .= ' ';
1313
+			$out .= '<input type="submit" class="button" id="'.$addfileaction.'" name="'.$addfileaction.'" value="'.$langs->trans("MailingAddFile").'" />';
1314 1314
 			print $out;
1315 1315
 			print '</td></tr>';
1316 1316
 
1317 1317
 		    // Background color
1318 1318
 			print '<tr><td>'.$langs->trans("BackgroundColorByDefault").'</td><td colspan="3">';
1319
-			print $htmlother->selectColor($object->bgcolor,'bgcolor','',0);
1319
+			print $htmlother->selectColor($object->bgcolor, 'bgcolor', '', 0);
1320 1320
 			print '</td></tr>';
1321 1321
 
1322 1322
 			print '</table>';
@@ -1328,14 +1328,14 @@  discard block
 block discarded – undo
1328 1328
 			{
1329 1329
 				// Editeur wysiwyg
1330 1330
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1331
-				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%');
1331
+				$doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, $conf->global->FCKEDITOR_ENABLE_MAILING, 20, '90%');
1332 1332
 				$doleditor->Create();
1333 1333
 			}
1334 1334
 			if ($action == 'edithtml')
1335 1335
 			{
1336 1336
 				// Editor HTML source
1337 1337
 				require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1338
-				$doleditor=new DolEditor('bodyemail',$object->body,'',600,'dolibarr_mailings','',true,true,'ace',20,'90%');
1338
+				$doleditor = new DolEditor('bodyemail', $object->body, '', 600, 'dolibarr_mailings', '', true, true, 'ace', 20, '90%');
1339 1339
 				$doleditor->Create(0, '', false, 'HTML Source', 'php');
1340 1340
 			}
1341 1341
 
@@ -1356,7 +1356,7 @@  discard block
 block discarded – undo
1356 1356
 	}
1357 1357
 	else
1358 1358
 	{
1359
-		dol_print_error($db,$object->error);
1359
+		dol_print_error($db, $object->error);
1360 1360
 	}
1361 1361
 }
1362 1362
 
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/mailing/info.php 3 patches
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -50,29 +50,29 @@
 block discarded – undo
50 50
 
51 51
 if ($object->fetch($id) >= 0)
52 52
 {
53
-	$head = emailing_prepare_head($object);
53
+    $head = emailing_prepare_head($object);
54 54
 
55
-	dol_fiche_head($head, 'info', $langs->trans("Mailing"), -1, 'email');
55
+    dol_fiche_head($head, 'info', $langs->trans("Mailing"), -1, 'email');
56 56
 
57
-	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
57
+    $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
58 58
 
59
-	$morehtmlright='';
60
-	if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
59
+    $morehtmlright='';
60
+    if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
61 61
 	
62
-	dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
62
+    dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
63 63
 	
64
-	print '<div class="underbanner clearboth"></div><br>';
64
+    print '<div class="underbanner clearboth"></div><br>';
65 65
 	
66
-	//print '<table width="100%"><tr><td>';
67
-	$object->user_creation=$object->user_creat;
68
-	$object->date_creation=$object->date_creat;
69
-	$object->user_validation=$object->user_valid;
70
-	$object->date_validation=$object->date_valid;
71
-	dol_print_object_info($object, 0);
72
-	//print '</td></tr></table>';
66
+    //print '<table width="100%"><tr><td>';
67
+    $object->user_creation=$object->user_creat;
68
+    $object->date_creation=$object->date_creat;
69
+    $object->user_validation=$object->user_valid;
70
+    $object->date_validation=$object->date_valid;
71
+    dol_print_object_info($object, 0);
72
+    //print '</td></tr></table>';
73 73
 	
74 74
 
75
-	dol_fiche_end();
75
+    dol_fiche_end();
76 76
 }
77 77
 
78 78
 // End of page
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,8 +33,9 @@  discard block
 block discarded – undo
33 33
 $langs->load("mails");
34 34
 
35 35
 // Security check
36
-if (! $user->rights->mailing->lire || $user->societe_id > 0)
37
-accessforbidden();
36
+if (! $user->rights->mailing->lire || $user->societe_id > 0) {
37
+    accessforbidden();
38
+}
38 39
 
39 40
 
40 41
 
@@ -57,7 +58,9 @@  discard block
 block discarded – undo
57 58
 	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
58 59
 
59 60
 	$morehtmlright='';
60
-	if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
61
+	if ($object->statut == 2) {
62
+	    $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
63
+	}
61 64
 	
62 65
 	dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
63 66
 	
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -25,18 +25,18 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
27 27
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
28
-require DOL_BASE_PATH . '/main.inc.php';
29
-require_once DOL_DOCUMENT_ROOT .'/comm/mailing/class/mailing.class.php';
28
+require DOL_BASE_PATH.'/main.inc.php';
29
+require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
32 32
 
33
-$id=GETPOST('id');
33
+$id = GETPOST('id');
34 34
 
35 35
 // Load translation files required by the page
36 36
 $langs->load("mails");
37 37
 
38 38
 // Security check
39
-if (! $user->rights->mailing->lire || $user->societe_id > 0)
39
+if (!$user->rights->mailing->lire || $user->societe_id > 0)
40 40
 accessforbidden();
41 41
 
42 42
 
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
  * View
46 46
  */
47 47
 
48
-llxHeader('',$langs->trans("Mailing"),'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
48
+llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
49 49
 
50 50
 $form = new Form($db);
51 51
 
@@ -59,18 +59,18 @@  discard block
 block discarded – undo
59 59
 
60 60
 	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
61 61
 
62
-	$morehtmlright='';
63
-	if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
62
+	$morehtmlright = '';
63
+	if ($object->statut == 2) $morehtmlright .= ' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') ';
64 64
 	
65 65
 	dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
66 66
 	
67 67
 	print '<div class="underbanner clearboth"></div><br>';
68 68
 	
69 69
 	//print '<table width="100%"><tr><td>';
70
-	$object->user_creation=$object->user_creat;
71
-	$object->date_creation=$object->date_creat;
72
-	$object->user_validation=$object->user_valid;
73
-	$object->date_validation=$object->date_valid;
70
+	$object->user_creation = $object->user_creat;
71
+	$object->date_creation = $object->date_creat;
72
+	$object->user_validation = $object->user_valid;
73
+	$object->date_validation = $object->date_valid;
74 74
 	dol_print_object_info($object, 0);
75 75
 	//print '</td></tr></table>';
76 76
 	
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/mailing/advtargetemailing.php 3 patches
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
 // Load translation files required by the page
38 38
 $langs->loadLangs(array('mails', 'companies'));
39 39
 if (! empty($conf->categorie->enabled)) {
40
-	$langs->load("categories");
40
+    $langs->load("categories");
41 41
 }
42 42
 
43 43
 // Security check
44 44
 if (! $user->rights->mailing->lire || $user->societe_id > 0)
45
-	accessforbidden();
45
+    accessforbidden();
46 46
 
47 47
 // Load variable for pagination
48 48
 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
@@ -54,9 +54,9 @@  discard block
 block discarded – undo
54 54
 $pageprev = $page - 1;
55 55
 $pagenext = $page + 1;
56 56
 if (! $sortorder)
57
-	$sortorder = "ASC";
57
+    $sortorder = "ASC";
58 58
 if (! $sortfield)
59
-	$sortfield = "email";
59
+    $sortfield = "email";
60 60
 
61 61
 $id = GETPOST('id', 'int');
62 62
 $rowid = GETPOST('rowid', 'int');
@@ -68,31 +68,31 @@  discard block
 block discarded – undo
68 68
 
69 69
 // Do we click on purge search criteria ?
70 70
 if (GETPOST('button_removefilter_x','alpha')) {
71
-	$search_nom = '';
72
-	$search_prenom = '';
73
-	$search_email = '';
71
+    $search_nom = '';
72
+    $search_prenom = '';
73
+    $search_email = '';
74 74
 }
75 75
 $array_query = array ();
76 76
 $object = new Mailing($db);
77 77
 $advTarget = new AdvanceTargetingMailing($db);
78 78
 
79 79
 if (empty($template_id)) {
80
-	$advTarget->fk_element = $id;
81
-	$advTarget->type_element = 'mailing';
82
-	$result = $advTarget->fetch_by_mailing();
80
+    $advTarget->fk_element = $id;
81
+    $advTarget->type_element = 'mailing';
82
+    $result = $advTarget->fetch_by_mailing();
83 83
 } else {
84
-	$result = $advTarget->fetch($template_id);
84
+    $result = $advTarget->fetch($template_id);
85 85
 }
86 86
 
87 87
 if ($result < 0)
88 88
 {
89
-	setEventMessages($advTarget->error, $advTarget->errors, 'errors');
89
+    setEventMessages($advTarget->error, $advTarget->errors, 'errors');
90 90
 }
91 91
 else
92 92
 {
93
-	if (! empty($advTarget->id)) {
94
-		$array_query = json_decode($advTarget->filtervalue, true);
95
-	}
93
+    if (! empty($advTarget->id)) {
94
+        $array_query = json_decode($advTarget->filtervalue, true);
95
+    }
96 96
 }
97 97
 
98 98
 
@@ -101,308 +101,308 @@  discard block
 block discarded – undo
101 101
  */
102 102
 
103 103
 if ($action == 'loadfilter') {
104
-	if (! empty($template_id)) {
105
-		$result = $advTarget->fetch($template_id);
106
-		if ($result < 0) {
107
-			setEventMessages($advTarget->error, $advTarget->errors, 'errors');
108
-		} else {
109
-			if (! empty($advTarget->id)) {
110
-				$array_query = json_decode($advTarget->filtervalue, true);
111
-			}
112
-		}
113
-	}
104
+    if (! empty($template_id)) {
105
+        $result = $advTarget->fetch($template_id);
106
+        if ($result < 0) {
107
+            setEventMessages($advTarget->error, $advTarget->errors, 'errors');
108
+        } else {
109
+            if (! empty($advTarget->id)) {
110
+                $array_query = json_decode($advTarget->filtervalue, true);
111
+            }
112
+        }
113
+    }
114 114
 }
115 115
 
116 116
 if ($action == 'add') {
117 117
 
118
-	$user_contact_query = false;
119
-
120
-	$array_query = array ();
121
-
122
-	// Get extra fields
123
-
124
-	foreach ( $_POST as $key => $value ) {
125
-		// print '$key='.$key.' $value='.$value.'<BR>';
126
-		if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
127
-			// Special case for start date come with 3 inputs day, month, year
128
-			if (preg_match("/st_dt/", $key)) {
129
-				$dtarr = array ();
130
-				$dtarr = explode('_', $key);
131
-				if (! array_key_exists('options_' . $dtarr[1] . '_st_dt', $array_query)) {
132
-					$array_query['options_' . $dtarr[1] . '_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear', 'int'));
133
-				}
134
-			} elseif (preg_match("/end_dt/", $key)) {
135
-				// Special case for end date come with 3 inputs day, month, year
136
-				$dtarr = array ();
137
-				$dtarr = explode('_', $key);
138
-				if (! array_key_exists('options_' . $dtarr[1] . '_end_dt', $array_query)) {
139
-					$array_query['options_' . $dtarr[1] . '_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear', 'int'));
140
-				}
141
-			} else {
142
-				$array_query[$key] = GETPOST($key);
143
-			}
144
-		}
145
-		if (preg_match("/^options_.*_cnct/", $key)) {
146
-			$user_contact_query = true;
147
-			// Special case for start date come with 3 inputs day, month, year
148
-			if (preg_match("/st_dt/", $key)) {
149
-				$dtarr = array ();
150
-				$dtarr = explode('_', $key);
151
-				if (! array_key_exists('options_' . $dtarr[1] . '_st_dt' . '_cnct', $array_query)) {
152
-					$array_query['options_' . $dtarr[1] . '_st_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear' . '_cnct', 'int'));
153
-				}
154
-			} elseif (preg_match("/end_dt/", $key)) {
155
-				// Special case for end date come with 3 inputs day, month, year
156
-				$dtarr = array ();
157
-				$dtarr = explode('_', $key);
158
-				if (! array_key_exists('options_' . $dtarr[1] . '_end_dt' . '_cnct', $array_query)) {
159
-					$array_query['options_' . $dtarr[1] . '_end_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear' . '_cnct', 'int'));
160
-				}
161
-			} else {
162
-				$array_query[$key] = GETPOST($key);
163
-			}
164
-		}
165
-
166
-		if (preg_match("/^cust_/", $key)) {
167
-			$array_query[$key] = GETPOST($key);
168
-		}
169
-
170
-		if (preg_match("/^contact_/", $key)) {
171
-
172
-			$array_query[$key] = GETPOST($key);
173
-
174
-			$specials_date_key = array (
175
-					'contact_update_st_dt',
176
-					'contact_update_end_dt',
177
-					'contact_create_st_dt',
178
-					'contact_create_end_dt'
179
-			);
180
-			foreach ( $specials_date_key as $date_key ) {
181
-				if ($key == $date_key) {
182
-					$dt = GETPOST($date_key);
183
-					if (! empty($dt)) {
184
-						$array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key . 'month', 'int'), GETPOST($date_key . 'day', 'int'), GETPOST($date_key . 'year', 'int'));
185
-					} else {
186
-						$array_query[$key] = '';
187
-					}
188
-				}
189
-			}
190
-
191
-			if (! empty($array_query[$key])) {
192
-				$user_contact_query = true;
193
-			}
194
-		}
195
-
196
-		if ($array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4) {
197
-			$user_contact_query = true;
198
-		}
199
-
200
-		if (preg_match("/^type_of_target/", $key)) {
201
-			$array_query[$key] = GETPOST($key);
202
-		}
203
-	}
204
-
205
-	// if ($array_query ['type_of_target'] == 1 || $array_query ['type_of_target'] == 3) {
206
-	$result = $advTarget->query_thirdparty($array_query);
207
-	if ($result < 0) {
208
-		setEventMessages($advTarget->error, $advTarget->errors, 'errors');
209
-	}
210
-	/*} else {
118
+    $user_contact_query = false;
119
+
120
+    $array_query = array ();
121
+
122
+    // Get extra fields
123
+
124
+    foreach ( $_POST as $key => $value ) {
125
+        // print '$key='.$key.' $value='.$value.'<BR>';
126
+        if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
127
+            // Special case for start date come with 3 inputs day, month, year
128
+            if (preg_match("/st_dt/", $key)) {
129
+                $dtarr = array ();
130
+                $dtarr = explode('_', $key);
131
+                if (! array_key_exists('options_' . $dtarr[1] . '_st_dt', $array_query)) {
132
+                    $array_query['options_' . $dtarr[1] . '_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear', 'int'));
133
+                }
134
+            } elseif (preg_match("/end_dt/", $key)) {
135
+                // Special case for end date come with 3 inputs day, month, year
136
+                $dtarr = array ();
137
+                $dtarr = explode('_', $key);
138
+                if (! array_key_exists('options_' . $dtarr[1] . '_end_dt', $array_query)) {
139
+                    $array_query['options_' . $dtarr[1] . '_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear', 'int'));
140
+                }
141
+            } else {
142
+                $array_query[$key] = GETPOST($key);
143
+            }
144
+        }
145
+        if (preg_match("/^options_.*_cnct/", $key)) {
146
+            $user_contact_query = true;
147
+            // Special case for start date come with 3 inputs day, month, year
148
+            if (preg_match("/st_dt/", $key)) {
149
+                $dtarr = array ();
150
+                $dtarr = explode('_', $key);
151
+                if (! array_key_exists('options_' . $dtarr[1] . '_st_dt' . '_cnct', $array_query)) {
152
+                    $array_query['options_' . $dtarr[1] . '_st_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear' . '_cnct', 'int'));
153
+                }
154
+            } elseif (preg_match("/end_dt/", $key)) {
155
+                // Special case for end date come with 3 inputs day, month, year
156
+                $dtarr = array ();
157
+                $dtarr = explode('_', $key);
158
+                if (! array_key_exists('options_' . $dtarr[1] . '_end_dt' . '_cnct', $array_query)) {
159
+                    $array_query['options_' . $dtarr[1] . '_end_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear' . '_cnct', 'int'));
160
+                }
161
+            } else {
162
+                $array_query[$key] = GETPOST($key);
163
+            }
164
+        }
165
+
166
+        if (preg_match("/^cust_/", $key)) {
167
+            $array_query[$key] = GETPOST($key);
168
+        }
169
+
170
+        if (preg_match("/^contact_/", $key)) {
171
+
172
+            $array_query[$key] = GETPOST($key);
173
+
174
+            $specials_date_key = array (
175
+                    'contact_update_st_dt',
176
+                    'contact_update_end_dt',
177
+                    'contact_create_st_dt',
178
+                    'contact_create_end_dt'
179
+            );
180
+            foreach ( $specials_date_key as $date_key ) {
181
+                if ($key == $date_key) {
182
+                    $dt = GETPOST($date_key);
183
+                    if (! empty($dt)) {
184
+                        $array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key . 'month', 'int'), GETPOST($date_key . 'day', 'int'), GETPOST($date_key . 'year', 'int'));
185
+                    } else {
186
+                        $array_query[$key] = '';
187
+                    }
188
+                }
189
+            }
190
+
191
+            if (! empty($array_query[$key])) {
192
+                $user_contact_query = true;
193
+            }
194
+        }
195
+
196
+        if ($array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4) {
197
+            $user_contact_query = true;
198
+        }
199
+
200
+        if (preg_match("/^type_of_target/", $key)) {
201
+            $array_query[$key] = GETPOST($key);
202
+        }
203
+    }
204
+
205
+    // if ($array_query ['type_of_target'] == 1 || $array_query ['type_of_target'] == 3) {
206
+    $result = $advTarget->query_thirdparty($array_query);
207
+    if ($result < 0) {
208
+        setEventMessages($advTarget->error, $advTarget->errors, 'errors');
209
+    }
210
+    /*} else {
211 211
 		$advTarget->thirdparty_lines = array ();
212 212
 	}*/
213 213
 
214
-	if ($user_contact_query && ($array_query['type_of_target'] == 1 || $array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4)) {
215
-		$result = $advTarget->query_contact($array_query, 1);
216
-		if ($result < 0) {
217
-			setEventMessages($advTarget->error, $advTarget->errors, 'errors');
218
-		}
219
-		// If use contact but no result use artefact to so not use socid into add_to_target
220
-		if (count($advTarget->contact_lines) == 0) {
221
-			$advTarget->contact_lines = array (
222
-					0
223
-			);
224
-		}
225
-	} else {
226
-		$advTarget->contact_lines = array ();
227
-	}
228
-
229
-	if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
230
-		// Add targets into database
231
-		$obj = new mailing_advthirdparties($db);
232
-		$result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines);
233
-	} else {
234
-		$result = 0;
235
-	}
236
-
237
-	if ($result > 0) {
238
-		$query_temlate_id = '';
239
-		if (! empty($template_id)) {
240
-			$query_temlate_id = '&template_id=' . $template_id;
241
-		}
242
-		setEventMessages($langs->trans("XTargetsAdded",$result), null, 'mesgs');
243
-		header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id . $query_temlate_id);
244
-		exit();
245
-	}
246
-	if ($result == 0) {
247
-		setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
248
-	}
249
-	if ($result < 0) {
250
-		setEventMessages($obj->error, $obj->errors, 'errors');
251
-	}
214
+    if ($user_contact_query && ($array_query['type_of_target'] == 1 || $array_query['type_of_target'] == 2 || $array_query['type_of_target'] == 4)) {
215
+        $result = $advTarget->query_contact($array_query, 1);
216
+        if ($result < 0) {
217
+            setEventMessages($advTarget->error, $advTarget->errors, 'errors');
218
+        }
219
+        // If use contact but no result use artefact to so not use socid into add_to_target
220
+        if (count($advTarget->contact_lines) == 0) {
221
+            $advTarget->contact_lines = array (
222
+                    0
223
+            );
224
+        }
225
+    } else {
226
+        $advTarget->contact_lines = array ();
227
+    }
228
+
229
+    if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
230
+        // Add targets into database
231
+        $obj = new mailing_advthirdparties($db);
232
+        $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines);
233
+    } else {
234
+        $result = 0;
235
+    }
236
+
237
+    if ($result > 0) {
238
+        $query_temlate_id = '';
239
+        if (! empty($template_id)) {
240
+            $query_temlate_id = '&template_id=' . $template_id;
241
+        }
242
+        setEventMessages($langs->trans("XTargetsAdded",$result), null, 'mesgs');
243
+        header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id . $query_temlate_id);
244
+        exit();
245
+    }
246
+    if ($result == 0) {
247
+        setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
248
+    }
249
+    if ($result < 0) {
250
+        setEventMessages($obj->error, $obj->errors, 'errors');
251
+    }
252 252
 }
253 253
 
254 254
 if ($action == 'clear') {
255
-	// Chargement de la classe
256
-	$classname = "MailingTargets";
257
-	$obj = new $classname($db);
258
-	$obj->clear_target($id);
255
+    // Chargement de la classe
256
+    $classname = "MailingTargets";
257
+    $obj = new $classname($db);
258
+    $obj->clear_target($id);
259 259
 
260
-	header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
261
-	exit();
260
+    header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
261
+    exit();
262 262
 }
263 263
 
264 264
 if ($action == 'savefilter' || $action == 'createfilter') {
265 265
 
266
-	$template_name = GETPOST('template_name');
267
-	$error = 0;
268
-
269
-	if ($action == 'createfilter' && empty($template_name)) {
270
-		setEventMessages($langs->trans('ErrorFieldRequired', $langs->trans('AdvTgtOrCreateNewFilter')), null, 'errors');
271
-		$error ++;
272
-	}
273
-
274
-	if (empty($error)) {
275
-
276
-		$array_query = array ();
277
-
278
-		// Get extra fields
279
-		foreach ( $_POST as $key => $value ) {
280
-			if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
281
-				// Special case for start date come with 3 inputs day, month, year
282
-				if (preg_match("/st_dt/", $key)) {
283
-					$dtarr = array ();
284
-					$dtarr = explode('_', $key);
285
-					if (! array_key_exists('options_' . $dtarr[1] . '_st_dt', $array_query)) {
286
-						$array_query['options_' . $dtarr[1] . '_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear', 'int'));
287
-					}
288
-				} elseif (preg_match("/end_dt/", $key)) {
289
-					// Special case for end date come with 3 inputs day, month, year
290
-					$dtarr = array ();
291
-					$dtarr = explode('_', $key);
292
-					if (! array_key_exists('options_' . $dtarr[1] . '_end_dt', $array_query)) {
293
-						$array_query['options_' . $dtarr[1] . '_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear', 'int'));
294
-						// print $array_query['options_'.$dtarr[1].'_end_dt'];
295
-						// 01/02/1013=1361228400
296
-					}
297
-				} else {
298
-					$array_query[$key] = GETPOST($key);
299
-				}
300
-			}
301
-			if (preg_match("/^options_.*_cnct/", $key)) {
302
-				// Special case for start date come with 3 inputs day, month, year
303
-				if (preg_match("/st_dt/", $key)) {
304
-					$dtarr = array ();
305
-					$dtarr = explode('_', $key);
306
-					if (! array_key_exists('options_' . $dtarr[1] . '_st_dt' . '_cnct', $array_query)) {
307
-						$array_query['options_' . $dtarr[1] . '_st_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear' . '_cnct', 'int'));
308
-					}
309
-				} elseif (preg_match("/end_dt/", $key)) {
310
-					// Special case for end date come with 3 inputs day, month, year
311
-					$dtarr = array ();
312
-					$dtarr = explode('_', $key);
313
-					if (! array_key_exists('options_' . $dtarr[1] . '_end_dt' . '_cnct', $array_query)) {
314
-						$array_query['options_' . $dtarr[1] . '_end_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear' . '_cnct', 'int'));
315
-						// print $array_query['cnct_options_'.$dtarr[1].'_end_dt'];
316
-						// 01/02/1013=1361228400
317
-					}
318
-				} else {
319
-					$array_query[$key] = GETPOST($key);
320
-				}
321
-			}
322
-
323
-			if (preg_match("/^cust_/", $key)) {
324
-				$array_query[$key] = GETPOST($key);
325
-			}
326
-
327
-			if (preg_match("/^contact_/", $key)) {
328
-
329
-				$array_query[$key] = GETPOST($key);
330
-
331
-				$specials_date_key = array (
332
-						'contact_update_st_dt',
333
-						'contact_update_end_dt',
334
-						'contact_create_st_dt',
335
-						'contact_create_end_dt'
336
-				);
337
-				foreach ( $specials_date_key as $date_key ) {
338
-					if ($key == $date_key) {
339
-						$dt = GETPOST($date_key);
340
-						if (! empty($dt)) {
341
-							$array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key . 'month', 'int'), GETPOST($date_key . 'day', 'int'), GETPOST($date_key . 'year', 'int'));
342
-						} else {
343
-							$array_query[$key] = '';
344
-						}
345
-					}
346
-				}
347
-			}
348
-
349
-			if (preg_match("/^type_of_target/", $key)) {
350
-				$array_query[$key] = GETPOST($key);
351
-			}
352
-		}
353
-		$advTarget->filtervalue = json_encode($array_query);
354
-
355
-		if ($action == 'createfilter') {
356
-			$advTarget->name = $template_name;
357
-			$result = $advTarget->create($user);
358
-			if ($result < 0) {
359
-				setEventMessages($advTarget->error, $advTarget->errors, 'errors');
360
-			}
361
-		} elseif ($action == 'savefilter') {
362
-
363
-			$result = $advTarget->update($user);
364
-			if ($result < 0) {
365
-				setEventMessages($advTarget->error, $advTarget->errors, 'errors');
366
-			}
367
-		}
368
-		$template_id = $advTarget->id;
369
-	}
266
+    $template_name = GETPOST('template_name');
267
+    $error = 0;
268
+
269
+    if ($action == 'createfilter' && empty($template_name)) {
270
+        setEventMessages($langs->trans('ErrorFieldRequired', $langs->trans('AdvTgtOrCreateNewFilter')), null, 'errors');
271
+        $error ++;
272
+    }
273
+
274
+    if (empty($error)) {
275
+
276
+        $array_query = array ();
277
+
278
+        // Get extra fields
279
+        foreach ( $_POST as $key => $value ) {
280
+            if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
281
+                // Special case for start date come with 3 inputs day, month, year
282
+                if (preg_match("/st_dt/", $key)) {
283
+                    $dtarr = array ();
284
+                    $dtarr = explode('_', $key);
285
+                    if (! array_key_exists('options_' . $dtarr[1] . '_st_dt', $array_query)) {
286
+                        $array_query['options_' . $dtarr[1] . '_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear', 'int'));
287
+                    }
288
+                } elseif (preg_match("/end_dt/", $key)) {
289
+                    // Special case for end date come with 3 inputs day, month, year
290
+                    $dtarr = array ();
291
+                    $dtarr = explode('_', $key);
292
+                    if (! array_key_exists('options_' . $dtarr[1] . '_end_dt', $array_query)) {
293
+                        $array_query['options_' . $dtarr[1] . '_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear', 'int'));
294
+                        // print $array_query['options_'.$dtarr[1].'_end_dt'];
295
+                        // 01/02/1013=1361228400
296
+                    }
297
+                } else {
298
+                    $array_query[$key] = GETPOST($key);
299
+                }
300
+            }
301
+            if (preg_match("/^options_.*_cnct/", $key)) {
302
+                // Special case for start date come with 3 inputs day, month, year
303
+                if (preg_match("/st_dt/", $key)) {
304
+                    $dtarr = array ();
305
+                    $dtarr = explode('_', $key);
306
+                    if (! array_key_exists('options_' . $dtarr[1] . '_st_dt' . '_cnct', $array_query)) {
307
+                        $array_query['options_' . $dtarr[1] . '_st_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear' . '_cnct', 'int'));
308
+                    }
309
+                } elseif (preg_match("/end_dt/", $key)) {
310
+                    // Special case for end date come with 3 inputs day, month, year
311
+                    $dtarr = array ();
312
+                    $dtarr = explode('_', $key);
313
+                    if (! array_key_exists('options_' . $dtarr[1] . '_end_dt' . '_cnct', $array_query)) {
314
+                        $array_query['options_' . $dtarr[1] . '_end_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear' . '_cnct', 'int'));
315
+                        // print $array_query['cnct_options_'.$dtarr[1].'_end_dt'];
316
+                        // 01/02/1013=1361228400
317
+                    }
318
+                } else {
319
+                    $array_query[$key] = GETPOST($key);
320
+                }
321
+            }
322
+
323
+            if (preg_match("/^cust_/", $key)) {
324
+                $array_query[$key] = GETPOST($key);
325
+            }
326
+
327
+            if (preg_match("/^contact_/", $key)) {
328
+
329
+                $array_query[$key] = GETPOST($key);
330
+
331
+                $specials_date_key = array (
332
+                        'contact_update_st_dt',
333
+                        'contact_update_end_dt',
334
+                        'contact_create_st_dt',
335
+                        'contact_create_end_dt'
336
+                );
337
+                foreach ( $specials_date_key as $date_key ) {
338
+                    if ($key == $date_key) {
339
+                        $dt = GETPOST($date_key);
340
+                        if (! empty($dt)) {
341
+                            $array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key . 'month', 'int'), GETPOST($date_key . 'day', 'int'), GETPOST($date_key . 'year', 'int'));
342
+                        } else {
343
+                            $array_query[$key] = '';
344
+                        }
345
+                    }
346
+                }
347
+            }
348
+
349
+            if (preg_match("/^type_of_target/", $key)) {
350
+                $array_query[$key] = GETPOST($key);
351
+            }
352
+        }
353
+        $advTarget->filtervalue = json_encode($array_query);
354
+
355
+        if ($action == 'createfilter') {
356
+            $advTarget->name = $template_name;
357
+            $result = $advTarget->create($user);
358
+            if ($result < 0) {
359
+                setEventMessages($advTarget->error, $advTarget->errors, 'errors');
360
+            }
361
+        } elseif ($action == 'savefilter') {
362
+
363
+            $result = $advTarget->update($user);
364
+            if ($result < 0) {
365
+                setEventMessages($advTarget->error, $advTarget->errors, 'errors');
366
+            }
367
+        }
368
+        $template_id = $advTarget->id;
369
+    }
370 370
 }
371 371
 
372 372
 if ($action == 'deletefilter') {
373
-	$result = $advTarget->delete($user);
374
-	if ($result < 0) {
375
-		setEventMessages($advTarget->error, $advTarget->errors, 'errors');
376
-	}
377
-	header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
378
-	exit();
373
+    $result = $advTarget->delete($user);
374
+    if ($result < 0) {
375
+        setEventMessages($advTarget->error, $advTarget->errors, 'errors');
376
+    }
377
+    header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
378
+    exit();
379 379
 }
380 380
 
381 381
 if ($action == 'delete') {
382
-	// Ici, rowid indique le destinataire et id le mailing
383
-	$sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing_cibles WHERE rowid=" . $rowid;
384
-	$resql = $db->query($sql);
385
-	if ($resql) {
386
-		if (! empty($id)) {
387
-			$classname = "MailingTargets";
388
-			$obj = new $classname($db);
389
-			$obj->update_nb($id);
390
-
391
-			header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
392
-			exit();
393
-		} else {
394
-			header("Location: liste.php");
395
-			exit();
396
-		}
397
-	} else {
398
-		dol_print_error($db);
399
-	}
382
+    // Ici, rowid indique le destinataire et id le mailing
383
+    $sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing_cibles WHERE rowid=" . $rowid;
384
+    $resql = $db->query($sql);
385
+    if ($resql) {
386
+        if (! empty($id)) {
387
+            $classname = "MailingTargets";
388
+            $obj = new $classname($db);
389
+            $obj->update_nb($id);
390
+
391
+            header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
392
+            exit();
393
+        } else {
394
+            header("Location: liste.php");
395
+            exit();
396
+        }
397
+    } else {
398
+        dol_print_error($db);
399
+    }
400 400
 }
401 401
 
402 402
 if ($_POST["button_removefilter"]) {
403
-	$search_nom = '';
404
-	$search_prenom = '';
405
-	$search_email = '';
403
+    $search_nom = '';
404
+    $search_prenom = '';
405
+    $search_email = '';
406 406
 }
407 407
 
408 408
 
@@ -422,52 +422,52 @@  discard block
 block discarded – undo
422 422
 
423 423
 if ($object->fetch($id) >= 0) {
424 424
 
425
-	$head = emailing_prepare_head($object);
425
+    $head = emailing_prepare_head($object);
426 426
 
427
-	dol_fiche_head($head, 'advtargets', $langs->trans("Mailing"), 0, 'email');
427
+    dol_fiche_head($head, 'advtargets', $langs->trans("Mailing"), 0, 'email');
428 428
 
429
-	print '<table class="border" width="100%">';
429
+    print '<table class="border" width="100%">';
430 430
 
431
-	$linkback = '<a href="' . DOL_URL_ROOT . '/comm/mailing/liste.php">' . $langs->trans("BackToList") . '</a>';
431
+    $linkback = '<a href="' . DOL_URL_ROOT . '/comm/mailing/liste.php">' . $langs->trans("BackToList") . '</a>';
432 432
 
433
-	print '<tr><td width="25%">' . $langs->trans("Ref") . '</td>';
434
-	print '<td colspan="3">';
435
-	print $form->showrefnav($object, 'id', $linkback);
436
-	print '</td></tr>';
433
+    print '<tr><td width="25%">' . $langs->trans("Ref") . '</td>';
434
+    print '<td colspan="3">';
435
+    print $form->showrefnav($object, 'id', $linkback);
436
+    print '</td></tr>';
437 437
 
438
-	print '<tr><td width="25%">' . $langs->trans("MailTitle") . '</td><td colspan="3">' . $object->titre . '</td></tr>';
438
+    print '<tr><td width="25%">' . $langs->trans("MailTitle") . '</td><td colspan="3">' . $object->titre . '</td></tr>';
439 439
 
440
-	print '<tr><td width="25%">' . $langs->trans("MailFrom") . '</td><td colspan="3">' . dol_print_email($object->email_from, 0, 0, 0, 0, 1) . '</td></tr>';
440
+    print '<tr><td width="25%">' . $langs->trans("MailFrom") . '</td><td colspan="3">' . dol_print_email($object->email_from, 0, 0, 0, 0, 1) . '</td></tr>';
441 441
 
442
-	// Errors to
443
-	print '<tr><td width="25%">' . $langs->trans("MailErrorsTo") . '</td><td colspan="3">' . dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
444
-	print '</td></tr>';
442
+    // Errors to
443
+    print '<tr><td width="25%">' . $langs->trans("MailErrorsTo") . '</td><td colspan="3">' . dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
444
+    print '</td></tr>';
445 445
 
446
-	// Status
447
-	print '<tr><td width="25%">' . $langs->trans("Status") . '</td><td colspan="3">' . $object->getLibStatut(4) . '</td></tr>';
446
+    // Status
447
+    print '<tr><td width="25%">' . $langs->trans("Status") . '</td><td colspan="3">' . $object->getLibStatut(4) . '</td></tr>';
448 448
 
449
-	// Nb of distinct emails
450
-	print '<tr><td width="25%">';
451
-	print $langs->trans("TotalNbOfDistinctRecipients");
452
-	print '</td><td colspan="3">';
453
-	$nbemail = ($object->nbemail ? $object->nbemail : '0');
454
-	if (! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
455
-		$text = $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
456
-		print $form->textwithpicto($nbemail, $text, 1, 'warning');
457
-	} else {
458
-		print $nbemail;
459
-	}
460
-	print '</td></tr>';
449
+    // Nb of distinct emails
450
+    print '<tr><td width="25%">';
451
+    print $langs->trans("TotalNbOfDistinctRecipients");
452
+    print '</td><td colspan="3">';
453
+    $nbemail = ($object->nbemail ? $object->nbemail : '0');
454
+    if (! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
455
+        $text = $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
456
+        print $form->textwithpicto($nbemail, $text, 1, 'warning');
457
+    } else {
458
+        print $nbemail;
459
+    }
460
+    print '</td></tr>';
461 461
 
462
-	print '</table>';
462
+    print '</table>';
463 463
 
464
-	print "</div>";
464
+    print "</div>";
465 465
 
466
-	// Show email selectors
467
-	if ($object->statut == 0 && $user->rights->mailing->creer) {
466
+    // Show email selectors
467
+    if ($object->statut == 0 && $user->rights->mailing->creer) {
468 468
 
469
-		include DOL_DOCUMENT_ROOT . '/core/tpl/advtarget.tpl.php';
470
-	}
469
+        include DOL_DOCUMENT_ROOT . '/core/tpl/advtarget.tpl.php';
470
+    }
471 471
 }
472 472
 
473 473
 // End of page
Please login to merge, or discard this patch.
Braces   +10 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,9 @@  discard block
 block discarded – undo
22 22
  *       \brief      Page to define emailing targets
23 23
  */
24 24
 
25
-if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1');
25
+if (! defined('NOSTYLECHECK')) {
26
+    define('NOSTYLECHECK','1');
27
+}
26 28
 
27 29
 
28 30
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
@@ -43,8 +45,9 @@  discard block
 block discarded – undo
43 45
 }
44 46
 
45 47
 // Security check
46
-if (! $user->rights->mailing->lire || $user->societe_id > 0)
48
+if (! $user->rights->mailing->lire || $user->societe_id > 0) {
47 49
 	accessforbidden();
50
+}
48 51
 
49 52
 // Load variable for pagination
50 53
 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
@@ -55,10 +58,12 @@  discard block
 block discarded – undo
55 58
 $offset = $limit * $page;
56 59
 $pageprev = $page - 1;
57 60
 $pagenext = $page + 1;
58
-if (! $sortorder)
61
+if (! $sortorder) {
59 62
 	$sortorder = "ASC";
60
-if (! $sortfield)
63
+}
64
+if (! $sortfield) {
61 65
 	$sortfield = "email";
66
+}
62 67
 
63 68
 $id = GETPOST('id', 'int');
64 69
 $rowid = GETPOST('rowid', 'int');
@@ -89,8 +94,7 @@  discard block
 block discarded – undo
89 94
 if ($result < 0)
90 95
 {
91 96
 	setEventMessages($advTarget->error, $advTarget->errors, 'errors');
92
-}
93
-else
97
+} else
94 98
 {
95 99
 	if (! empty($advTarget->id)) {
96 100
 		$array_query = json_decode($advTarget->filtervalue, true);
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -22,59 +22,59 @@  discard block
 block discarded – undo
22 22
  *       \brief      Page to define emailing targets
23 23
  */
24 24
 
25
-if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK','1');
25
+if (!defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1');
26 26
 
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
31
-require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/mailing.class.php';
32
-require_once DOL_DOCUMENT_ROOT . '/core/lib/emailing.lib.php';
33
-require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/advtargetemailing.class.php';
34
-require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/html.formadvtargetemailing.class.php';
35
-require_once DOL_DOCUMENT_ROOT . '/core/modules/mailings/advthirdparties.modules.php';
36
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php';
37
-require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31
+require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
32
+require_once DOL_DOCUMENT_ROOT.'/core/lib/emailing.lib.php';
33
+require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/advtargetemailing.class.php';
34
+require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/html.formadvtargetemailing.class.php';
35
+require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/advthirdparties.modules.php';
36
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
38 38
 
39 39
 // Load translation files required by the page
40 40
 $langs->loadLangs(array('mails', 'companies'));
41
-if (! empty($conf->categorie->enabled)) {
41
+if (!empty($conf->categorie->enabled)) {
42 42
 	$langs->load("categories");
43 43
 }
44 44
 
45 45
 // Security check
46
-if (! $user->rights->mailing->lire || $user->societe_id > 0)
46
+if (!$user->rights->mailing->lire || $user->societe_id > 0)
47 47
 	accessforbidden();
48 48
 
49 49
 // Load variable for pagination
50
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
51
-$sortfield = GETPOST('sortfield','alpha');
52
-$sortorder = GETPOST('sortorder','alpha');
53
-$page = GETPOST('page','int');
50
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
51
+$sortfield = GETPOST('sortfield', 'alpha');
52
+$sortorder = GETPOST('sortorder', 'alpha');
53
+$page = GETPOST('page', 'int');
54 54
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
55 55
 $offset = $limit * $page;
56 56
 $pageprev = $page - 1;
57 57
 $pagenext = $page + 1;
58
-if (! $sortorder)
58
+if (!$sortorder)
59 59
 	$sortorder = "ASC";
60
-if (! $sortfield)
60
+if (!$sortfield)
61 61
 	$sortfield = "email";
62 62
 
63 63
 $id = GETPOST('id', 'int');
64 64
 $rowid = GETPOST('rowid', 'int');
65
-$action = GETPOST('action','aZ09');
65
+$action = GETPOST('action', 'aZ09');
66 66
 $search_nom = GETPOST("search_nom");
67 67
 $search_prenom = GETPOST("search_prenom");
68 68
 $search_email = GETPOST("search_email");
69 69
 $template_id = GETPOST('template_id', 'int');
70 70
 
71 71
 // Do we click on purge search criteria ?
72
-if (GETPOST('button_removefilter_x','alpha')) {
72
+if (GETPOST('button_removefilter_x', 'alpha')) {
73 73
 	$search_nom = '';
74 74
 	$search_prenom = '';
75 75
 	$search_email = '';
76 76
 }
77
-$array_query = array ();
77
+$array_query = array();
78 78
 $object = new Mailing($db);
79 79
 $advTarget = new AdvanceTargetingMailing($db);
80 80
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 }
93 93
 else
94 94
 {
95
-	if (! empty($advTarget->id)) {
95
+	if (!empty($advTarget->id)) {
96 96
 		$array_query = json_decode($advTarget->filtervalue, true);
97 97
 	}
98 98
 }
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
  */
104 104
 
105 105
 if ($action == 'loadfilter') {
106
-	if (! empty($template_id)) {
106
+	if (!empty($template_id)) {
107 107
 		$result = $advTarget->fetch($template_id);
108 108
 		if ($result < 0) {
109 109
 			setEventMessages($advTarget->error, $advTarget->errors, 'errors');
110 110
 		} else {
111
-			if (! empty($advTarget->id)) {
111
+			if (!empty($advTarget->id)) {
112 112
 				$array_query = json_decode($advTarget->filtervalue, true);
113 113
 			}
114 114
 		}
@@ -119,26 +119,26 @@  discard block
 block discarded – undo
119 119
 
120 120
 	$user_contact_query = false;
121 121
 
122
-	$array_query = array ();
122
+	$array_query = array();
123 123
 
124 124
 	// Get extra fields
125 125
 
126
-	foreach ( $_POST as $key => $value ) {
126
+	foreach ($_POST as $key => $value) {
127 127
 		// print '$key='.$key.' $value='.$value.'<BR>';
128 128
 		if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
129 129
 			// Special case for start date come with 3 inputs day, month, year
130 130
 			if (preg_match("/st_dt/", $key)) {
131
-				$dtarr = array ();
131
+				$dtarr = array();
132 132
 				$dtarr = explode('_', $key);
133
-				if (! array_key_exists('options_' . $dtarr[1] . '_st_dt', $array_query)) {
134
-					$array_query['options_' . $dtarr[1] . '_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear', 'int'));
133
+				if (!array_key_exists('options_'.$dtarr[1].'_st_dt', $array_query)) {
134
+					$array_query['options_'.$dtarr[1].'_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_st_dtmonth', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtday', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtyear', 'int'));
135 135
 				}
136 136
 			} elseif (preg_match("/end_dt/", $key)) {
137 137
 				// Special case for end date come with 3 inputs day, month, year
138
-				$dtarr = array ();
138
+				$dtarr = array();
139 139
 				$dtarr = explode('_', $key);
140
-				if (! array_key_exists('options_' . $dtarr[1] . '_end_dt', $array_query)) {
141
-					$array_query['options_' . $dtarr[1] . '_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear', 'int'));
140
+				if (!array_key_exists('options_'.$dtarr[1].'_end_dt', $array_query)) {
141
+					$array_query['options_'.$dtarr[1].'_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_end_dtmonth', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtday', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtyear', 'int'));
142 142
 				}
143 143
 			} else {
144 144
 				$array_query[$key] = GETPOST($key);
@@ -148,17 +148,17 @@  discard block
 block discarded – undo
148 148
 			$user_contact_query = true;
149 149
 			// Special case for start date come with 3 inputs day, month, year
150 150
 			if (preg_match("/st_dt/", $key)) {
151
-				$dtarr = array ();
151
+				$dtarr = array();
152 152
 				$dtarr = explode('_', $key);
153
-				if (! array_key_exists('options_' . $dtarr[1] . '_st_dt' . '_cnct', $array_query)) {
154
-					$array_query['options_' . $dtarr[1] . '_st_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear' . '_cnct', 'int'));
153
+				if (!array_key_exists('options_'.$dtarr[1].'_st_dt'.'_cnct', $array_query)) {
154
+					$array_query['options_'.$dtarr[1].'_st_dt'.'_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_st_dtmonth'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtday'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtyear'.'_cnct', 'int'));
155 155
 				}
156 156
 			} elseif (preg_match("/end_dt/", $key)) {
157 157
 				// Special case for end date come with 3 inputs day, month, year
158
-				$dtarr = array ();
158
+				$dtarr = array();
159 159
 				$dtarr = explode('_', $key);
160
-				if (! array_key_exists('options_' . $dtarr[1] . '_end_dt' . '_cnct', $array_query)) {
161
-					$array_query['options_' . $dtarr[1] . '_end_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear' . '_cnct', 'int'));
160
+				if (!array_key_exists('options_'.$dtarr[1].'_end_dt'.'_cnct', $array_query)) {
161
+					$array_query['options_'.$dtarr[1].'_end_dt'.'_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_end_dtmonth'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtday'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtyear'.'_cnct', 'int'));
162 162
 				}
163 163
 			} else {
164 164
 				$array_query[$key] = GETPOST($key);
@@ -173,24 +173,24 @@  discard block
 block discarded – undo
173 173
 
174 174
 			$array_query[$key] = GETPOST($key);
175 175
 
176
-			$specials_date_key = array (
176
+			$specials_date_key = array(
177 177
 					'contact_update_st_dt',
178 178
 					'contact_update_end_dt',
179 179
 					'contact_create_st_dt',
180 180
 					'contact_create_end_dt'
181 181
 			);
182
-			foreach ( $specials_date_key as $date_key ) {
182
+			foreach ($specials_date_key as $date_key) {
183 183
 				if ($key == $date_key) {
184 184
 					$dt = GETPOST($date_key);
185
-					if (! empty($dt)) {
186
-						$array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key . 'month', 'int'), GETPOST($date_key . 'day', 'int'), GETPOST($date_key . 'year', 'int'));
185
+					if (!empty($dt)) {
186
+						$array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key.'month', 'int'), GETPOST($date_key.'day', 'int'), GETPOST($date_key.'year', 'int'));
187 187
 					} else {
188 188
 						$array_query[$key] = '';
189 189
 					}
190 190
 				}
191 191
 			}
192 192
 
193
-			if (! empty($array_query[$key])) {
193
+			if (!empty($array_query[$key])) {
194 194
 				$user_contact_query = true;
195 195
 			}
196 196
 		}
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 		}
221 221
 		// If use contact but no result use artefact to so not use socid into add_to_target
222 222
 		if (count($advTarget->contact_lines) == 0) {
223
-			$advTarget->contact_lines = array (
223
+			$advTarget->contact_lines = array(
224 224
 					0
225 225
 			);
226 226
 		}
227 227
 	} else {
228
-		$advTarget->contact_lines = array ();
228
+		$advTarget->contact_lines = array();
229 229
 	}
230 230
 
231 231
 	if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) {
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
 
239 239
 	if ($result > 0) {
240 240
 		$query_temlate_id = '';
241
-		if (! empty($template_id)) {
242
-			$query_temlate_id = '&template_id=' . $template_id;
241
+		if (!empty($template_id)) {
242
+			$query_temlate_id = '&template_id='.$template_id;
243 243
 		}
244
-		setEventMessages($langs->trans("XTargetsAdded",$result), null, 'mesgs');
245
-		header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id . $query_temlate_id);
244
+		setEventMessages($langs->trans("XTargetsAdded", $result), null, 'mesgs');
245
+		header("Location: ".$_SERVER['PHP_SELF']."?id=".$id.$query_temlate_id);
246 246
 		exit();
247 247
 	}
248 248
 	if ($result == 0) {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	$obj = new $classname($db);
260 260
 	$obj->clear_target($id);
261 261
 
262
-	header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
262
+	header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
263 263
 	exit();
264 264
 }
265 265
 
@@ -270,29 +270,29 @@  discard block
 block discarded – undo
270 270
 
271 271
 	if ($action == 'createfilter' && empty($template_name)) {
272 272
 		setEventMessages($langs->trans('ErrorFieldRequired', $langs->trans('AdvTgtOrCreateNewFilter')), null, 'errors');
273
-		$error ++;
273
+		$error++;
274 274
 	}
275 275
 
276 276
 	if (empty($error)) {
277 277
 
278
-		$array_query = array ();
278
+		$array_query = array();
279 279
 
280 280
 		// Get extra fields
281
-		foreach ( $_POST as $key => $value ) {
281
+		foreach ($_POST as $key => $value) {
282 282
 			if (preg_match("/^options_.*(?<!_cnct)$/", $key)) {
283 283
 				// Special case for start date come with 3 inputs day, month, year
284 284
 				if (preg_match("/st_dt/", $key)) {
285
-					$dtarr = array ();
285
+					$dtarr = array();
286 286
 					$dtarr = explode('_', $key);
287
-					if (! array_key_exists('options_' . $dtarr[1] . '_st_dt', $array_query)) {
288
-						$array_query['options_' . $dtarr[1] . '_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear', 'int'));
287
+					if (!array_key_exists('options_'.$dtarr[1].'_st_dt', $array_query)) {
288
+						$array_query['options_'.$dtarr[1].'_st_dt'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_st_dtmonth', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtday', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtyear', 'int'));
289 289
 					}
290 290
 				} elseif (preg_match("/end_dt/", $key)) {
291 291
 					// Special case for end date come with 3 inputs day, month, year
292
-					$dtarr = array ();
292
+					$dtarr = array();
293 293
 					$dtarr = explode('_', $key);
294
-					if (! array_key_exists('options_' . $dtarr[1] . '_end_dt', $array_query)) {
295
-						$array_query['options_' . $dtarr[1] . '_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear', 'int'));
294
+					if (!array_key_exists('options_'.$dtarr[1].'_end_dt', $array_query)) {
295
+						$array_query['options_'.$dtarr[1].'_end_dt'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_end_dtmonth', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtday', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtyear', 'int'));
296 296
 						// print $array_query['options_'.$dtarr[1].'_end_dt'];
297 297
 						// 01/02/1013=1361228400
298 298
 					}
@@ -303,17 +303,17 @@  discard block
 block discarded – undo
303 303
 			if (preg_match("/^options_.*_cnct/", $key)) {
304 304
 				// Special case for start date come with 3 inputs day, month, year
305 305
 				if (preg_match("/st_dt/", $key)) {
306
-					$dtarr = array ();
306
+					$dtarr = array();
307 307
 					$dtarr = explode('_', $key);
308
-					if (! array_key_exists('options_' . $dtarr[1] . '_st_dt' . '_cnct', $array_query)) {
309
-						$array_query['options_' . $dtarr[1] . '_st_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_st_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_st_dtyear' . '_cnct', 'int'));
308
+					if (!array_key_exists('options_'.$dtarr[1].'_st_dt'.'_cnct', $array_query)) {
309
+						$array_query['options_'.$dtarr[1].'_st_dt'.'_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_st_dtmonth'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtday'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_st_dtyear'.'_cnct', 'int'));
310 310
 					}
311 311
 				} elseif (preg_match("/end_dt/", $key)) {
312 312
 					// Special case for end date come with 3 inputs day, month, year
313
-					$dtarr = array ();
313
+					$dtarr = array();
314 314
 					$dtarr = explode('_', $key);
315
-					if (! array_key_exists('options_' . $dtarr[1] . '_end_dt' . '_cnct', $array_query)) {
316
-						$array_query['options_' . $dtarr[1] . '_end_dt' . '_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_' . $dtarr[1] . '_end_dtmonth' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtday' . '_cnct', 'int'), GETPOST('options_' . $dtarr[1] . '_end_dtyear' . '_cnct', 'int'));
315
+					if (!array_key_exists('options_'.$dtarr[1].'_end_dt'.'_cnct', $array_query)) {
316
+						$array_query['options_'.$dtarr[1].'_end_dt'.'_cnct'] = dol_mktime(0, 0, 0, GETPOST('options_'.$dtarr[1].'_end_dtmonth'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtday'.'_cnct', 'int'), GETPOST('options_'.$dtarr[1].'_end_dtyear'.'_cnct', 'int'));
317 317
 						// print $array_query['cnct_options_'.$dtarr[1].'_end_dt'];
318 318
 						// 01/02/1013=1361228400
319 319
 					}
@@ -330,17 +330,17 @@  discard block
 block discarded – undo
330 330
 
331 331
 				$array_query[$key] = GETPOST($key);
332 332
 
333
-				$specials_date_key = array (
333
+				$specials_date_key = array(
334 334
 						'contact_update_st_dt',
335 335
 						'contact_update_end_dt',
336 336
 						'contact_create_st_dt',
337 337
 						'contact_create_end_dt'
338 338
 				);
339
-				foreach ( $specials_date_key as $date_key ) {
339
+				foreach ($specials_date_key as $date_key) {
340 340
 					if ($key == $date_key) {
341 341
 						$dt = GETPOST($date_key);
342
-						if (! empty($dt)) {
343
-							$array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key . 'month', 'int'), GETPOST($date_key . 'day', 'int'), GETPOST($date_key . 'year', 'int'));
342
+						if (!empty($dt)) {
343
+							$array_query[$key] = dol_mktime(0, 0, 0, GETPOST($date_key.'month', 'int'), GETPOST($date_key.'day', 'int'), GETPOST($date_key.'year', 'int'));
344 344
 						} else {
345 345
 							$array_query[$key] = '';
346 346
 						}
@@ -376,21 +376,21 @@  discard block
 block discarded – undo
376 376
 	if ($result < 0) {
377 377
 		setEventMessages($advTarget->error, $advTarget->errors, 'errors');
378 378
 	}
379
-	header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
379
+	header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
380 380
 	exit();
381 381
 }
382 382
 
383 383
 if ($action == 'delete') {
384 384
 	// Ici, rowid indique le destinataire et id le mailing
385
-	$sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing_cibles WHERE rowid=" . $rowid;
385
+	$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$rowid;
386 386
 	$resql = $db->query($sql);
387 387
 	if ($resql) {
388
-		if (! empty($id)) {
388
+		if (!empty($id)) {
389 389
 			$classname = "MailingTargets";
390 390
 			$obj = new $classname($db);
391 391
 			$obj->update_nb($id);
392 392
 
393
-			header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
393
+			header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
394 394
 			exit();
395 395
 		} else {
396 396
 			header("Location: liste.php");
@@ -430,30 +430,30 @@  discard block
 block discarded – undo
430 430
 
431 431
 	print '<table class="border" width="100%">';
432 432
 
433
-	$linkback = '<a href="' . DOL_URL_ROOT . '/comm/mailing/liste.php">' . $langs->trans("BackToList") . '</a>';
433
+	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/liste.php">'.$langs->trans("BackToList").'</a>';
434 434
 
435
-	print '<tr><td width="25%">' . $langs->trans("Ref") . '</td>';
435
+	print '<tr><td width="25%">'.$langs->trans("Ref").'</td>';
436 436
 	print '<td colspan="3">';
437 437
 	print $form->showrefnav($object, 'id', $linkback);
438 438
 	print '</td></tr>';
439 439
 
440
-	print '<tr><td width="25%">' . $langs->trans("MailTitle") . '</td><td colspan="3">' . $object->titre . '</td></tr>';
440
+	print '<tr><td width="25%">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
441 441
 
442
-	print '<tr><td width="25%">' . $langs->trans("MailFrom") . '</td><td colspan="3">' . dol_print_email($object->email_from, 0, 0, 0, 0, 1) . '</td></tr>';
442
+	print '<tr><td width="25%">'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'</td></tr>';
443 443
 
444 444
 	// Errors to
445
-	print '<tr><td width="25%">' . $langs->trans("MailErrorsTo") . '</td><td colspan="3">' . dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
445
+	print '<tr><td width="25%">'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
446 446
 	print '</td></tr>';
447 447
 
448 448
 	// Status
449
-	print '<tr><td width="25%">' . $langs->trans("Status") . '</td><td colspan="3">' . $object->getLibStatut(4) . '</td></tr>';
449
+	print '<tr><td width="25%">'.$langs->trans("Status").'</td><td colspan="3">'.$object->getLibStatut(4).'</td></tr>';
450 450
 
451 451
 	// Nb of distinct emails
452 452
 	print '<tr><td width="25%">';
453 453
 	print $langs->trans("TotalNbOfDistinctRecipients");
454 454
 	print '</td><td colspan="3">';
455 455
 	$nbemail = ($object->nbemail ? $object->nbemail : '0');
456
-	if (! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
456
+	if (!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) {
457 457
 		$text = $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
458 458
 		print $form->textwithpicto($nbemail, $text, 1, 'warning');
459 459
 	} else {
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 	// Show email selectors
469 469
 	if ($object->statut == 0 && $user->rights->mailing->creer) {
470 470
 
471
-		include DOL_DOCUMENT_ROOT . '/core/tpl/advtarget.tpl.php';
471
+		include DOL_DOCUMENT_ROOT.'/core/tpl/advtarget.tpl.php';
472 472
 	}
473 473
 }
474 474
 
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/mailing/index.php 3 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
             if (preg_match("/(.*)\.(.*)\.(.*)/i",$file,$reg))
83 83
             {
84 84
                 $modulename=$reg[1];
85
-       			if ($modulename == 'example') continue;
85
+                    if ($modulename == 'example') continue;
86 86
 
87 87
                 // Loading Class
88 88
                 $file = $dir."/".$modulename.".modules.php";
@@ -111,22 +111,22 @@  discard block
 block discarded – undo
111 111
                         $result=$db->query($sql);
112 112
                         if ($result)
113 113
                         {
114
-                          $num = $db->num_rows($result);
114
+                            $num = $db->num_rows($result);
115 115
 
116
-                          $i = 0;
116
+                            $i = 0;
117 117
 
118
-                          while ($i < $num )
118
+                            while ($i < $num )
119 119
                             {
120
-                              $obj = $db->fetch_object($result);
121
-                              print '<td>'.img_object('',$mailmodule->picto).' '.$obj->label.'</td><td align="right">'.$obj->nb.'<td>';
122
-                              $i++;
120
+                                $obj = $db->fetch_object($result);
121
+                                print '<td>'.img_object('',$mailmodule->picto).' '.$obj->label.'</td><td align="right">'.$obj->nb.'<td>';
122
+                                $i++;
123 123
                             }
124 124
 
125
-                          $db->free($result);
125
+                            $db->free($result);
126 126
                         }
127 127
                         else
128 128
                         {
129
-                          dol_print_error($db);
129
+                            dol_print_error($db);
130 130
                         }
131 131
                         print '</tr>';
132 132
                     }
@@ -156,43 +156,43 @@  discard block
 block discarded – undo
156 156
 $result=$db->query($sql);
157 157
 if ($result)
158 158
 {
159
-  print '<table class="noborder" width="100%">';
160
-  print '<tr class="liste_titre">';
161
-  print '<td colspan="2">'.$langs->trans("LastMailings",$limit).'</td>';
162
-  print '<td align="center">'.$langs->trans("DateCreation").'</td>';
163
-  print '<td align="center">'.$langs->trans("NbOfEMails").'</td>';
164
-  print '<td align="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td></tr>';
165
-
166
-  $num = $db->num_rows($result);
167
-  if ($num > 0)
168
-  {
169
-      $i = 0;
159
+    print '<table class="noborder" width="100%">';
160
+    print '<tr class="liste_titre">';
161
+    print '<td colspan="2">'.$langs->trans("LastMailings",$limit).'</td>';
162
+    print '<td align="center">'.$langs->trans("DateCreation").'</td>';
163
+    print '<td align="center">'.$langs->trans("NbOfEMails").'</td>';
164
+    print '<td align="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td></tr>';
165
+
166
+    $num = $db->num_rows($result);
167
+    if ($num > 0)
168
+    {
169
+        $i = 0;
170 170
 
171 171
     while ($i < $num )
172
-	{
173
-	  $obj = $db->fetch_object($result);
174
-
175
-	  print '<tr class="oddeven">';
176
-	  print '<td class="nowrap"><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowEMail"),"email").' '.$obj->rowid.'</a></td>';
177
-	  print '<td>'.dol_trunc($obj->titre,38).'</td>';
178
-	  print '<td align="center">'.dol_print_date($db->jdate($obj->date_creat),'day').'</td>';
179
-	  print '<td align="center">'.($obj->nbemail?$obj->nbemail:"0").'</td>';
180
-	  $mailstatic=new Mailing($db);
181
-	  print '<td align="right">'.$mailstatic->LibStatut($obj->statut,5).'</td>';
182
-      print '</tr>';
183
-	  $i++;
184
-	}
172
+    {
173
+        $obj = $db->fetch_object($result);
174
+
175
+        print '<tr class="oddeven">';
176
+        print '<td class="nowrap"><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowEMail"),"email").' '.$obj->rowid.'</a></td>';
177
+        print '<td>'.dol_trunc($obj->titre,38).'</td>';
178
+        print '<td align="center">'.dol_print_date($db->jdate($obj->date_creat),'day').'</td>';
179
+        print '<td align="center">'.($obj->nbemail?$obj->nbemail:"0").'</td>';
180
+        $mailstatic=new Mailing($db);
181
+        print '<td align="right">'.$mailstatic->LibStatut($obj->statut,5).'</td>';
182
+        print '</tr>';
183
+        $i++;
185 184
     }
186
-  else
185
+    }
186
+    else
187 187
     {
188
-     print '<tr><td class="opacitymedium">'.$langs->trans("None").'</td></tr>';
188
+        print '<tr><td class="opacitymedium">'.$langs->trans("None").'</td></tr>';
189 189
     }
190
-  print "</table><br>";
191
-  $db->free($result);
190
+    print "</table><br>";
191
+    $db->free($result);
192 192
 }
193 193
 else
194 194
 {
195
-  dol_print_error($db);
195
+    dol_print_error($db);
196 196
 }
197 197
 
198 198
 
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
     print '</div>';
208 208
 
209 209
     print '<br>';
210
- }
210
+    }
211 211
 
212 212
 // End of page
213 213
 llxFooter();
Please login to merge, or discard this patch.
Braces   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -82,7 +82,9 @@  discard block
 block discarded – undo
82 82
             if (preg_match("/(.*)\.(.*)\.(.*)/i",$file,$reg))
83 83
             {
84 84
                 $modulename=$reg[1];
85
-       			if ($modulename == 'example') continue;
85
+       			if ($modulename == 'example') {
86
+       			    continue;
87
+       			}
86 88
 
87 89
                 // Loading Class
88 90
                 $file = $dir."/".$modulename.".modules.php";
@@ -123,8 +125,7 @@  discard block
 block discarded – undo
123 125
                             }
124 126
 
125 127
                           $db->free($result);
126
-                        }
127
-                        else
128
+                        } else
128 129
                         {
129 130
                           dol_print_error($db);
130 131
                         }
@@ -182,15 +183,13 @@  discard block
 block discarded – undo
182 183
       print '</tr>';
183 184
 	  $i++;
184 185
 	}
185
-    }
186
-  else
186
+    } else
187 187
     {
188 188
      print '<tr><td class="opacitymedium">'.$langs->trans("None").'</td></tr>';
189 189
     }
190 190
   print "</table><br>";
191 191
   $db->free($result);
192
-}
193
-else
192
+} else
194 193
 {
195 194
   dol_print_error($db);
196 195
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 
27 27
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
28 28
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
29
-require DOL_BASE_PATH . '/main.inc.php';
30
-require_once DOL_DOCUMENT_ROOT .'/comm/mailing/class/mailing.class.php';
29
+require DOL_BASE_PATH.'/main.inc.php';
30
+require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
32 32
 
33 33
 // Load translation files required by the page
@@ -35,15 +35,15 @@  discard block
 block discarded – undo
35 35
 
36 36
 
37 37
 // Security check
38
-$result=restrictedArea($user,'mailing');
38
+$result = restrictedArea($user, 'mailing');
39 39
 
40 40
 
41 41
 /*
42 42
  *	View
43 43
  */
44 44
 
45
-$help_url='EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
46
-llxHeader('','EMailing',$help_url);
45
+$help_url = 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing';
46
+llxHeader('', 'EMailing', $help_url);
47 47
 
48 48
 print load_fiche_titre($langs->trans("MailingArea"));
49 49
 
@@ -73,18 +73,18 @@  discard block
 block discarded – undo
73 73
 print '<table class="noborder" width="100%">';
74 74
 print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("TargetsStatistics").'</td></tr>';
75 75
 
76
-$dir=DOL_DOCUMENT_ROOT."/core/modules/mailings";
77
-$handle=opendir($dir);
76
+$dir = DOL_DOCUMENT_ROOT."/core/modules/mailings";
77
+$handle = opendir($dir);
78 78
 
79 79
 if (is_resource($handle))
80 80
 {
81
-    while (($file = readdir($handle))!==false)
81
+    while (($file = readdir($handle)) !== false)
82 82
     {
83 83
         if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
84 84
         {
85
-            if (preg_match("/(.*)\.(.*)\.(.*)/i",$file,$reg))
85
+            if (preg_match("/(.*)\.(.*)\.(.*)/i", $file, $reg))
86 86
             {
87
-                $modulename=$reg[1];
87
+                $modulename = $reg[1];
88 88
        			if ($modulename == 'example') continue;
89 89
 
90 90
                 // Loading Class
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
                 require_once $file;
94 94
                 $mailmodule = new $classname($db);
95 95
 
96
-                $qualified=1;
96
+                $qualified = 1;
97 97
                 foreach ($mailmodule->require_module as $key)
98 98
                 {
99
-                    if (! $conf->$key->enabled || (! $user->admin && $mailmodule->require_admin))
99
+                    if (!$conf->$key->enabled || (!$user->admin && $mailmodule->require_admin))
100 100
                     {
101
-                        $qualified=0;
101
+                        $qualified = 0;
102 102
                         //print "Les pr�requis d'activation du module mailing ne sont pas respect�s. Il ne sera pas actif";
103 103
                         break;
104 104
                     }
@@ -111,17 +111,17 @@  discard block
 block discarded – undo
111 111
                     {
112 112
                         print '<tr class="oddeven">';
113 113
 
114
-                        $result=$db->query($sql);
114
+                        $result = $db->query($sql);
115 115
                         if ($result)
116 116
                         {
117 117
                           $num = $db->num_rows($result);
118 118
 
119 119
                           $i = 0;
120 120
 
121
-                          while ($i < $num )
121
+                          while ($i < $num)
122 122
                             {
123 123
                               $obj = $db->fetch_object($result);
124
-                              print '<td>'.img_object('',$mailmodule->picto).' '.$obj->label.'</td><td align="right">'.$obj->nb.'<td>';
124
+                              print '<td>'.img_object('', $mailmodule->picto).' '.$obj->label.'</td><td align="right">'.$obj->nb.'<td>';
125 125
                               $i++;
126 126
                             }
127 127
 
@@ -151,17 +151,17 @@  discard block
 block discarded – undo
151 151
 /*
152 152
  * List of last emailings
153 153
  */
154
-$limit=10;
154
+$limit = 10;
155 155
 $sql  = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat";
156
-$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
157
-$sql.= " ORDER BY m.date_creat DESC";
158
-$sql.= " LIMIT ".$limit;
159
-$result=$db->query($sql);
156
+$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
157
+$sql .= " ORDER BY m.date_creat DESC";
158
+$sql .= " LIMIT ".$limit;
159
+$result = $db->query($sql);
160 160
 if ($result)
161 161
 {
162 162
   print '<table class="noborder" width="100%">';
163 163
   print '<tr class="liste_titre">';
164
-  print '<td colspan="2">'.$langs->trans("LastMailings",$limit).'</td>';
164
+  print '<td colspan="2">'.$langs->trans("LastMailings", $limit).'</td>';
165 165
   print '<td align="center">'.$langs->trans("DateCreation").'</td>';
166 166
   print '<td align="center">'.$langs->trans("NbOfEMails").'</td>';
167 167
   print '<td align="right"><a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("AllEMailings").'</a></td></tr>';
@@ -171,17 +171,17 @@  discard block
 block discarded – undo
171 171
   {
172 172
       $i = 0;
173 173
 
174
-    while ($i < $num )
174
+    while ($i < $num)
175 175
 	{
176 176
 	  $obj = $db->fetch_object($result);
177 177
 
178 178
 	  print '<tr class="oddeven">';
179
-	  print '<td class="nowrap"><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowEMail"),"email").' '.$obj->rowid.'</a></td>';
180
-	  print '<td>'.dol_trunc($obj->titre,38).'</td>';
181
-	  print '<td align="center">'.dol_print_date($db->jdate($obj->date_creat),'day').'</td>';
182
-	  print '<td align="center">'.($obj->nbemail?$obj->nbemail:"0").'</td>';
183
-	  $mailstatic=new Mailing($db);
184
-	  print '<td align="right">'.$mailstatic->LibStatut($obj->statut,5).'</td>';
179
+	  print '<td class="nowrap"><a href="card.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowEMail"), "email").' '.$obj->rowid.'</a></td>';
180
+	  print '<td>'.dol_trunc($obj->titre, 38).'</td>';
181
+	  print '<td align="center">'.dol_print_date($db->jdate($obj->date_creat), 'day').'</td>';
182
+	  print '<td align="center">'.($obj->nbemail ? $obj->nbemail : "0").'</td>';
183
+	  $mailstatic = new Mailing($db);
184
+	  print '<td align="right">'.$mailstatic->LibStatut($obj->statut, 5).'</td>';
185 185
       print '</tr>';
186 186
 	  $i++;
187 187
 	}
@@ -203,10 +203,10 @@  discard block
 block discarded – undo
203 203
 print '</div></div></div>';
204 204
 
205 205
 
206
-if ($langs->file_exists("html/spam.html",0)) {
206
+if ($langs->file_exists("html/spam.html", 0)) {
207 207
     print "<br><br><br><br>".$langs->trans("Note")."<br>";
208 208
     print '<div style="padding: 4px; background: #FAFAFA; border: 1px solid #BBBBBB;" >';
209
-    dol_print_file($langs,"html/spam.html",0);
209
+    dol_print_file($langs, "html/spam.html", 0);
210 210
     print '</div>';
211 211
 
212 212
     print '<br>';
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/mailing/cibles.php 3 patches
Indentation   +496 added lines, -496 removed lines patch added patch discarded remove patch
@@ -72,52 +72,52 @@  discard block
 block discarded – undo
72 72
 
73 73
 if ($action == 'add')
74 74
 {
75
-	$module=GETPOST("module",'alpha');
76
-	$result=-1;
77
-
78
-	foreach ($modulesdir as $dir)
79
-	{
80
-	    // Load modules attributes in arrays (name, numero, orders) from dir directory
81
-	    //print $dir."\n<br>";
82
-	    dol_syslog("Scan directory ".$dir." for modules");
83
-
84
-	    // Loading Class
85
-	    $file = $dir."/".$module.".modules.php";
86
-	    $classname = "mailing_".$module;
87
-
88
-		if (file_exists($file))
89
-		{
90
-			require_once $file;
91
-
92
-			// Add targets into database
93
-			$obj = new $classname($db);
94
-			dol_syslog("Call add_to_target on class ".$classname);
95
-			$result=$obj->add_to_target($id);
96
-		}
97
-	}
98
-	if ($result > 0)
99
-	{
100
-		setEventMessages($langs->trans("XTargetsAdded",$result), null, 'mesgs');
101
-
102
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
103
-		exit;
104
-	}
105
-	if ($result == 0)
106
-	{
107
-		setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
108
-	}
109
-	if ($result < 0)
110
-	{
111
-		setEventMessages($langs->trans("Error").($obj->error?' '.$obj->error:''), null, 'errors');
112
-	}
75
+    $module=GETPOST("module",'alpha');
76
+    $result=-1;
77
+
78
+    foreach ($modulesdir as $dir)
79
+    {
80
+        // Load modules attributes in arrays (name, numero, orders) from dir directory
81
+        //print $dir."\n<br>";
82
+        dol_syslog("Scan directory ".$dir." for modules");
83
+
84
+        // Loading Class
85
+        $file = $dir."/".$module.".modules.php";
86
+        $classname = "mailing_".$module;
87
+
88
+        if (file_exists($file))
89
+        {
90
+            require_once $file;
91
+
92
+            // Add targets into database
93
+            $obj = new $classname($db);
94
+            dol_syslog("Call add_to_target on class ".$classname);
95
+            $result=$obj->add_to_target($id);
96
+        }
97
+    }
98
+    if ($result > 0)
99
+    {
100
+        setEventMessages($langs->trans("XTargetsAdded",$result), null, 'mesgs');
101
+
102
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
103
+        exit;
104
+    }
105
+    if ($result == 0)
106
+    {
107
+        setEventMessages($langs->trans("WarningNoEMailsAdded"), null, 'warnings');
108
+    }
109
+    if ($result < 0)
110
+    {
111
+        setEventMessages($langs->trans("Error").($obj->error?' '.$obj->error:''), null, 'errors');
112
+    }
113 113
 }
114 114
 
115 115
 if (GETPOST('clearlist'))
116 116
 {
117
-	// Loading Class
118
-	$obj = new MailingTargets($db);
119
-	$obj->clear_target($id);
120
-	/* Avoid this to allow reposition
117
+    // Loading Class
118
+    $obj = new MailingTargets($db);
119
+    $obj->clear_target($id);
120
+    /* Avoid this to allow reposition
121 121
 	header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
122 122
 	exit;
123 123
 	*/
@@ -125,39 +125,39 @@  discard block
 block discarded – undo
125 125
 
126 126
 if ($action == 'delete')
127 127
 {
128
-	// Ici, rowid indique le destinataire et id le mailing
129
-	$sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$rowid;
130
-	$resql=$db->query($sql);
131
-	if ($resql)
132
-	{
133
-		if (!empty($id))
134
-		{
135
-			$obj = new MailingTargets($db);
136
-			$obj->update_nb($id);
137
-
138
-			header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
139
-			exit;
140
-		}
141
-		else
142
-		{
143
-			header("Location: list.php");
144
-			exit;
145
-		}
146
-	}
147
-	else
148
-	{
149
-		dol_print_error($db);
150
-	}
128
+    // Ici, rowid indique le destinataire et id le mailing
129
+    $sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$rowid;
130
+    $resql=$db->query($sql);
131
+    if ($resql)
132
+    {
133
+        if (!empty($id))
134
+        {
135
+            $obj = new MailingTargets($db);
136
+            $obj->update_nb($id);
137
+
138
+            header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
139
+            exit;
140
+        }
141
+        else
142
+        {
143
+            header("Location: list.php");
144
+            exit;
145
+        }
146
+    }
147
+    else
148
+    {
149
+        dol_print_error($db);
150
+    }
151 151
 }
152 152
 
153 153
 // Purge search criteria
154 154
 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
155 155
 {
156
-	$search_lastname='';
157
-	$search_firstname='';
158
-	$search_email='';
159
-	$search_other='';
160
-	$search_dest_status='';
156
+    $search_lastname='';
157
+    $search_firstname='';
158
+    $search_email='';
159
+    $search_other='';
160
+    $search_dest_status='';
161 161
 }
162 162
 
163 163
 
@@ -173,377 +173,377 @@  discard block
 block discarded – undo
173 173
 
174 174
 if ($object->fetch($id) >= 0)
175 175
 {
176
-	$head = emailing_prepare_head($object);
177
-
178
-	dol_fiche_head($head, 'targets', $langs->trans("Mailing"), -1, 'email');
179
-
180
-	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
181
-
182
-	$morehtmlright='';
183
-	$nbtry = $nbok = 0;
184
-	if ($object->statut == 2 || $object->statut == 3)
185
-	{
186
-		$nbtry = $object->countNbOfTargets('alreadysent');
187
-		$nbko  = $object->countNbOfTargets('alreadysentko');
188
-
189
-		$morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
190
-		if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
191
-		$morehtmlright.=') &nbsp; ';
192
-	}
193
-
194
-	dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
195
-
196
-	print '<div class="fichecenter">';
197
-	print '<div class="underbanner clearboth"></div>';
198
-
199
-	print '<table class="border" width="100%">';
200
-
201
-	print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
202
-
203
-	print '<tr><td>'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
204
-
205
-	// Errors to
206
-	print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1);
207
-	print '</td></tr>';
208
-
209
-	// Nb of distinct emails
210
-	print '<tr><td>';
211
-	print $langs->trans("TotalNbOfDistinctRecipients");
212
-	print '</td><td colspan="3">';
213
-	$nbemail = ($object->nbemail?$object->nbemail:0);
214
-	if (is_numeric($nbemail))
215
-	{
216
-		$text='';
217
-		if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
218
-		{
219
-			if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
220
-			{
221
-				$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
222
-			}
223
-			else
224
-			{
225
-				$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
226
-			}
227
-		}
228
-		if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
229
-		if ($text)
230
-		{
231
-			print $form->textwithpicto($nbemail,$text,1,'warning');
232
-		}
233
-		else
234
-		{
235
-			print $nbemail;
236
-		}
237
-	}
238
-	print '</td></tr>';
239
-
240
-	print '</table>';
241
-
242
-	print "</div>";
243
-
244
-	dol_fiche_end();
245
-
246
-	print '<br>';
247
-
248
-
249
-	$allowaddtarget=($object->statut == 0);
250
-
251
-	// Show email selectors
252
-	if ($allowaddtarget && $user->rights->mailing->creer)
253
-	{
254
-		print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"),1):''), 'title_generic');
255
-
256
-		//print '<table class="noborder" width="100%">';
257
-		print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">';
258
-
259
-		//print '<tr class="liste_titre">';
260
-		print '<div class="tagtr liste_titre">';
261
-		//print '<td class="liste_titre">'.$langs->trans("RecipientSelectionModules").'</td>';
262
-		print '<div class="tagtd">'.$langs->trans("RecipientSelectionModules").'</div>';
263
-		//print '<td class="liste_titre" align="center">'.$langs->trans("NbOfUniqueEMails").'</td>';
264
-		print '<div class="tagtd" align="center">'.$langs->trans("NbOfUniqueEMails").'</div>';
265
-		//print '<td class="liste_titre" align="left">'.$langs->trans("Filter").'</td>';
266
-		print '<div class="tagtd" align="left">'.$langs->trans("Filter").'</div>';
267
-		//print '<td class="liste_titre" align="center">&nbsp;</td>';
268
-		print '<div class="tagtd">&nbsp;</div>';
269
-		//print "</tr>\n";
270
-		print '</div>';
271
-
272
-		clearstatcache();
273
-
274
-		foreach ($modulesdir as $dir)
275
-		{
276
-		    $modulenames=array();
277
-
278
-		    // Load modules attributes in arrays (name, numero, orders) from dir directory
279
-		    //print $dir."\n<br>";
280
-		    dol_syslog("Scan directory ".$dir." for modules");
281
-		    $handle=@opendir($dir);
282
-			if (is_resource($handle))
283
-			{
284
-				while (($file = readdir($handle))!==false)
285
-				{
286
-					if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
287
-					{
288
-						if (preg_match("/(.*)\.modules\.php$/i",$file,$reg))
289
-						{
290
-							if ($reg[1] == 'example') continue;
291
-							$modulenames[]=$reg[1];
292
-						}
293
-					}
294
-				}
295
-				closedir($handle);
296
-			}
297
-
298
-			// Sort $modulenames
299
-			sort($modulenames);
300
-
301
-			$var = true;
302
-
303
-			// Loop on each submodule
304
-			foreach($modulenames as $modulename)
305
-			{
306
-				// Loading Class
307
-				$file = $dir.$modulename.".modules.php";
308
-				$classname = "mailing_".$modulename;
309
-				require_once $file;
310
-
311
-				$obj = new $classname($db);
312
-
313
-				// Check dependencies
314
-				$qualified=(isset($obj->enabled)?$obj->enabled:1);
315
-				foreach ($obj->require_module as $key)
316
-				{
317
-					if (! $conf->$key->enabled || (! $user->admin && $obj->require_admin))
318
-					{
319
-						$qualified=0;
320
-						//print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif";
321
-						break;
322
-					}
323
-				}
324
-
325
-				// Si le module mailing est qualifie
326
-				if ($qualified)
327
-				{
328
-					$var = ! $var;
329
-
330
-					if ($allowaddtarget)
331
-					{
332
-						print '<form '.$bctag[$var].' name="'.$modulename.'" action="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'&module='.$modulename.'" method="POST" enctype="multipart/form-data">';
333
-						print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
334
-					}
335
-					else
336
-					{
337
-					    print '<div '.$bctag[$var].'>';
338
-					}
339
-
340
-					print '<div class="tagtd">';
341
-					if (empty($obj->picto)) $obj->picto='generic';
342
-					print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj),$obj->picto);
343
-					print ' ';
344
-					print $obj->getDesc();
345
-					print '</div>';
346
-
347
-					try {
348
-						$nbofrecipient=$obj->getNbOfRecipients('');
349
-					}
350
-					catch(Exception $e)
351
-					{
352
-						dol_syslog($e->getMessage(), LOG_ERR);
353
-					}
354
-
355
-					print '<div class="tagtd center">';
356
-					if ($nbofrecipient >= 0)
357
-					{
358
-						print $nbofrecipient;
359
-					}
360
-					else
361
-					{
362
-						print $langs->trans("Error").' '.img_error($obj->error);
363
-					}
364
-					print '</div>';
365
-
366
-					print '<div class="tagtd" align="left">';
367
-					if ($allowaddtarget)
368
-					{
369
-    					try {
370
-    						$filter=$obj->formFilter();
371
-    					}
372
-    					catch(Exception $e)
373
-    					{
374
-    						dol_syslog($e->getMessage(), LOG_ERR);
375
-    					}
376
-    					if ($filter) print $filter;
377
-    					else print $langs->trans("None");
378
-					}
379
-					print '</div>';
380
-
381
-					print '<div class="tagtd" align="right">';
382
-					if ($allowaddtarget)
383
-					{
384
-						print '<input type="submit" class="button" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
385
-					}
386
-					else
387
-					{
388
-					    print '<input type="submit" class="button disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
389
-						//print $langs->trans("MailNoChangePossible");
390
-						print "&nbsp;";
391
-					}
392
-					print '</div>';
393
-
394
-					if ($allowaddtarget) print '</form>';
395
-					else print '</div>';
396
-				}
397
-			}
398
-		}	// End foreach dir
399
-
400
-		print '</div>';
401
-
402
-		print '<br><br>';
403
-	}
404
-
405
-	// List of selected targets
406
-	$sql  = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.source_url, mc.source_id, mc.source_type, mc.error_text";
407
-	$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
408
-	$sql .= " WHERE mc.fk_mailing=".$object->id;
409
-	if ($search_lastname)  $sql.= natural_search("mc.lastname", $search_lastname);
410
-	if ($search_firstname) $sql.= natural_search("mc.firstname", $search_firstname);
411
-	if ($search_email)     $sql.= natural_search("mc.email", $search_email);
412
-	if ($search_other)     $sql.= natural_search("mc.other", $search_other);
413
-	if ($search_dest_status != '' && $search_dest_status >= -1) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." ";
414
-	$sql .= $db->order($sortfield,$sortorder);
415
-
416
-	// Count total nb of records
417
-	$nbtotalofrecords = '';
418
-	if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
419
-	{
420
-	    $result = $db->query($sql);
421
-	    $nbtotalofrecords = $db->num_rows($result);
422
-	    if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
423
-	    {
424
-	    	$page = 0;
425
-	    	$offset = 0;
426
-	    }
427
-	}
428
-
429
-	//$nbtotalofrecords=$object->nbemail;     // nbemail is a denormalized field storing nb of targets
430
-	$sql .= $db->plimit($limit+1, $offset);
431
-
432
-	$resql=$db->query($sql);
433
-	if ($resql)
434
-	{
435
-
436
-		$num = $db->num_rows($resql);
437
-
438
-		$param = "&amp;id=".$object->id;
439
-		//if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
440
-		if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
441
-		if ($search_lastname)  $param.= "&amp;search_lastname=".urlencode($search_lastname);
442
-		if ($search_firstname) $param.= "&amp;search_firstname=".urlencode($search_firstname);
443
-		if ($search_email)     $param.= "&amp;search_email=".urlencode($search_email);
444
-		if ($search_other)     $param.= "&amp;search_other=".urlencode($search_other);
445
-
446
-		print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
447
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
448
-		print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
449
-		print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
176
+    $head = emailing_prepare_head($object);
177
+
178
+    dol_fiche_head($head, 'targets', $langs->trans("Mailing"), -1, 'email');
179
+
180
+    $linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
181
+
182
+    $morehtmlright='';
183
+    $nbtry = $nbok = 0;
184
+    if ($object->statut == 2 || $object->statut == 3)
185
+    {
186
+        $nbtry = $object->countNbOfTargets('alreadysent');
187
+        $nbko  = $object->countNbOfTargets('alreadysentko');
188
+
189
+        $morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
190
+        if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
191
+        $morehtmlright.=') &nbsp; ';
192
+    }
193
+
194
+    dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
195
+
196
+    print '<div class="fichecenter">';
197
+    print '<div class="underbanner clearboth"></div>';
198
+
199
+    print '<table class="border" width="100%">';
200
+
201
+    print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
202
+
203
+    print '<tr><td>'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
204
+
205
+    // Errors to
206
+    print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1);
207
+    print '</td></tr>';
208
+
209
+    // Nb of distinct emails
210
+    print '<tr><td>';
211
+    print $langs->trans("TotalNbOfDistinctRecipients");
212
+    print '</td><td colspan="3">';
213
+    $nbemail = ($object->nbemail?$object->nbemail:0);
214
+    if (is_numeric($nbemail))
215
+    {
216
+        $text='';
217
+        if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
218
+        {
219
+            if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
220
+            {
221
+                $text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
222
+            }
223
+            else
224
+            {
225
+                $text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
226
+            }
227
+        }
228
+        if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
229
+        if ($text)
230
+        {
231
+            print $form->textwithpicto($nbemail,$text,1,'warning');
232
+        }
233
+        else
234
+        {
235
+            print $nbemail;
236
+        }
237
+    }
238
+    print '</td></tr>';
239
+
240
+    print '</table>';
241
+
242
+    print "</div>";
243
+
244
+    dol_fiche_end();
245
+
246
+    print '<br>';
247
+
248
+
249
+    $allowaddtarget=($object->statut == 0);
250
+
251
+    // Show email selectors
252
+    if ($allowaddtarget && $user->rights->mailing->creer)
253
+    {
254
+        print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"),1):''), 'title_generic');
255
+
256
+        //print '<table class="noborder" width="100%">';
257
+        print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">';
258
+
259
+        //print '<tr class="liste_titre">';
260
+        print '<div class="tagtr liste_titre">';
261
+        //print '<td class="liste_titre">'.$langs->trans("RecipientSelectionModules").'</td>';
262
+        print '<div class="tagtd">'.$langs->trans("RecipientSelectionModules").'</div>';
263
+        //print '<td class="liste_titre" align="center">'.$langs->trans("NbOfUniqueEMails").'</td>';
264
+        print '<div class="tagtd" align="center">'.$langs->trans("NbOfUniqueEMails").'</div>';
265
+        //print '<td class="liste_titre" align="left">'.$langs->trans("Filter").'</td>';
266
+        print '<div class="tagtd" align="left">'.$langs->trans("Filter").'</div>';
267
+        //print '<td class="liste_titre" align="center">&nbsp;</td>';
268
+        print '<div class="tagtd">&nbsp;</div>';
269
+        //print "</tr>\n";
270
+        print '</div>';
271
+
272
+        clearstatcache();
273
+
274
+        foreach ($modulesdir as $dir)
275
+        {
276
+            $modulenames=array();
277
+
278
+            // Load modules attributes in arrays (name, numero, orders) from dir directory
279
+            //print $dir."\n<br>";
280
+            dol_syslog("Scan directory ".$dir." for modules");
281
+            $handle=@opendir($dir);
282
+            if (is_resource($handle))
283
+            {
284
+                while (($file = readdir($handle))!==false)
285
+                {
286
+                    if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
287
+                    {
288
+                        if (preg_match("/(.*)\.modules\.php$/i",$file,$reg))
289
+                        {
290
+                            if ($reg[1] == 'example') continue;
291
+                            $modulenames[]=$reg[1];
292
+                        }
293
+                    }
294
+                }
295
+                closedir($handle);
296
+            }
297
+
298
+            // Sort $modulenames
299
+            sort($modulenames);
300
+
301
+            $var = true;
302
+
303
+            // Loop on each submodule
304
+            foreach($modulenames as $modulename)
305
+            {
306
+                // Loading Class
307
+                $file = $dir.$modulename.".modules.php";
308
+                $classname = "mailing_".$modulename;
309
+                require_once $file;
310
+
311
+                $obj = new $classname($db);
312
+
313
+                // Check dependencies
314
+                $qualified=(isset($obj->enabled)?$obj->enabled:1);
315
+                foreach ($obj->require_module as $key)
316
+                {
317
+                    if (! $conf->$key->enabled || (! $user->admin && $obj->require_admin))
318
+                    {
319
+                        $qualified=0;
320
+                        //print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif";
321
+                        break;
322
+                    }
323
+                }
324
+
325
+                // Si le module mailing est qualifie
326
+                if ($qualified)
327
+                {
328
+                    $var = ! $var;
329
+
330
+                    if ($allowaddtarget)
331
+                    {
332
+                        print '<form '.$bctag[$var].' name="'.$modulename.'" action="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'&module='.$modulename.'" method="POST" enctype="multipart/form-data">';
333
+                        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
334
+                    }
335
+                    else
336
+                    {
337
+                        print '<div '.$bctag[$var].'>';
338
+                    }
339
+
340
+                    print '<div class="tagtd">';
341
+                    if (empty($obj->picto)) $obj->picto='generic';
342
+                    print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj),$obj->picto);
343
+                    print ' ';
344
+                    print $obj->getDesc();
345
+                    print '</div>';
346
+
347
+                    try {
348
+                        $nbofrecipient=$obj->getNbOfRecipients('');
349
+                    }
350
+                    catch(Exception $e)
351
+                    {
352
+                        dol_syslog($e->getMessage(), LOG_ERR);
353
+                    }
354
+
355
+                    print '<div class="tagtd center">';
356
+                    if ($nbofrecipient >= 0)
357
+                    {
358
+                        print $nbofrecipient;
359
+                    }
360
+                    else
361
+                    {
362
+                        print $langs->trans("Error").' '.img_error($obj->error);
363
+                    }
364
+                    print '</div>';
365
+
366
+                    print '<div class="tagtd" align="left">';
367
+                    if ($allowaddtarget)
368
+                    {
369
+                        try {
370
+                            $filter=$obj->formFilter();
371
+                        }
372
+                        catch(Exception $e)
373
+                        {
374
+                            dol_syslog($e->getMessage(), LOG_ERR);
375
+                        }
376
+                        if ($filter) print $filter;
377
+                        else print $langs->trans("None");
378
+                    }
379
+                    print '</div>';
380
+
381
+                    print '<div class="tagtd" align="right">';
382
+                    if ($allowaddtarget)
383
+                    {
384
+                        print '<input type="submit" class="button" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
385
+                    }
386
+                    else
387
+                    {
388
+                        print '<input type="submit" class="button disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
389
+                        //print $langs->trans("MailNoChangePossible");
390
+                        print "&nbsp;";
391
+                    }
392
+                    print '</div>';
393
+
394
+                    if ($allowaddtarget) print '</form>';
395
+                    else print '</div>';
396
+                }
397
+            }
398
+        }	// End foreach dir
399
+
400
+        print '</div>';
401
+
402
+        print '<br><br>';
403
+    }
404
+
405
+    // List of selected targets
406
+    $sql  = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.source_url, mc.source_id, mc.source_type, mc.error_text";
407
+    $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
408
+    $sql .= " WHERE mc.fk_mailing=".$object->id;
409
+    if ($search_lastname)  $sql.= natural_search("mc.lastname", $search_lastname);
410
+    if ($search_firstname) $sql.= natural_search("mc.firstname", $search_firstname);
411
+    if ($search_email)     $sql.= natural_search("mc.email", $search_email);
412
+    if ($search_other)     $sql.= natural_search("mc.other", $search_other);
413
+    if ($search_dest_status != '' && $search_dest_status >= -1) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." ";
414
+    $sql .= $db->order($sortfield,$sortorder);
415
+
416
+    // Count total nb of records
417
+    $nbtotalofrecords = '';
418
+    if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
419
+    {
420
+        $result = $db->query($sql);
421
+        $nbtotalofrecords = $db->num_rows($result);
422
+        if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
423
+        {
424
+            $page = 0;
425
+            $offset = 0;
426
+        }
427
+    }
428
+
429
+    //$nbtotalofrecords=$object->nbemail;     // nbemail is a denormalized field storing nb of targets
430
+    $sql .= $db->plimit($limit+1, $offset);
431
+
432
+    $resql=$db->query($sql);
433
+    if ($resql)
434
+    {
435
+
436
+        $num = $db->num_rows($resql);
437
+
438
+        $param = "&amp;id=".$object->id;
439
+        //if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
440
+        if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
441
+        if ($search_lastname)  $param.= "&amp;search_lastname=".urlencode($search_lastname);
442
+        if ($search_firstname) $param.= "&amp;search_firstname=".urlencode($search_firstname);
443
+        if ($search_email)     $param.= "&amp;search_email=".urlencode($search_email);
444
+        if ($search_other)     $param.= "&amp;search_other=".urlencode($search_other);
445
+
446
+        print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
447
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
448
+        print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
449
+        print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
450 450
         print '<input type="hidden" name="page" value="'.$page.'">';
451
-		print '<input type="hidden" name="id" value="'.$object->id.'">';
451
+        print '<input type="hidden" name="id" value="'.$object->id.'">';
452 452
 
453
-		$cleartext='';
454
-		if ($allowaddtarget) {
455
-		    $cleartext=$langs->trans("ToClearAllRecipientsClickHere").' '.'<a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition">'.$langs->trans("TargetsReset").'</a>';
456
-		}
457
-		print_barre_liste($langs->trans("MailSelectedRecipients"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$cleartext,$num,$nbtotalofrecords,'title_generic',0,'','', $limit);
453
+        $cleartext='';
454
+        if ($allowaddtarget) {
455
+            $cleartext=$langs->trans("ToClearAllRecipientsClickHere").' '.'<a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition">'.$langs->trans("TargetsReset").'</a>';
456
+        }
457
+        print_barre_liste($langs->trans("MailSelectedRecipients"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$cleartext,$num,$nbtotalofrecords,'title_generic',0,'','', $limit);
458 458
 
459
-		print '</form>';
459
+        print '</form>';
460 460
 
461
-		print "\n<!-- Liste destinataires selectionnes -->\n";
462
-		print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
463
-		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
464
-		print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
465
-		print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
461
+        print "\n<!-- Liste destinataires selectionnes -->\n";
462
+        print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
463
+        print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
464
+        print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
465
+        print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
466 466
         print '<input type="hidden" name="page" value="'.$page.'">';
467
-		print '<input type="hidden" name="id" value="'.$object->id.'">';
468
-		print '<input type="hidden" name="limit" value="'.$limit.'">';
469
-
470
-
471
-		if ($page)	$param.= "&amp;page=".$page;
472
-
473
-		print '<div class="div-table-responsive">';
474
-		print '<table class="noborder" width="100%">';
475
-
476
-		// Ligne des champs de filtres
477
-		print '<tr class="liste_titre_filter">';
478
-		// EMail
479
-		print '<td class="liste_titre">';
480
-		print '<input class="flat maxwidth100" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
481
-		print '</td>';
482
-		// Name
483
-		print '<td class="liste_titre">';
484
-		print '<input class="flat maxwidth100" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'">';
485
-		print '</td>';
486
-		// Firstname
487
-		print '<td class="liste_titre">';
488
-		print '<input class="flat maxwidth100" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).'">';
489
-		print '</td>';
490
-		// Other
491
-		print '<td class="liste_titre">';
492
-		print '<input class="flat maxwidth100" type="text" name="search_other" value="'.dol_escape_htmltag($search_other).'">';
493
-		print '</td>';
494
-		// Source
495
-		print '<td class="liste_titre">';
496
-		print '&nbsp';
497
-		print '</td>';
498
-
499
-		// Date sending
500
-		print '<td class="liste_titre">';
501
-		print '&nbsp';
502
-		print '</td>';
503
-		//Statut
504
-		print '<td class="liste_titre" align="right">';
505
-		print $formmailing->selectDestinariesStatus($search_dest_status,'search_dest_status',1);
506
-		print '</td>';
507
-		// Action column
508
-		print '<td class="liste_titre" align="right">';
509
-		$searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
510
-		print $searchpicto;
511
-		print '</td>';
512
-		print '</tr>';
513
-
514
-		print '<tr class="liste_titre">';
515
-		print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"mc.email",$param,"","",$sortfield,$sortorder);
516
-		print_liste_field_titre("Lastname",$_SERVER["PHP_SELF"],"mc.lastname",$param,"","",$sortfield,$sortorder);
517
-		print_liste_field_titre("Firstname",$_SERVER["PHP_SELF"],"mc.firstname",$param,"","",$sortfield,$sortorder);
518
-		print_liste_field_titre("OtherInformations",$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder);
519
-		print_liste_field_titre("Source",$_SERVER["PHP_SELF"],"",$param,"",'align="center"',$sortfield,$sortorder);
520
-		// Date sending
521
-		if ($object->statut < 2)
522
-		{
523
-			print_liste_field_titre('');
524
-		}
525
-		else
526
-		{
527
-			print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder);
528
-		}
529
-		print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"mc.statut",$param,'','align="right"',$sortfield,$sortorder);
530
-		print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
531
-		print '</tr>';
532
-
533
-		$i = 0;
534
-
535
-		if ($num)
536
-		{
537
-			while ($i < min($num,$limit))
538
-			{
539
-				$obj = $db->fetch_object($resql);
540
-
541
-				print '<tr class="oddeven">';
542
-				print '<td>'.$obj->email.'</td>';
543
-				print '<td>'.$obj->lastname.'</td>';
544
-				print '<td>'.$obj->firstname.'</td>';
545
-				print '<td>'.$obj->other.'</td>';
546
-				print '<td align="center">';
467
+        print '<input type="hidden" name="id" value="'.$object->id.'">';
468
+        print '<input type="hidden" name="limit" value="'.$limit.'">';
469
+
470
+
471
+        if ($page)	$param.= "&amp;page=".$page;
472
+
473
+        print '<div class="div-table-responsive">';
474
+        print '<table class="noborder" width="100%">';
475
+
476
+        // Ligne des champs de filtres
477
+        print '<tr class="liste_titre_filter">';
478
+        // EMail
479
+        print '<td class="liste_titre">';
480
+        print '<input class="flat maxwidth100" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
481
+        print '</td>';
482
+        // Name
483
+        print '<td class="liste_titre">';
484
+        print '<input class="flat maxwidth100" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'">';
485
+        print '</td>';
486
+        // Firstname
487
+        print '<td class="liste_titre">';
488
+        print '<input class="flat maxwidth100" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).'">';
489
+        print '</td>';
490
+        // Other
491
+        print '<td class="liste_titre">';
492
+        print '<input class="flat maxwidth100" type="text" name="search_other" value="'.dol_escape_htmltag($search_other).'">';
493
+        print '</td>';
494
+        // Source
495
+        print '<td class="liste_titre">';
496
+        print '&nbsp';
497
+        print '</td>';
498
+
499
+        // Date sending
500
+        print '<td class="liste_titre">';
501
+        print '&nbsp';
502
+        print '</td>';
503
+        //Statut
504
+        print '<td class="liste_titre" align="right">';
505
+        print $formmailing->selectDestinariesStatus($search_dest_status,'search_dest_status',1);
506
+        print '</td>';
507
+        // Action column
508
+        print '<td class="liste_titre" align="right">';
509
+        $searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
510
+        print $searchpicto;
511
+        print '</td>';
512
+        print '</tr>';
513
+
514
+        print '<tr class="liste_titre">';
515
+        print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"mc.email",$param,"","",$sortfield,$sortorder);
516
+        print_liste_field_titre("Lastname",$_SERVER["PHP_SELF"],"mc.lastname",$param,"","",$sortfield,$sortorder);
517
+        print_liste_field_titre("Firstname",$_SERVER["PHP_SELF"],"mc.firstname",$param,"","",$sortfield,$sortorder);
518
+        print_liste_field_titre("OtherInformations",$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder);
519
+        print_liste_field_titre("Source",$_SERVER["PHP_SELF"],"",$param,"",'align="center"',$sortfield,$sortorder);
520
+        // Date sending
521
+        if ($object->statut < 2)
522
+        {
523
+            print_liste_field_titre('');
524
+        }
525
+        else
526
+        {
527
+            print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder);
528
+        }
529
+        print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"mc.statut",$param,'','align="right"',$sortfield,$sortorder);
530
+        print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
531
+        print '</tr>';
532
+
533
+        $i = 0;
534
+
535
+        if ($num)
536
+        {
537
+            while ($i < min($num,$limit))
538
+            {
539
+                $obj = $db->fetch_object($resql);
540
+
541
+                print '<tr class="oddeven">';
542
+                print '<td>'.$obj->email.'</td>';
543
+                print '<td>'.$obj->lastname.'</td>';
544
+                print '<td>'.$obj->firstname.'</td>';
545
+                print '<td>'.$obj->other.'</td>';
546
+                print '<td align="center">';
547 547
                 if (empty($obj->source_id) || empty($obj->source_type))
548 548
                 {
549 549
                     print empty($obj->source_url)?'':$obj->source_url; // For backward compatibility
@@ -554,14 +554,14 @@  discard block
 block discarded – undo
554 554
                     {
555 555
                         include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
556 556
                         $objectstatic=new Adherent($db);
557
-						$objectstatic->fetch($obj->source_id);
557
+                        $objectstatic->fetch($obj->source_id);
558 558
                         print $objectstatic->getNomUrl(1);
559 559
                     }
560 560
                     else if ($obj->source_type == 'user')
561 561
                     {
562 562
                         include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
563 563
                         $objectstatic=new User($db);
564
-						$objectstatic->fetch($obj->source_id);
564
+                        $objectstatic->fetch($obj->source_id);
565 565
                         $objectstatic->id=$obj->source_id;
566 566
                         print $objectstatic->getNomUrl(1);
567 567
                     }
@@ -569,78 +569,78 @@  discard block
 block discarded – undo
569 569
                     {
570 570
                         include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
571 571
                         $objectstatic=new Societe($db);
572
-						$objectstatic->fetch($obj->source_id);
572
+                        $objectstatic->fetch($obj->source_id);
573 573
                         print $objectstatic->getNomUrl(1);
574 574
                     }
575 575
                     else if ($obj->source_type == 'contact')
576 576
                     {
577
-                    	include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
578
-                    	$objectstatic=new Contact($db);
579
-                    	$objectstatic->fetch($obj->source_id);
580
-                    	print $objectstatic->getNomUrl(1);
577
+                        include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
578
+                        $objectstatic=new Contact($db);
579
+                        $objectstatic->fetch($obj->source_id);
580
+                        print $objectstatic->getNomUrl(1);
581 581
                     }
582 582
                     else
583 583
                     {
584 584
                         print $obj->source_url;
585 585
                     }
586 586
                 }
587
-				print '</td>';
587
+                print '</td>';
588 588
 
589
-				// Status of recipient sending email (Warning != status of emailing)
590
-				if ($obj->statut == 0)
591
-				{
592
-					print '<td align="center">&nbsp;</td>';
593
-					print '<td align="right" class="nowrap">'.$langs->trans("MailingStatusNotSent");
594
-					print '</td>';
595
-				}
596
-				else
597
-				{
598
-					print '<td align="center">'.$obj->date_envoi.'</td>';
599
-					print '<td align="right" class="nowrap">';
600
-					print $object::libStatutDest($obj->statut, 2, $obj->error_text);
601
-					print '</td>';
602
-				}
603
-
604
-				// Search Icon
605
-				print '<td align="right">';
606
-				if ($obj->statut == 0)	// Not sent yet
607
-				{
608
-					if ($user->rights->mailing->creer && $allowaddtarget) {
609
-						print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&rowid='.$obj->rowid.$param.'">'.img_delete($langs->trans("RemoveRecipient")).'</a>';
610
-					}
611
-				}
612
-				/*if ($obj->statut == -1)	// Sent with error
589
+                // Status of recipient sending email (Warning != status of emailing)
590
+                if ($obj->statut == 0)
591
+                {
592
+                    print '<td align="center">&nbsp;</td>';
593
+                    print '<td align="right" class="nowrap">'.$langs->trans("MailingStatusNotSent");
594
+                    print '</td>';
595
+                }
596
+                else
597
+                {
598
+                    print '<td align="center">'.$obj->date_envoi.'</td>';
599
+                    print '<td align="right" class="nowrap">';
600
+                    print $object::libStatutDest($obj->statut, 2, $obj->error_text);
601
+                    print '</td>';
602
+                }
603
+
604
+                // Search Icon
605
+                print '<td align="right">';
606
+                if ($obj->statut == 0)	// Not sent yet
607
+                {
608
+                    if ($user->rights->mailing->creer && $allowaddtarget) {
609
+                        print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&rowid='.$obj->rowid.$param.'">'.img_delete($langs->trans("RemoveRecipient")).'</a>';
610
+                    }
611
+                }
612
+                /*if ($obj->statut == -1)	// Sent with error
613 613
 				{
614 614
 					print '<a href="'.$_SERVER['PHP_SELF'].'?action=retry&rowid='.$obj->rowid.$param.'">'.$langs->trans("Retry").'</a>';
615 615
 				}*/
616
-				print '</td>';
617
-				print '</tr>';
618
-
619
-				$i++;
620
-			}
621
-		}
622
-		else
623
-		{
624
-			if ($object->statut < 2)
625
-			{
626
-			    print '<tr><td colspan="8" class="opacitymedium">';
627
-    			print $langs->trans("NoTargetYet");
628
-    			print '</td></tr>';
629
-			}
630
-		}
631
-		print "</table><br>";
632
-		print '</div>';
633
-
634
-		print '</form>';
635
-
636
-		$db->free($resql);
637
-	}
638
-	else
639
-	{
640
-		dol_print_error($db);
641
-	}
642
-
643
-	print "\n<!-- Fin liste destinataires selectionnes -->\n";
616
+                print '</td>';
617
+                print '</tr>';
618
+
619
+                $i++;
620
+            }
621
+        }
622
+        else
623
+        {
624
+            if ($object->statut < 2)
625
+            {
626
+                print '<tr><td colspan="8" class="opacitymedium">';
627
+                print $langs->trans("NoTargetYet");
628
+                print '</td></tr>';
629
+            }
630
+        }
631
+        print "</table><br>";
632
+        print '</div>';
633
+
634
+        print '</form>';
635
+
636
+        $db->free($resql);
637
+    }
638
+    else
639
+    {
640
+        dol_print_error($db);
641
+    }
642
+
643
+    print "\n<!-- Fin liste destinataires selectionnes -->\n";
644 644
 }
645 645
 
646 646
 // End of page
Please login to merge, or discard this patch.
Braces   +91 added lines, -61 removed lines patch added patch discarded remove patch
@@ -36,7 +36,9 @@  discard block
 block discarded – undo
36 36
 $langs->load("mails");
37 37
 
38 38
 // Security check
39
-if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden();
39
+if (! $user->rights->mailing->lire || $user->societe_id > 0) {
40
+    accessforbidden();
41
+}
40 42
 
41 43
 
42 44
 // Load variable for pagination
@@ -48,8 +50,12 @@  discard block
 block discarded – undo
48 50
 $offset = $limit * $page;
49 51
 $pageprev = $page - 1;
50 52
 $pagenext = $page + 1;
51
-if (! $sortfield) $sortfield="email";
52
-if (! $sortorder) $sortorder="ASC";
53
+if (! $sortfield) {
54
+    $sortfield="email";
55
+}
56
+if (! $sortorder) {
57
+    $sortorder="ASC";
58
+}
53 59
 
54 60
 $id=GETPOST('id','int');
55 61
 $rowid=GETPOST('rowid','int');
@@ -137,23 +143,23 @@  discard block
 block discarded – undo
137 143
 
138 144
 			header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
139 145
 			exit;
140
-		}
141
-		else
146
+		} else
142 147
 		{
143 148
 			header("Location: list.php");
144 149
 			exit;
145 150
 		}
146
-	}
147
-	else
151
+	} else
148 152
 	{
149 153
 		dol_print_error($db);
150 154
 	}
151 155
 }
152 156
 
153 157
 // Purge search criteria
154
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
158
+if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) {
159
+    // All tests are required to be compatible with all browsers
155 160
 {
156 161
 	$search_lastname='';
162
+}
157 163
 	$search_firstname='';
158 164
 	$search_email='';
159 165
 	$search_other='';
@@ -187,7 +193,9 @@  discard block
 block discarded – undo
187 193
 		$nbko  = $object->countNbOfTargets('alreadysentko');
188 194
 
189 195
 		$morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
190
-		if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
196
+		if ($nbko) {
197
+		    $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
198
+		}
191 199
 		$morehtmlright.=') &nbsp; ';
192 200
 	}
193 201
 
@@ -219,18 +227,18 @@  discard block
 block discarded – undo
219 227
 			if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
220 228
 			{
221 229
 				$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
222
-			}
223
-			else
230
+			} else
224 231
 			{
225 232
 				$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
226 233
 			}
227 234
 		}
228
-		if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
235
+		if (empty($nbemail)) {
236
+		    $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
237
+		}
229 238
 		if ($text)
230 239
 		{
231 240
 			print $form->textwithpicto($nbemail,$text,1,'warning');
232
-		}
233
-		else
241
+		} else
234 242
 		{
235 243
 			print $nbemail;
236 244
 		}
@@ -287,7 +295,9 @@  discard block
 block discarded – undo
287 295
 					{
288 296
 						if (preg_match("/(.*)\.modules\.php$/i",$file,$reg))
289 297
 						{
290
-							if ($reg[1] == 'example') continue;
298
+							if ($reg[1] == 'example') {
299
+							    continue;
300
+							}
291 301
 							$modulenames[]=$reg[1];
292 302
 						}
293 303
 					}
@@ -331,14 +341,15 @@  discard block
 block discarded – undo
331 341
 					{
332 342
 						print '<form '.$bctag[$var].' name="'.$modulename.'" action="'.$_SERVER['PHP_SELF'].'?action=add&id='.$object->id.'&module='.$modulename.'" method="POST" enctype="multipart/form-data">';
333 343
 						print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
334
-					}
335
-					else
344
+					} else
336 345
 					{
337 346
 					    print '<div '.$bctag[$var].'>';
338 347
 					}
339 348
 
340 349
 					print '<div class="tagtd">';
341
-					if (empty($obj->picto)) $obj->picto='generic';
350
+					if (empty($obj->picto)) {
351
+					    $obj->picto='generic';
352
+					}
342 353
 					print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj),$obj->picto);
343 354
 					print ' ';
344 355
 					print $obj->getDesc();
@@ -346,8 +357,7 @@  discard block
 block discarded – undo
346 357
 
347 358
 					try {
348 359
 						$nbofrecipient=$obj->getNbOfRecipients('');
349
-					}
350
-					catch(Exception $e)
360
+					} catch(Exception $e)
351 361
 					{
352 362
 						dol_syslog($e->getMessage(), LOG_ERR);
353 363
 					}
@@ -356,8 +366,7 @@  discard block
 block discarded – undo
356 366
 					if ($nbofrecipient >= 0)
357 367
 					{
358 368
 						print $nbofrecipient;
359
-					}
360
-					else
369
+					} else
361 370
 					{
362 371
 						print $langs->trans("Error").' '.img_error($obj->error);
363 372
 					}
@@ -368,13 +377,15 @@  discard block
 block discarded – undo
368 377
 					{
369 378
     					try {
370 379
     						$filter=$obj->formFilter();
371
-    					}
372
-    					catch(Exception $e)
380
+    					} catch(Exception $e)
373 381
     					{
374 382
     						dol_syslog($e->getMessage(), LOG_ERR);
375 383
     					}
376
-    					if ($filter) print $filter;
377
-    					else print $langs->trans("None");
384
+    					if ($filter) {
385
+    					    print $filter;
386
+    					} else {
387
+    					    print $langs->trans("None");
388
+    					}
378 389
 					}
379 390
 					print '</div>';
380 391
 
@@ -382,8 +393,7 @@  discard block
 block discarded – undo
382 393
 					if ($allowaddtarget)
383 394
 					{
384 395
 						print '<input type="submit" class="button" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
385
-					}
386
-					else
396
+					} else
387 397
 					{
388 398
 					    print '<input type="submit" class="button disabled" disabled="disabled" name="button_'.$modulename.'" value="'.$langs->trans("Add").'">';
389 399
 						//print $langs->trans("MailNoChangePossible");
@@ -391,8 +401,11 @@  discard block
 block discarded – undo
391 401
 					}
392 402
 					print '</div>';
393 403
 
394
-					if ($allowaddtarget) print '</form>';
395
-					else print '</div>';
404
+					if ($allowaddtarget) {
405
+					    print '</form>';
406
+					} else {
407
+					    print '</div>';
408
+					}
396 409
 				}
397 410
 			}
398 411
 		}	// End foreach dir
@@ -406,11 +419,21 @@  discard block
 block discarded – undo
406 419
 	$sql  = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.source_url, mc.source_id, mc.source_type, mc.error_text";
407 420
 	$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
408 421
 	$sql .= " WHERE mc.fk_mailing=".$object->id;
409
-	if ($search_lastname)  $sql.= natural_search("mc.lastname", $search_lastname);
410
-	if ($search_firstname) $sql.= natural_search("mc.firstname", $search_firstname);
411
-	if ($search_email)     $sql.= natural_search("mc.email", $search_email);
412
-	if ($search_other)     $sql.= natural_search("mc.other", $search_other);
413
-	if ($search_dest_status != '' && $search_dest_status >= -1) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." ";
422
+	if ($search_lastname) {
423
+	    $sql.= natural_search("mc.lastname", $search_lastname);
424
+	}
425
+	if ($search_firstname) {
426
+	    $sql.= natural_search("mc.firstname", $search_firstname);
427
+	}
428
+	if ($search_email) {
429
+	    $sql.= natural_search("mc.email", $search_email);
430
+	}
431
+	if ($search_other) {
432
+	    $sql.= natural_search("mc.other", $search_other);
433
+	}
434
+	if ($search_dest_status != '' && $search_dest_status >= -1) {
435
+	    $sql.= " AND mc.statut=".$db->escape($search_dest_status)." ";
436
+	}
414 437
 	$sql .= $db->order($sortfield,$sortorder);
415 438
 
416 439
 	// Count total nb of records
@@ -419,9 +442,11 @@  discard block
 block discarded – undo
419 442
 	{
420 443
 	    $result = $db->query($sql);
421 444
 	    $nbtotalofrecords = $db->num_rows($result);
422
-	    if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
445
+	    if (($page * $limit) > $nbtotalofrecords) {
446
+	        // if total resultset is smaller then paging size (filtering), goto and load page 0
423 447
 	    {
424 448
 	    	$page = 0;
449
+	    }
425 450
 	    	$offset = 0;
426 451
 	    }
427 452
 	}
@@ -437,11 +462,21 @@  discard block
 block discarded – undo
437 462
 
438 463
 		$param = "&amp;id=".$object->id;
439 464
 		//if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
440
-		if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
441
-		if ($search_lastname)  $param.= "&amp;search_lastname=".urlencode($search_lastname);
442
-		if ($search_firstname) $param.= "&amp;search_firstname=".urlencode($search_firstname);
443
-		if ($search_email)     $param.= "&amp;search_email=".urlencode($search_email);
444
-		if ($search_other)     $param.= "&amp;search_other=".urlencode($search_other);
465
+		if ($limit > 0 && $limit != $conf->liste_limit) {
466
+		    $param.='&limit='.urlencode($limit);
467
+		}
468
+		if ($search_lastname) {
469
+		    $param.= "&amp;search_lastname=".urlencode($search_lastname);
470
+		}
471
+		if ($search_firstname) {
472
+		    $param.= "&amp;search_firstname=".urlencode($search_firstname);
473
+		}
474
+		if ($search_email) {
475
+		    $param.= "&amp;search_email=".urlencode($search_email);
476
+		}
477
+		if ($search_other) {
478
+		    $param.= "&amp;search_other=".urlencode($search_other);
479
+		}
445 480
 
446 481
 		print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
447 482
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -468,7 +503,9 @@  discard block
 block discarded – undo
468 503
 		print '<input type="hidden" name="limit" value="'.$limit.'">';
469 504
 
470 505
 
471
-		if ($page)	$param.= "&amp;page=".$page;
506
+		if ($page) {
507
+		    $param.= "&amp;page=".$page;
508
+		}
472 509
 
473 510
 		print '<div class="div-table-responsive">';
474 511
 		print '<table class="noborder" width="100%">';
@@ -521,8 +558,7 @@  discard block
 block discarded – undo
521 558
 		if ($object->statut < 2)
522 559
 		{
523 560
 			print_liste_field_titre('');
524
-		}
525
-		else
561
+		} else
526 562
 		{
527 563
 			print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder);
528 564
 		}
@@ -547,8 +583,7 @@  discard block
 block discarded – undo
547 583
                 if (empty($obj->source_id) || empty($obj->source_type))
548 584
                 {
549 585
                     print empty($obj->source_url)?'':$obj->source_url; // For backward compatibility
550
-                }
551
-                else
586
+                } else
552 587
                 {
553 588
                     if ($obj->source_type == 'member')
554 589
                     {
@@ -556,30 +591,26 @@  discard block
 block discarded – undo
556 591
                         $objectstatic=new Adherent($db);
557 592
 						$objectstatic->fetch($obj->source_id);
558 593
                         print $objectstatic->getNomUrl(1);
559
-                    }
560
-                    else if ($obj->source_type == 'user')
594
+                    } else if ($obj->source_type == 'user')
561 595
                     {
562 596
                         include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
563 597
                         $objectstatic=new User($db);
564 598
 						$objectstatic->fetch($obj->source_id);
565 599
                         $objectstatic->id=$obj->source_id;
566 600
                         print $objectstatic->getNomUrl(1);
567
-                    }
568
-                    else if ($obj->source_type == 'thirdparty')
601
+                    } else if ($obj->source_type == 'thirdparty')
569 602
                     {
570 603
                         include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
571 604
                         $objectstatic=new Societe($db);
572 605
 						$objectstatic->fetch($obj->source_id);
573 606
                         print $objectstatic->getNomUrl(1);
574
-                    }
575
-                    else if ($obj->source_type == 'contact')
607
+                    } else if ($obj->source_type == 'contact')
576 608
                     {
577 609
                     	include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
578 610
                     	$objectstatic=new Contact($db);
579 611
                     	$objectstatic->fetch($obj->source_id);
580 612
                     	print $objectstatic->getNomUrl(1);
581
-                    }
582
-                    else
613
+                    } else
583 614
                     {
584 615
                         print $obj->source_url;
585 616
                     }
@@ -592,8 +623,7 @@  discard block
 block discarded – undo
592 623
 					print '<td align="center">&nbsp;</td>';
593 624
 					print '<td align="right" class="nowrap">'.$langs->trans("MailingStatusNotSent");
594 625
 					print '</td>';
595
-				}
596
-				else
626
+				} else
597 627
 				{
598 628
 					print '<td align="center">'.$obj->date_envoi.'</td>';
599 629
 					print '<td align="right" class="nowrap">';
@@ -603,10 +633,12 @@  discard block
 block discarded – undo
603 633
 
604 634
 				// Search Icon
605 635
 				print '<td align="right">';
606
-				if ($obj->statut == 0)	// Not sent yet
636
+				if ($obj->statut == 0) {
637
+				    // Not sent yet
607 638
 				{
608 639
 					if ($user->rights->mailing->creer && $allowaddtarget) {
609 640
 						print '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&rowid='.$obj->rowid.$param.'">'.img_delete($langs->trans("RemoveRecipient")).'</a>';
641
+				}
610 642
 					}
611 643
 				}
612 644
 				/*if ($obj->statut == -1)	// Sent with error
@@ -618,8 +650,7 @@  discard block
 block discarded – undo
618 650
 
619 651
 				$i++;
620 652
 			}
621
-		}
622
-		else
653
+		} else
623 654
 		{
624 655
 			if ($object->statut < 2)
625 656
 			{
@@ -634,8 +665,7 @@  discard block
 block discarded – undo
634 665
 		print '</form>';
635 666
 
636 667
 		$db->free($resql);
637
-	}
638
-	else
668
+	} else
639 669
 	{
640 670
 		dol_print_error($db);
641 671
 	}
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/modules/mailings/modules_mailings.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmailing.class.php';
@@ -39,29 +39,29 @@  discard block
 block discarded – undo
39 39
 $langs->load("mails");
40 40
 
41 41
 // Security check
42
-if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden();
42
+if (!$user->rights->mailing->lire || $user->societe_id > 0) accessforbidden();
43 43
 
44 44
 
45 45
 // Load variable for pagination
46
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
47
-$sortfield = GETPOST('sortfield','alpha');
48
-$sortorder = GETPOST('sortorder','alpha');
49
-$page = GETPOST('page','int');
46
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
47
+$sortfield = GETPOST('sortfield', 'alpha');
48
+$sortorder = GETPOST('sortorder', 'alpha');
49
+$page = GETPOST('page', 'int');
50 50
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
51 51
 $offset = $limit * $page;
52 52
 $pageprev = $page - 1;
53 53
 $pagenext = $page + 1;
54
-if (! $sortfield) $sortfield="email";
55
-if (! $sortorder) $sortorder="ASC";
56
-
57
-$id=GETPOST('id','int');
58
-$rowid=GETPOST('rowid','int');
59
-$action=GETPOST('action','aZ09');
60
-$search_lastname=GETPOST("search_lastname");
61
-$search_firstname=GETPOST("search_firstname");
62
-$search_email=GETPOST("search_email");
63
-$search_other=GETPOST("search_other");
64
-$search_dest_status=GETPOST('search_dest_status');
54
+if (!$sortfield) $sortfield = "email";
55
+if (!$sortorder) $sortorder = "ASC";
56
+
57
+$id = GETPOST('id', 'int');
58
+$rowid = GETPOST('rowid', 'int');
59
+$action = GETPOST('action', 'aZ09');
60
+$search_lastname = GETPOST("search_lastname");
61
+$search_firstname = GETPOST("search_firstname");
62
+$search_email = GETPOST("search_email");
63
+$search_other = GETPOST("search_other");
64
+$search_dest_status = GETPOST('search_dest_status');
65 65
 
66 66
 // Search modules dirs
67 67
 $modulesdir = dolGetModulesDirs('/mailings');
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 
76 76
 if ($action == 'add')
77 77
 {
78
-	$module=GETPOST("module",'alpha');
79
-	$result=-1;
78
+	$module = GETPOST("module", 'alpha');
79
+	$result = -1;
80 80
 
81 81
 	foreach ($modulesdir as $dir)
82 82
 	{
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
 			// Add targets into database
96 96
 			$obj = new $classname($db);
97 97
 			dol_syslog("Call add_to_target on class ".$classname);
98
-			$result=$obj->add_to_target($id);
98
+			$result = $obj->add_to_target($id);
99 99
 		}
100 100
 	}
101 101
 	if ($result > 0)
102 102
 	{
103
-		setEventMessages($langs->trans("XTargetsAdded",$result), null, 'mesgs');
103
+		setEventMessages($langs->trans("XTargetsAdded", $result), null, 'mesgs');
104 104
 
105 105
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
106 106
 		exit;
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	}
112 112
 	if ($result < 0)
113 113
 	{
114
-		setEventMessages($langs->trans("Error").($obj->error?' '.$obj->error:''), null, 'errors');
114
+		setEventMessages($langs->trans("Error").($obj->error ? ' '.$obj->error : ''), null, 'errors');
115 115
 	}
116 116
 }
117 117
 
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 if ($action == 'delete')
130 130
 {
131 131
 	// Ici, rowid indique le destinataire et id le mailing
132
-	$sql="DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$rowid;
133
-	$resql=$db->query($sql);
132
+	$sql = "DELETE FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE rowid=".$rowid;
133
+	$resql = $db->query($sql);
134 134
 	if ($resql)
135 135
 	{
136 136
 		if (!empty($id))
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 }
155 155
 
156 156
 // Purge search criteria
157
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
157
+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
158 158
 {
159
-	$search_lastname='';
160
-	$search_firstname='';
161
-	$search_email='';
162
-	$search_other='';
163
-	$search_dest_status='';
159
+	$search_lastname = '';
160
+	$search_firstname = '';
161
+	$search_email = '';
162
+	$search_other = '';
163
+	$search_dest_status = '';
164 164
 }
165 165
 
166 166
 
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
  * View
170 170
  */
171 171
 
172
-llxHeader('',$langs->trans("Mailing"),'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
172
+llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
173 173
 
174 174
 $form = new Form($db);
175 175
 $formmailing = new FormMailing($db);
@@ -182,16 +182,16 @@  discard block
 block discarded – undo
182 182
 
183 183
 	$linkback = '<a href="'.DOL_URL_ROOT.'/comm/mailing/list.php">'.$langs->trans("BackToList").'</a>';
184 184
 
185
-	$morehtmlright='';
185
+	$morehtmlright = '';
186 186
 	$nbtry = $nbok = 0;
187 187
 	if ($object->statut == 2 || $object->statut == 3)
188 188
 	{
189 189
 		$nbtry = $object->countNbOfTargets('alreadysent');
190 190
 		$nbko  = $object->countNbOfTargets('alreadysentko');
191 191
 
192
-		$morehtmlright.=' ('.$nbtry.'/'.$object->nbemail;
193
-		if ($nbko) $morehtmlright.=' - '.$nbko.' '.$langs->trans("Error");
194
-		$morehtmlright.=') &nbsp; ';
192
+		$morehtmlright .= ' ('.$nbtry.'/'.$object->nbemail;
193
+		if ($nbko) $morehtmlright .= ' - '.$nbko.' '.$langs->trans("Error");
194
+		$morehtmlright .= ') &nbsp; ';
195 195
 	}
196 196
 
197 197
 	dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright);
@@ -203,35 +203,35 @@  discard block
 block discarded – undo
203 203
 
204 204
 	print '<tr><td class="titlefield">'.$langs->trans("MailTitle").'</td><td colspan="3">'.$object->titre.'</td></tr>';
205 205
 
206
-	print '<tr><td>'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from,0,0,0,0,1).'</td></tr>';
206
+	print '<tr><td>'.$langs->trans("MailFrom").'</td><td colspan="3">'.dol_print_email($object->email_from, 0, 0, 0, 0, 1).'</td></tr>';
207 207
 
208 208
 	// Errors to
209
-	print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto,0,0,0,0,1);
209
+	print '<tr><td>'.$langs->trans("MailErrorsTo").'</td><td colspan="3">'.dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1);
210 210
 	print '</td></tr>';
211 211
 
212 212
 	// Nb of distinct emails
213 213
 	print '<tr><td>';
214 214
 	print $langs->trans("TotalNbOfDistinctRecipients");
215 215
 	print '</td><td colspan="3">';
216
-	$nbemail = ($object->nbemail?$object->nbemail:0);
216
+	$nbemail = ($object->nbemail ? $object->nbemail : 0);
217 217
 	if (is_numeric($nbemail))
218 218
 	{
219
-		$text='';
220
-		if ((! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
219
+		$text = '';
220
+		if ((!empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) && ($object->statut == 1 || ($object->statut == 2 && $nbtry < $nbemail)))
221 221
 		{
222 222
 			if ($conf->global->MAILING_LIMIT_SENDBYWEB > 0)
223 223
 			{
224
-				$text.=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
224
+				$text .= $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB);
225 225
 			}
226 226
 			else
227 227
 			{
228
-				$text.=$langs->trans('SendingFromWebInterfaceIsNotAllowed');
228
+				$text .= $langs->trans('SendingFromWebInterfaceIsNotAllowed');
229 229
 			}
230 230
 		}
231
-		if (empty($nbemail)) $nbemail.=' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
231
+		if (empty($nbemail)) $nbemail .= ' '.img_warning('').' <font class="warning">'.$langs->trans("NoTargetYet").'</font>';
232 232
 		if ($text)
233 233
 		{
234
-			print $form->textwithpicto($nbemail,$text,1,'warning');
234
+			print $form->textwithpicto($nbemail, $text, 1, 'warning');
235 235
 		}
236 236
 		else
237 237
 		{
@@ -249,12 +249,12 @@  discard block
 block discarded – undo
249 249
 	print '<br>';
250 250
 
251 251
 
252
-	$allowaddtarget=($object->statut == 0);
252
+	$allowaddtarget = ($object->statut == 0);
253 253
 
254 254
 	// Show email selectors
255 255
 	if ($allowaddtarget && $user->rights->mailing->creer)
256 256
 	{
257
-		print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"),1):''), 'title_generic');
257
+		print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin ?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"), 1) : ''), 'title_generic');
258 258
 
259 259
 		//print '<table class="noborder" width="100%">';
260 260
 		print '<div class="tagtable centpercent liste_titre_bydiv borderbottom" id="tablelines">';
@@ -276,22 +276,22 @@  discard block
 block discarded – undo
276 276
 
277 277
 		foreach ($modulesdir as $dir)
278 278
 		{
279
-		    $modulenames=array();
279
+		    $modulenames = array();
280 280
 
281 281
 		    // Load modules attributes in arrays (name, numero, orders) from dir directory
282 282
 		    //print $dir."\n<br>";
283 283
 		    dol_syslog("Scan directory ".$dir." for modules");
284
-		    $handle=@opendir($dir);
284
+		    $handle = @opendir($dir);
285 285
 			if (is_resource($handle))
286 286
 			{
287
-				while (($file = readdir($handle))!==false)
287
+				while (($file = readdir($handle)) !== false)
288 288
 				{
289 289
 					if (substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS')
290 290
 					{
291
-						if (preg_match("/(.*)\.modules\.php$/i",$file,$reg))
291
+						if (preg_match("/(.*)\.modules\.php$/i", $file, $reg))
292 292
 						{
293 293
 							if ($reg[1] == 'example') continue;
294
-							$modulenames[]=$reg[1];
294
+							$modulenames[] = $reg[1];
295 295
 						}
296 296
 					}
297 297
 				}
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 			$var = true;
305 305
 
306 306
 			// Loop on each submodule
307
-			foreach($modulenames as $modulename)
307
+			foreach ($modulenames as $modulename)
308 308
 			{
309 309
 				// Loading Class
310 310
 				$file = $dir.$modulename.".modules.php";
@@ -314,12 +314,12 @@  discard block
 block discarded – undo
314 314
 				$obj = new $classname($db);
315 315
 
316 316
 				// Check dependencies
317
-				$qualified=(isset($obj->enabled)?$obj->enabled:1);
317
+				$qualified = (isset($obj->enabled) ? $obj->enabled : 1);
318 318
 				foreach ($obj->require_module as $key)
319 319
 				{
320
-					if (! $conf->$key->enabled || (! $user->admin && $obj->require_admin))
320
+					if (!$conf->$key->enabled || (!$user->admin && $obj->require_admin))
321 321
 					{
322
-						$qualified=0;
322
+						$qualified = 0;
323 323
 						//print "Les prerequis d'activation du module mailing ne sont pas respectes. Il ne sera pas actif";
324 324
 						break;
325 325
 					}
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 				// Si le module mailing est qualifie
329 329
 				if ($qualified)
330 330
 				{
331
-					$var = ! $var;
331
+					$var = !$var;
332 332
 
333 333
 					if ($allowaddtarget)
334 334
 					{
@@ -341,16 +341,16 @@  discard block
 block discarded – undo
341 341
 					}
342 342
 
343 343
 					print '<div class="tagtd">';
344
-					if (empty($obj->picto)) $obj->picto='generic';
345
-					print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj),$obj->picto);
344
+					if (empty($obj->picto)) $obj->picto = 'generic';
345
+					print img_object($langs->trans("EmailingTargetSelector").': '.get_class($obj), $obj->picto);
346 346
 					print ' ';
347 347
 					print $obj->getDesc();
348 348
 					print '</div>';
349 349
 
350 350
 					try {
351
-						$nbofrecipient=$obj->getNbOfRecipients('');
351
+						$nbofrecipient = $obj->getNbOfRecipients('');
352 352
 					}
353
-					catch(Exception $e)
353
+					catch (Exception $e)
354 354
 					{
355 355
 						dol_syslog($e->getMessage(), LOG_ERR);
356 356
 					}
@@ -370,9 +370,9 @@  discard block
 block discarded – undo
370 370
 					if ($allowaddtarget)
371 371
 					{
372 372
     					try {
373
-    						$filter=$obj->formFilter();
373
+    						$filter = $obj->formFilter();
374 374
     					}
375
-    					catch(Exception $e)
375
+    					catch (Exception $e)
376 376
     					{
377 377
     						dol_syslog($e->getMessage(), LOG_ERR);
378 378
     					}
@@ -409,12 +409,12 @@  discard block
 block discarded – undo
409 409
 	$sql  = "SELECT mc.rowid, mc.lastname, mc.firstname, mc.email, mc.other, mc.statut, mc.date_envoi, mc.source_url, mc.source_id, mc.source_type, mc.error_text";
410 410
 	$sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc";
411 411
 	$sql .= " WHERE mc.fk_mailing=".$object->id;
412
-	if ($search_lastname)  $sql.= natural_search("mc.lastname", $search_lastname);
413
-	if ($search_firstname) $sql.= natural_search("mc.firstname", $search_firstname);
414
-	if ($search_email)     $sql.= natural_search("mc.email", $search_email);
415
-	if ($search_other)     $sql.= natural_search("mc.other", $search_other);
416
-	if ($search_dest_status != '' && $search_dest_status >= -1) $sql.= " AND mc.statut=".$db->escape($search_dest_status)." ";
417
-	$sql .= $db->order($sortfield,$sortorder);
412
+	if ($search_lastname)  $sql .= natural_search("mc.lastname", $search_lastname);
413
+	if ($search_firstname) $sql .= natural_search("mc.firstname", $search_firstname);
414
+	if ($search_email)     $sql .= natural_search("mc.email", $search_email);
415
+	if ($search_other)     $sql .= natural_search("mc.other", $search_other);
416
+	if ($search_dest_status != '' && $search_dest_status >= -1) $sql .= " AND mc.statut=".$db->escape($search_dest_status)." ";
417
+	$sql .= $db->order($sortfield, $sortorder);
418 418
 
419 419
 	// Count total nb of records
420 420
 	$nbtotalofrecords = '';
@@ -430,9 +430,9 @@  discard block
 block discarded – undo
430 430
 	}
431 431
 
432 432
 	//$nbtotalofrecords=$object->nbemail;     // nbemail is a denormalized field storing nb of targets
433
-	$sql .= $db->plimit($limit+1, $offset);
433
+	$sql .= $db->plimit($limit + 1, $offset);
434 434
 
435
-	$resql=$db->query($sql);
435
+	$resql = $db->query($sql);
436 436
 	if ($resql)
437 437
 	{
438 438
 
@@ -440,11 +440,11 @@  discard block
 block discarded – undo
440 440
 
441 441
 		$param = "&amp;id=".$object->id;
442 442
 		//if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
443
-		if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
444
-		if ($search_lastname)  $param.= "&amp;search_lastname=".urlencode($search_lastname);
445
-		if ($search_firstname) $param.= "&amp;search_firstname=".urlencode($search_firstname);
446
-		if ($search_email)     $param.= "&amp;search_email=".urlencode($search_email);
447
-		if ($search_other)     $param.= "&amp;search_other=".urlencode($search_other);
443
+		if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
444
+		if ($search_lastname)  $param .= "&amp;search_lastname=".urlencode($search_lastname);
445
+		if ($search_firstname) $param .= "&amp;search_firstname=".urlencode($search_firstname);
446
+		if ($search_email)     $param .= "&amp;search_email=".urlencode($search_email);
447
+		if ($search_other)     $param .= "&amp;search_other=".urlencode($search_other);
448 448
 
449 449
 		print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
450 450
 		print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -453,11 +453,11 @@  discard block
 block discarded – undo
453 453
         print '<input type="hidden" name="page" value="'.$page.'">';
454 454
 		print '<input type="hidden" name="id" value="'.$object->id.'">';
455 455
 
456
-		$cleartext='';
456
+		$cleartext = '';
457 457
 		if ($allowaddtarget) {
458
-		    $cleartext=$langs->trans("ToClearAllRecipientsClickHere").' '.'<a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition">'.$langs->trans("TargetsReset").'</a>';
458
+		    $cleartext = $langs->trans("ToClearAllRecipientsClickHere").' '.'<a href="'.$_SERVER["PHP_SELF"].'?clearlist=1&id='.$object->id.'" class="button reposition">'.$langs->trans("TargetsReset").'</a>';
459 459
 		}
460
-		print_barre_liste($langs->trans("MailSelectedRecipients"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$cleartext,$num,$nbtotalofrecords,'title_generic',0,'','', $limit);
460
+		print_barre_liste($langs->trans("MailSelectedRecipients"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $cleartext, $num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit);
461 461
 
462 462
 		print '</form>';
463 463
 
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
 		print '<input type="hidden" name="limit" value="'.$limit.'">';
472 472
 
473 473
 
474
-		if ($page)	$param.= "&amp;page=".$page;
474
+		if ($page)	$param .= "&amp;page=".$page;
475 475
 
476 476
 		print '<div class="div-table-responsive">';
477 477
 		print '<table class="noborder" width="100%">';
@@ -505,21 +505,21 @@  discard block
 block discarded – undo
505 505
 		print '</td>';
506 506
 		//Statut
507 507
 		print '<td class="liste_titre" align="right">';
508
-		print $formmailing->selectDestinariesStatus($search_dest_status,'search_dest_status',1);
508
+		print $formmailing->selectDestinariesStatus($search_dest_status, 'search_dest_status', 1);
509 509
 		print '</td>';
510 510
 		// Action column
511 511
 		print '<td class="liste_titre" align="right">';
512
-		$searchpicto=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1);
512
+		$searchpicto = $form->showFilterAndCheckAddButtons($massactionbutton ? 1 : 0, 'checkforselect', 1);
513 513
 		print $searchpicto;
514 514
 		print '</td>';
515 515
 		print '</tr>';
516 516
 
517 517
 		print '<tr class="liste_titre">';
518
-		print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"mc.email",$param,"","",$sortfield,$sortorder);
519
-		print_liste_field_titre("Lastname",$_SERVER["PHP_SELF"],"mc.lastname",$param,"","",$sortfield,$sortorder);
520
-		print_liste_field_titre("Firstname",$_SERVER["PHP_SELF"],"mc.firstname",$param,"","",$sortfield,$sortorder);
521
-		print_liste_field_titre("OtherInformations",$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder);
522
-		print_liste_field_titre("Source",$_SERVER["PHP_SELF"],"",$param,"",'align="center"',$sortfield,$sortorder);
518
+		print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "mc.email", $param, "", "", $sortfield, $sortorder);
519
+		print_liste_field_titre("Lastname", $_SERVER["PHP_SELF"], "mc.lastname", $param, "", "", $sortfield, $sortorder);
520
+		print_liste_field_titre("Firstname", $_SERVER["PHP_SELF"], "mc.firstname", $param, "", "", $sortfield, $sortorder);
521
+		print_liste_field_titre("OtherInformations", $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
522
+		print_liste_field_titre("Source", $_SERVER["PHP_SELF"], "", $param, "", 'align="center"', $sortfield, $sortorder);
523 523
 		// Date sending
524 524
 		if ($object->statut < 2)
525 525
 		{
@@ -527,17 +527,17 @@  discard block
 block discarded – undo
527 527
 		}
528 528
 		else
529 529
 		{
530
-			print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,'','align="center"',$sortfield,$sortorder);
530
+			print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, '', 'align="center"', $sortfield, $sortorder);
531 531
 		}
532
-		print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"mc.statut",$param,'','align="right"',$sortfield,$sortorder);
533
-		print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch ');
532
+		print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "mc.statut", $param, '', 'align="right"', $sortfield, $sortorder);
533
+		print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch ');
534 534
 		print '</tr>';
535 535
 
536 536
 		$i = 0;
537 537
 
538 538
 		if ($num)
539 539
 		{
540
-			while ($i < min($num,$limit))
540
+			while ($i < min($num, $limit))
541 541
 			{
542 542
 				$obj = $db->fetch_object($resql);
543 543
 
@@ -549,36 +549,36 @@  discard block
 block discarded – undo
549 549
 				print '<td align="center">';
550 550
                 if (empty($obj->source_id) || empty($obj->source_type))
551 551
                 {
552
-                    print empty($obj->source_url)?'':$obj->source_url; // For backward compatibility
552
+                    print empty($obj->source_url) ? '' : $obj->source_url; // For backward compatibility
553 553
                 }
554 554
                 else
555 555
                 {
556 556
                     if ($obj->source_type == 'member')
557 557
                     {
558 558
                         include_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
559
-                        $objectstatic=new Adherent($db);
559
+                        $objectstatic = new Adherent($db);
560 560
 						$objectstatic->fetch($obj->source_id);
561 561
                         print $objectstatic->getNomUrl(1);
562 562
                     }
563 563
                     else if ($obj->source_type == 'user')
564 564
                     {
565 565
                         include_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
566
-                        $objectstatic=new User($db);
566
+                        $objectstatic = new User($db);
567 567
 						$objectstatic->fetch($obj->source_id);
568
-                        $objectstatic->id=$obj->source_id;
568
+                        $objectstatic->id = $obj->source_id;
569 569
                         print $objectstatic->getNomUrl(1);
570 570
                     }
571 571
                     else if ($obj->source_type == 'thirdparty')
572 572
                     {
573 573
                         include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
574
-                        $objectstatic=new Societe($db);
574
+                        $objectstatic = new Societe($db);
575 575
 						$objectstatic->fetch($obj->source_id);
576 576
                         print $objectstatic->getNomUrl(1);
577 577
                     }
578 578
                     else if ($obj->source_type == 'contact')
579 579
                     {
580 580
                     	include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
581
-                    	$objectstatic=new Contact($db);
581
+                    	$objectstatic = new Contact($db);
582 582
                     	$objectstatic->fetch($obj->source_id);
583 583
                     	print $objectstatic->getNomUrl(1);
584 584
                     }
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/mailing/list.php 3 patches
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -77,29 +77,29 @@  discard block
 block discarded – undo
77 77
 
78 78
 if (empty($reshook))
79 79
 {
80
-	// Selection of new fields
81
-	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
80
+    // Selection of new fields
81
+    include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
82 82
 
83
-	// Purge search criteria
84
-	if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
85
-	{
86
-		/*foreach($object->fields as $key => $val)
83
+    // Purge search criteria
84
+    if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
85
+    {
86
+        /*foreach($object->fields as $key => $val)
87 87
 		{
88 88
 			$search[$key]='';
89 89
 		}*/
90
-		$search_ref = '';
91
-		$search_all = '';
92
-		$toselect='';
93
-		$search_array_options=array();
94
-	}
95
-	if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
96
-		|| GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
97
-	{
98
-		$massaction='';     // Protection to avoid mass action if we force a new search during a mass action confirmation
99
-	}
100
-
101
-	// Mass actions
102
-	/*$objectclass='MyObject';
90
+        $search_ref = '';
91
+        $search_all = '';
92
+        $toselect='';
93
+        $search_array_options=array();
94
+    }
95
+    if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
96
+        || GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
97
+    {
98
+        $massaction='';     // Protection to avoid mass action if we force a new search during a mass action confirmation
99
+    }
100
+
101
+    // Mass actions
102
+    /*$objectclass='MyObject';
103 103
 	$objectlabel='MyObject';
104 104
 	$permtoread = $user->rights->mymodule->read;
105 105
 	$permtodelete = $user->rights->mymodule->delete;
@@ -119,126 +119,126 @@  discard block
 block discarded – undo
119 119
 
120 120
 if ($filteremail)
121 121
 {
122
-	$sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
123
-	$sql.= " mc.statut as sendstatut";
124
-	$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
125
-	$sql.= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
126
-	$sql.= " AND mc.email = '".$db->escape($filteremail)."'";
127
-	if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
128
-	if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
129
-	if (! $sortorder) $sortorder="ASC";
130
-	if (! $sortfield) $sortfield="m.rowid";
131
-	$sql.= $db->order($sortfield,$sortorder);
132
-	$sql.= $db->plimit($conf->liste_limit +1, $offset);
122
+    $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
123
+    $sql.= " mc.statut as sendstatut";
124
+    $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
125
+    $sql.= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
126
+    $sql.= " AND mc.email = '".$db->escape($filteremail)."'";
127
+    if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
128
+    if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
129
+    if (! $sortorder) $sortorder="ASC";
130
+    if (! $sortfield) $sortfield="m.rowid";
131
+    $sql.= $db->order($sortfield,$sortorder);
132
+    $sql.= $db->plimit($conf->liste_limit +1, $offset);
133 133
 }
134 134
 else
135 135
 {
136
-	$sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
137
-	$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
138
-	$sql.= " WHERE m.entity = ".$conf->entity;
139
-	if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
140
-	if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
141
-	if (! $sortorder) $sortorder="ASC";
142
-	if (! $sortfield) $sortfield="m.rowid";
143
-	$sql.= $db->order($sortfield,$sortorder);
144
-	$sql.= $db->plimit($conf->liste_limit +1, $offset);
136
+    $sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
137
+    $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
138
+    $sql.= " WHERE m.entity = ".$conf->entity;
139
+    if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
140
+    if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
141
+    if (! $sortorder) $sortorder="ASC";
142
+    if (! $sortfield) $sortfield="m.rowid";
143
+    $sql.= $db->order($sortfield,$sortorder);
144
+    $sql.= $db->plimit($conf->liste_limit +1, $offset);
145 145
 }
146 146
 
147 147
 //print $sql;
148 148
 $result = $db->query($sql);
149 149
 if ($result)
150 150
 {
151
-	$num = $db->num_rows($result);
151
+    $num = $db->num_rows($result);
152 152
 
153
-	$title=$langs->trans("ListOfEMailings");
154
-	if ($filteremail) $title.=' ('.$langs->trans("SentTo",$filteremail).')';
153
+    $title=$langs->trans("ListOfEMailings");
154
+    if ($filteremail) $title.=' ('.$langs->trans("SentTo",$filteremail).')';
155 155
 
156
-	$newcardbutton='';
157
-	if ($user->rights->mailing->creer)
158
-	{
159
-		$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/mailing/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewMailing').'</span>';
160
-		$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
161
-		$newcardbutton.= '</a>';
162
-	}
156
+    $newcardbutton='';
157
+    if ($user->rights->mailing->creer)
158
+    {
159
+        $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/mailing/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewMailing').'</span>';
160
+        $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
161
+        $newcardbutton.= '</a>';
162
+    }
163 163
 
164
-	$i = 0;
164
+    $i = 0;
165 165
 
166
-	$param = "&search_all=".urlencode($search_all);
167
-	if ($filteremail) $param.='&filteremail='.urlencode($filteremail);
166
+    $param = "&search_all=".urlencode($search_all);
167
+    if ($filteremail) $param.='&filteremail='.urlencode($filteremail);
168 168
 
169
-	print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
170
-	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
171
-	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
172
-	print '<input type="hidden" name="action" value="list">';
173
-	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
174
-	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
175
-	print '<input type="hidden" name="page" value="'.$page.'">';
169
+    print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
170
+    if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
171
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
172
+    print '<input type="hidden" name="action" value="list">';
173
+    print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
174
+    print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
175
+    print '<input type="hidden" name="page" value="'.$page.'">';
176 176
 
177
-	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '',$num, '', 'title_generic.png', 0, $newcardbutton);
177
+    print_barre_liste($title, $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '',$num, '', 'title_generic.png', 0, $newcardbutton);
178 178
 
179
-	$moreforfilter = '';
179
+    $moreforfilter = '';
180 180
 
181 181
     print '<div class="div-table-responsive">';
182 182
     print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
183 183
 
184
-	print '<tr class="liste_titre_filter">';
185
-	print '<td class="liste_titre">';
186
-	print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
187
-	print '</td>';
188
-	// Title
189
-	print '<td class="liste_titre">';
190
-	print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
191
-	print '</td>';
192
-	print '<td class="liste_titre">&nbsp;</td>';
193
-	if (! $filteremail) print '<td class="liste_titre">&nbsp;</td>';
194
-	print '<td class="liste_titre">&nbsp;</td>';
195
-	print '<td class="liste_titre">&nbsp;</td>';
196
-	print '<td class="liste_titre" align="right">';
197
-	$searchpicto=$form->showFilterAndCheckAddButtons(0);
198
-	print $searchpicto;
199
-	print '</td>';
200
-	print "</tr>\n";
201
-
202
-	print '<tr class="liste_titre">';
203
-	print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"m.rowid",$param,"","",$sortfield,$sortorder);
204
-	print_liste_field_titre("Title",$_SERVER["PHP_SELF"],"m.titre",$param,"","",$sortfield,$sortorder);
205
-	print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"m.date_creat",$param,"",'align="center"',$sortfield,$sortorder);
206
-	if (! $filteremail) print_liste_field_titre("NbOfEMails",$_SERVER["PHP_SELF"],"m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
207
-	if (! $filteremail) print_liste_field_titre("DateLastSend",$_SERVER["PHP_SELF"],"m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
208
-	else print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
209
-	print_liste_field_titre("Status",$_SERVER["PHP_SELF"],($filteremail?"mc.statut":"m.statut"),$param,"",'align="right"',$sortfield,$sortorder);
210
-	print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
211
-	print "</tr>\n";
212
-
213
-
214
-	$email=new Mailing($db);
215
-
216
-	while ($i < min($num,$limit))
217
-	{
218
-		$obj = $db->fetch_object($result);
219
-
220
-		$email->id = $obj->rowid;
221
-		$email->ref = $obj->rowid;
222
-
223
-		print "<tr>";
224
-
225
-		print '<td>';
226
-		print $email->getNomUrl(1);
227
-		print '</td>';
228
-
229
-		print '<td>'.$obj->titre.'</td>';
230
-		// Date creation
231
-
232
-		print '<td align="center">';
233
-		print dol_print_date($db->jdate($obj->datec),'day');
234
-		print '</td>';
235
-
236
-		// Nb of email
237
-		if (! $filteremail)
238
-		{
239
-			print '<td align="center">';
240
-			$nbemail = $obj->nbemail;
241
-			/*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
184
+    print '<tr class="liste_titre_filter">';
185
+    print '<td class="liste_titre">';
186
+    print '<input type="text" class="flat maxwidth50" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
187
+    print '</td>';
188
+    // Title
189
+    print '<td class="liste_titre">';
190
+    print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
191
+    print '</td>';
192
+    print '<td class="liste_titre">&nbsp;</td>';
193
+    if (! $filteremail) print '<td class="liste_titre">&nbsp;</td>';
194
+    print '<td class="liste_titre">&nbsp;</td>';
195
+    print '<td class="liste_titre">&nbsp;</td>';
196
+    print '<td class="liste_titre" align="right">';
197
+    $searchpicto=$form->showFilterAndCheckAddButtons(0);
198
+    print $searchpicto;
199
+    print '</td>';
200
+    print "</tr>\n";
201
+
202
+    print '<tr class="liste_titre">';
203
+    print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"m.rowid",$param,"","",$sortfield,$sortorder);
204
+    print_liste_field_titre("Title",$_SERVER["PHP_SELF"],"m.titre",$param,"","",$sortfield,$sortorder);
205
+    print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"m.date_creat",$param,"",'align="center"',$sortfield,$sortorder);
206
+    if (! $filteremail) print_liste_field_titre("NbOfEMails",$_SERVER["PHP_SELF"],"m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
207
+    if (! $filteremail) print_liste_field_titre("DateLastSend",$_SERVER["PHP_SELF"],"m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
208
+    else print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
209
+    print_liste_field_titre("Status",$_SERVER["PHP_SELF"],($filteremail?"mc.statut":"m.statut"),$param,"",'align="right"',$sortfield,$sortorder);
210
+    print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
211
+    print "</tr>\n";
212
+
213
+
214
+    $email=new Mailing($db);
215
+
216
+    while ($i < min($num,$limit))
217
+    {
218
+        $obj = $db->fetch_object($result);
219
+
220
+        $email->id = $obj->rowid;
221
+        $email->ref = $obj->rowid;
222
+
223
+        print "<tr>";
224
+
225
+        print '<td>';
226
+        print $email->getNomUrl(1);
227
+        print '</td>';
228
+
229
+        print '<td>'.$obj->titre.'</td>';
230
+        // Date creation
231
+
232
+        print '<td align="center">';
233
+        print dol_print_date($db->jdate($obj->datec),'day');
234
+        print '</td>';
235
+
236
+        // Nb of email
237
+        if (! $filteremail)
238
+        {
239
+            print '<td align="center">';
240
+            $nbemail = $obj->nbemail;
241
+            /*if ($obj->statut != 3 && !empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail)
242 242
 			{
243 243
 				$text=$langs->trans('LimitSendingEmailing',$conf->global->MAILING_LIMIT_SENDBYWEB);
244 244
 				print $form->textwithpicto($nbemail,$text,1,'warning');
@@ -247,39 +247,39 @@  discard block
 block discarded – undo
247 247
 			{
248 248
 				print $nbemail;
249 249
 			}*/
250
-			print $nbemail;
251
-			print '</td>';
252
-		}
253
-
254
-		// Last send
255
-		print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi),'day').'</td>';
256
-		print '</td>';
257
-
258
-		// Status
259
-		print '<td align="right" class="nowrap">';
260
-		if ($filteremail)
261
-		{
262
-			print $email::libStatutDest($obj->sendstatut,2);
263
-		}
264
-		else
265
-		{
266
-			print $email->LibStatut($obj->statut,5);
267
-		}
268
-		print '</td>';
269
-
270
-		print '<td></td>';
271
-
272
-		print "</tr>\n";
273
-		$i++;
274
-	}
275
-	print '</table>';
276
-	print '</div>';
277
-	print '</form>';
278
-	$db->free($result);
250
+            print $nbemail;
251
+            print '</td>';
252
+        }
253
+
254
+        // Last send
255
+        print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi),'day').'</td>';
256
+        print '</td>';
257
+
258
+        // Status
259
+        print '<td align="right" class="nowrap">';
260
+        if ($filteremail)
261
+        {
262
+            print $email::libStatutDest($obj->sendstatut,2);
263
+        }
264
+        else
265
+        {
266
+            print $email->LibStatut($obj->statut,5);
267
+        }
268
+        print '</td>';
269
+
270
+        print '<td></td>';
271
+
272
+        print "</tr>\n";
273
+        $i++;
274
+    }
275
+    print '</table>';
276
+    print '</div>';
277
+    print '</form>';
278
+    $db->free($result);
279 279
 }
280 280
 else
281 281
 {
282
-	dol_print_error($db);
282
+    dol_print_error($db);
283 283
 }
284 284
 
285 285
 // End of page
Please login to merge, or discard this patch.
Braces   +59 added lines, -25 removed lines patch added patch discarded remove patch
@@ -39,8 +39,12 @@  discard block
 block discarded – undo
39 39
 $offset = $limit * $page;
40 40
 $pageprev = $page - 1;
41 41
 $pagenext = $page + 1;
42
-if (! $sortorder) $sortorder="DESC";
43
-if (! $sortfield) $sortfield="m.date_creat";
42
+if (! $sortorder) {
43
+    $sortorder="DESC";
44
+}
45
+if (! $sortfield) {
46
+    $sortfield="m.date_creat";
47
+}
44 48
 
45 49
 $search_all=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
46 50
 $search_ref=GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
@@ -73,7 +77,9 @@  discard block
 block discarded – undo
73 77
 
74 78
 $parameters=array();
75 79
 $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
76
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80
+if ($reshook < 0) {
81
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
82
+}
77 83
 
78 84
 if (empty($reshook))
79 85
 {
@@ -81,13 +87,15 @@  discard block
 block discarded – undo
81 87
 	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
82 88
 
83 89
 	// Purge search criteria
84
-	if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
90
+	if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) {
91
+	    // All tests are required to be compatible with all browsers
85 92
 	{
86 93
 		/*foreach($object->fields as $key => $val)
87 94
 		{
88 95
 			$search[$key]='';
89 96
 		}*/
90 97
 		$search_ref = '';
98
+	}
91 99
 		$search_all = '';
92 100
 		$toselect='';
93 101
 		$search_array_options=array();
@@ -124,22 +132,37 @@  discard block
 block discarded – undo
124 132
 	$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
125 133
 	$sql.= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
126 134
 	$sql.= " AND mc.email = '".$db->escape($filteremail)."'";
127
-	if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
128
-	if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
129
-	if (! $sortorder) $sortorder="ASC";
130
-	if (! $sortfield) $sortfield="m.rowid";
135
+	if ($search_ref) {
136
+	    $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
137
+	}
138
+	if ($search_all) {
139
+	    $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
140
+	}
141
+	if (! $sortorder) {
142
+	    $sortorder="ASC";
143
+	}
144
+	if (! $sortfield) {
145
+	    $sortfield="m.rowid";
146
+	}
131 147
 	$sql.= $db->order($sortfield,$sortorder);
132 148
 	$sql.= $db->plimit($conf->liste_limit +1, $offset);
133
-}
134
-else
149
+} else
135 150
 {
136 151
 	$sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
137 152
 	$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
138 153
 	$sql.= " WHERE m.entity = ".$conf->entity;
139
-	if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
140
-	if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
141
-	if (! $sortorder) $sortorder="ASC";
142
-	if (! $sortfield) $sortfield="m.rowid";
154
+	if ($search_ref) {
155
+	    $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
156
+	}
157
+	if ($search_all) {
158
+	    $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
159
+	}
160
+	if (! $sortorder) {
161
+	    $sortorder="ASC";
162
+	}
163
+	if (! $sortfield) {
164
+	    $sortfield="m.rowid";
165
+	}
143 166
 	$sql.= $db->order($sortfield,$sortorder);
144 167
 	$sql.= $db->plimit($conf->liste_limit +1, $offset);
145 168
 }
@@ -151,7 +174,9 @@  discard block
 block discarded – undo
151 174
 	$num = $db->num_rows($result);
152 175
 
153 176
 	$title=$langs->trans("ListOfEMailings");
154
-	if ($filteremail) $title.=' ('.$langs->trans("SentTo",$filteremail).')';
177
+	if ($filteremail) {
178
+	    $title.=' ('.$langs->trans("SentTo",$filteremail).')';
179
+	}
155 180
 
156 181
 	$newcardbutton='';
157 182
 	if ($user->rights->mailing->creer)
@@ -164,10 +189,14 @@  discard block
 block discarded – undo
164 189
 	$i = 0;
165 190
 
166 191
 	$param = "&search_all=".urlencode($search_all);
167
-	if ($filteremail) $param.='&filteremail='.urlencode($filteremail);
192
+	if ($filteremail) {
193
+	    $param.='&filteremail='.urlencode($filteremail);
194
+	}
168 195
 
169 196
 	print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
170
-	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
197
+	if ($optioncss != '') {
198
+	    print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
199
+	}
171 200
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
172 201
 	print '<input type="hidden" name="action" value="list">';
173 202
 	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
@@ -190,7 +219,9 @@  discard block
 block discarded – undo
190 219
 	print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
191 220
 	print '</td>';
192 221
 	print '<td class="liste_titre">&nbsp;</td>';
193
-	if (! $filteremail) print '<td class="liste_titre">&nbsp;</td>';
222
+	if (! $filteremail) {
223
+	    print '<td class="liste_titre">&nbsp;</td>';
224
+	}
194 225
 	print '<td class="liste_titre">&nbsp;</td>';
195 226
 	print '<td class="liste_titre">&nbsp;</td>';
196 227
 	print '<td class="liste_titre" align="right">';
@@ -203,9 +234,14 @@  discard block
 block discarded – undo
203 234
 	print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"m.rowid",$param,"","",$sortfield,$sortorder);
204 235
 	print_liste_field_titre("Title",$_SERVER["PHP_SELF"],"m.titre",$param,"","",$sortfield,$sortorder);
205 236
 	print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"m.date_creat",$param,"",'align="center"',$sortfield,$sortorder);
206
-	if (! $filteremail) print_liste_field_titre("NbOfEMails",$_SERVER["PHP_SELF"],"m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
207
-	if (! $filteremail) print_liste_field_titre("DateLastSend",$_SERVER["PHP_SELF"],"m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
208
-	else print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
237
+	if (! $filteremail) {
238
+	    print_liste_field_titre("NbOfEMails",$_SERVER["PHP_SELF"],"m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
239
+	}
240
+	if (! $filteremail) {
241
+	    print_liste_field_titre("DateLastSend",$_SERVER["PHP_SELF"],"m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
242
+	} else {
243
+	    print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
244
+	}
209 245
 	print_liste_field_titre("Status",$_SERVER["PHP_SELF"],($filteremail?"mc.statut":"m.statut"),$param,"",'align="right"',$sortfield,$sortorder);
210 246
 	print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
211 247
 	print "</tr>\n";
@@ -260,8 +296,7 @@  discard block
 block discarded – undo
260 296
 		if ($filteremail)
261 297
 		{
262 298
 			print $email::libStatutDest($obj->sendstatut,2);
263
-		}
264
-		else
299
+		} else
265 300
 		{
266 301
 			print $email->LibStatut($obj->statut,5);
267 302
 		}
@@ -276,8 +311,7 @@  discard block
 block discarded – undo
276 311
 	print '</div>';
277 312
 	print '</form>';
278 313
 	$db->free($result);
279
-}
280
-else
314
+} else
281 315
 {
282 316
 	dol_print_error($db);
283 317
 }
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -25,29 +25,29 @@  discard block
 block discarded – undo
25 25
 
26 26
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
27 27
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
28
-require DOL_BASE_PATH . '/main.inc.php';
28
+require DOL_BASE_PATH.'/main.inc.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/comm/mailing/class/mailing.class.php';
30 30
 
31 31
 // Load translation files required by the page
32 32
 $langs->load("mails");
33 33
 
34 34
 // Security check
35
-$result=restrictedArea($user,'mailing');
35
+$result = restrictedArea($user, 'mailing');
36 36
 
37
-$sortfield = GETPOST("sortfield",'alpha');
38
-$sortorder = GETPOST("sortorder",'alpha');
39
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
40
-$page = GETPOST("page",'int');
41
-if (empty($page) || $page == -1 || GETPOST('button_search','alpha') || GETPOST('button_removefilter','alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; }     // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
37
+$sortfield = GETPOST("sortfield", 'alpha');
38
+$sortorder = GETPOST("sortorder", 'alpha');
39
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
40
+$page = GETPOST("page", 'int');
41
+if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; }     // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
42 42
 $offset = $limit * $page;
43 43
 $pageprev = $page - 1;
44 44
 $pagenext = $page + 1;
45
-if (! $sortorder) $sortorder="DESC";
46
-if (! $sortfield) $sortfield="m.date_creat";
45
+if (!$sortorder) $sortorder = "DESC";
46
+if (!$sortfield) $sortfield = "m.date_creat";
47 47
 
48
-$search_all=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
49
-$search_ref=GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
50
-$filteremail=GETPOST('filteremail','alpha');
48
+$search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
49
+$search_ref = GETPOST("search_ref", "alpha") ? GETPOST("search_ref", "alpha") : GETPOST("sref", "alpha");
50
+$filteremail = GETPOST('filteremail', 'alpha');
51 51
 
52 52
 $object = new Mailing($db);
53 53
 
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
 // fetch optionals attributes and labels
59 59
 $extralabels = $extrafields->fetch_name_optionals_label('mailing');
60
-$search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
60
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
61 61
 
62 62
 // List of fields to search into when doing a "search in all"
63 63
 $fieldstosearchall = array(
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
  * Actions
72 72
  */
73 73
 
74
-if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
75
-if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
74
+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
75
+if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction = ''; }
76 76
 
77
-$parameters=array();
78
-$reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action);    // Note that $action and $object may have been modified by some hooks
77
+$parameters = array();
78
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
79 79
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80 80
 
81 81
 if (empty($reshook))
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
85 85
 
86 86
 	// Purge search criteria
87
-	if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
87
+	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
88 88
 	{
89 89
 		/*foreach($object->fields as $key => $val)
90 90
 		{
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
 		}*/
93 93
 		$search_ref = '';
94 94
 		$search_all = '';
95
-		$toselect='';
96
-		$search_array_options=array();
95
+		$toselect = '';
96
+		$search_array_options = array();
97 97
 	}
98
-	if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')
99
-		|| GETPOST('button_search_x','alpha') || GETPOST('button_search.x','alpha') || GETPOST('button_search','alpha'))
98
+	if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
99
+		|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha'))
100 100
 	{
101
-		$massaction='';     // Protection to avoid mass action if we force a new search during a mass action confirmation
101
+		$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
102 102
 	}
103 103
 
104 104
 	// Mass actions
@@ -116,35 +116,35 @@  discard block
 block discarded – undo
116 116
  * View
117 117
  */
118 118
 
119
-llxHeader('',$langs->trans("Mailing"),'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
119
+llxHeader('', $langs->trans("Mailing"), 'EN:Module_EMailing|FR:Module_Mailing|ES:M&oacute;dulo_Mailing');
120 120
 
121 121
 $form = new Form($db);
122 122
 
123 123
 if ($filteremail)
124 124
 {
125 125
 	$sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi,";
126
-	$sql.= " mc.statut as sendstatut";
127
-	$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
128
-	$sql.= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
129
-	$sql.= " AND mc.email = '".$db->escape($filteremail)."'";
130
-	if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
131
-	if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
132
-	if (! $sortorder) $sortorder="ASC";
133
-	if (! $sortfield) $sortfield="m.rowid";
134
-	$sql.= $db->order($sortfield,$sortorder);
135
-	$sql.= $db->plimit($conf->liste_limit +1, $offset);
126
+	$sql .= " mc.statut as sendstatut";
127
+	$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m, ".MAIN_DB_PREFIX."mailing_cibles as mc";
128
+	$sql .= " WHERE m.rowid = mc.fk_mailing AND m.entity = ".$conf->entity;
129
+	$sql .= " AND mc.email = '".$db->escape($filteremail)."'";
130
+	if ($search_ref) $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
131
+	if ($search_all) $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
132
+	if (!$sortorder) $sortorder = "ASC";
133
+	if (!$sortfield) $sortfield = "m.rowid";
134
+	$sql .= $db->order($sortfield, $sortorder);
135
+	$sql .= $db->plimit($conf->liste_limit + 1, $offset);
136 136
 }
137 137
 else
138 138
 {
139 139
 	$sql = "SELECT m.rowid, m.titre, m.nbemail, m.statut, m.date_creat as datec, m.date_envoi as date_envoi";
140
-	$sql.= " FROM ".MAIN_DB_PREFIX."mailing as m";
141
-	$sql.= " WHERE m.entity = ".$conf->entity;
142
-	if ($search_ref) $sql.= " AND m.rowid = '".$db->escape($search_ref)."'";
143
-	if ($search_all) $sql.= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
144
-	if (! $sortorder) $sortorder="ASC";
145
-	if (! $sortfield) $sortfield="m.rowid";
146
-	$sql.= $db->order($sortfield,$sortorder);
147
-	$sql.= $db->plimit($conf->liste_limit +1, $offset);
140
+	$sql .= " FROM ".MAIN_DB_PREFIX."mailing as m";
141
+	$sql .= " WHERE m.entity = ".$conf->entity;
142
+	if ($search_ref) $sql .= " AND m.rowid = '".$db->escape($search_ref)."'";
143
+	if ($search_all) $sql .= " AND (m.titre like '%".$db->escape($search_all)."%' OR m.sujet like '%".$db->escape($search_all)."%' OR m.body like '%".$db->escape($search_all)."%')";
144
+	if (!$sortorder) $sortorder = "ASC";
145
+	if (!$sortfield) $sortfield = "m.rowid";
146
+	$sql .= $db->order($sortfield, $sortorder);
147
+	$sql .= $db->plimit($conf->liste_limit + 1, $offset);
148 148
 }
149 149
 
150 150
 //print $sql;
@@ -153,21 +153,21 @@  discard block
 block discarded – undo
153 153
 {
154 154
 	$num = $db->num_rows($result);
155 155
 
156
-	$title=$langs->trans("ListOfEMailings");
157
-	if ($filteremail) $title.=' ('.$langs->trans("SentTo",$filteremail).')';
156
+	$title = $langs->trans("ListOfEMailings");
157
+	if ($filteremail) $title .= ' ('.$langs->trans("SentTo", $filteremail).')';
158 158
 
159
-	$newcardbutton='';
159
+	$newcardbutton = '';
160 160
 	if ($user->rights->mailing->creer)
161 161
 	{
162
-		$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/mailing/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewMailing').'</span>';
163
-		$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
164
-		$newcardbutton.= '</a>';
162
+		$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/comm/mailing/card.php?action=create"><span class="valignmiddle">'.$langs->trans('NewMailing').'</span>';
163
+		$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>';
164
+		$newcardbutton .= '</a>';
165 165
 	}
166 166
 
167 167
 	$i = 0;
168 168
 
169 169
 	$param = "&search_all=".urlencode($search_all);
170
-	if ($filteremail) $param.='&filteremail='.urlencode($filteremail);
170
+	if ($filteremail) $param .= '&filteremail='.urlencode($filteremail);
171 171
 
172 172
 	print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
173 173
 	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
@@ -177,12 +177,12 @@  discard block
 block discarded – undo
177 177
 	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
178 178
 	print '<input type="hidden" name="page" value="'.$page.'">';
179 179
 
180
-	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '',$num, '', 'title_generic.png', 0, $newcardbutton);
180
+	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, '', 'title_generic.png', 0, $newcardbutton);
181 181
 
182 182
 	$moreforfilter = '';
183 183
 
184 184
     print '<div class="div-table-responsive">';
185
-    print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
185
+    print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
186 186
 
187 187
 	print '<tr class="liste_titre_filter">';
188 188
 	print '<td class="liste_titre">';
@@ -193,30 +193,30 @@  discard block
 block discarded – undo
193 193
 	print '<input type="text" class="flat maxwidth100 maxwidth50onsmartphone" name="search_all" value="'.dol_escape_htmltag($search_all).'">';
194 194
 	print '</td>';
195 195
 	print '<td class="liste_titre">&nbsp;</td>';
196
-	if (! $filteremail) print '<td class="liste_titre">&nbsp;</td>';
196
+	if (!$filteremail) print '<td class="liste_titre">&nbsp;</td>';
197 197
 	print '<td class="liste_titre">&nbsp;</td>';
198 198
 	print '<td class="liste_titre">&nbsp;</td>';
199 199
 	print '<td class="liste_titre" align="right">';
200
-	$searchpicto=$form->showFilterAndCheckAddButtons(0);
200
+	$searchpicto = $form->showFilterAndCheckAddButtons(0);
201 201
 	print $searchpicto;
202 202
 	print '</td>';
203 203
 	print "</tr>\n";
204 204
 
205 205
 	print '<tr class="liste_titre">';
206
-	print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"m.rowid",$param,"","",$sortfield,$sortorder);
207
-	print_liste_field_titre("Title",$_SERVER["PHP_SELF"],"m.titre",$param,"","",$sortfield,$sortorder);
208
-	print_liste_field_titre("DateCreation",$_SERVER["PHP_SELF"],"m.date_creat",$param,"",'align="center"',$sortfield,$sortorder);
209
-	if (! $filteremail) print_liste_field_titre("NbOfEMails",$_SERVER["PHP_SELF"],"m.nbemail",$param,"",'align="center"',$sortfield,$sortorder);
210
-	if (! $filteremail) print_liste_field_titre("DateLastSend",$_SERVER["PHP_SELF"],"m.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
211
-	else print_liste_field_titre("DateSending",$_SERVER["PHP_SELF"],"mc.date_envoi",$param,"",'align="center"',$sortfield,$sortorder);
212
-	print_liste_field_titre("Status",$_SERVER["PHP_SELF"],($filteremail?"mc.statut":"m.statut"),$param,"",'align="right"',$sortfield,$sortorder);
213
-	print_liste_field_titre('', $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch ');
206
+	print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "m.rowid", $param, "", "", $sortfield, $sortorder);
207
+	print_liste_field_titre("Title", $_SERVER["PHP_SELF"], "m.titre", $param, "", "", $sortfield, $sortorder);
208
+	print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "m.date_creat", $param, "", 'align="center"', $sortfield, $sortorder);
209
+	if (!$filteremail) print_liste_field_titre("NbOfEMails", $_SERVER["PHP_SELF"], "m.nbemail", $param, "", 'align="center"', $sortfield, $sortorder);
210
+	if (!$filteremail) print_liste_field_titre("DateLastSend", $_SERVER["PHP_SELF"], "m.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
211
+	else print_liste_field_titre("DateSending", $_SERVER["PHP_SELF"], "mc.date_envoi", $param, "", 'align="center"', $sortfield, $sortorder);
212
+	print_liste_field_titre("Status", $_SERVER["PHP_SELF"], ($filteremail ? "mc.statut" : "m.statut"), $param, "", 'align="right"', $sortfield, $sortorder);
213
+	print_liste_field_titre('', $_SERVER["PHP_SELF"], "", '', '', 'align="right"', $sortfield, $sortorder, 'maxwidthsearch ');
214 214
 	print "</tr>\n";
215 215
 
216 216
 
217
-	$email=new Mailing($db);
217
+	$email = new Mailing($db);
218 218
 
219
-	while ($i < min($num,$limit))
219
+	while ($i < min($num, $limit))
220 220
 	{
221 221
 		$obj = $db->fetch_object($result);
222 222
 
@@ -233,11 +233,11 @@  discard block
 block discarded – undo
233 233
 		// Date creation
234 234
 
235 235
 		print '<td align="center">';
236
-		print dol_print_date($db->jdate($obj->datec),'day');
236
+		print dol_print_date($db->jdate($obj->datec), 'day');
237 237
 		print '</td>';
238 238
 
239 239
 		// Nb of email
240
-		if (! $filteremail)
240
+		if (!$filteremail)
241 241
 		{
242 242
 			print '<td align="center">';
243 243
 			$nbemail = $obj->nbemail;
@@ -255,18 +255,18 @@  discard block
 block discarded – undo
255 255
 		}
256 256
 
257 257
 		// Last send
258
-		print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi),'day').'</td>';
258
+		print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->date_envoi), 'day').'</td>';
259 259
 		print '</td>';
260 260
 
261 261
 		// Status
262 262
 		print '<td align="right" class="nowrap">';
263 263
 		if ($filteremail)
264 264
 		{
265
-			print $email::libStatutDest($obj->sendstatut,2);
265
+			print $email::libStatutDest($obj->sendstatut, 2);
266 266
 		}
267 267
 		else
268 268
 		{
269
-			print $email->LibStatut($obj->statut,5);
269
+			print $email->LibStatut($obj->statut, 5);
270 270
 		}
271 271
 		print '</td>';
272 272
 
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/admin/propal_extrafields.php 2 patches
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,13 +37,17 @@
 block discarded – undo
37 37
 // List of supported format
38 38
 $tmptype2label=ExtraFields::$type2label;
39 39
 $type2label=array('');
40
-foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val);
40
+foreach ($tmptype2label as $key => $val) {
41
+    $type2label[$key]=$langs->transnoentitiesnoconv($val);
42
+}
41 43
 
42 44
 $action=GETPOST('action', 'alpha');
43 45
 $attrname=GETPOST('attrname', 'alpha');
44 46
 $elementtype='propal'; //Must be the $table_element of the class that manage extrafield
45 47
 
46
-if (!$user->admin) accessforbidden();
48
+if (!$user->admin) {
49
+    accessforbidden();
50
+}
47 51
 
48 52
 
49 53
 /*
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
29 29
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
30
-require DOL_BASE_PATH . '/main.inc.php';
30
+require DOL_BASE_PATH.'/main.inc.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
33 33
 
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
 $form = new Form($db);
39 39
 
40 40
 // List of supported format
41
-$tmptype2label=ExtraFields::$type2label;
42
-$type2label=array('');
43
-foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val);
41
+$tmptype2label = ExtraFields::$type2label;
42
+$type2label = array('');
43
+foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
44 44
 
45
-$action=GETPOST('action', 'alpha');
46
-$attrname=GETPOST('attrname', 'alpha');
47
-$elementtype='propal'; //Must be the $table_element of the class that manage extrafield
45
+$action = GETPOST('action', 'alpha');
46
+$attrname = GETPOST('attrname', 'alpha');
47
+$elementtype = 'propal'; //Must be the $table_element of the class that manage extrafield
48 48
 
49 49
 if (!$user->admin) accessforbidden();
50 50
 
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
  * View
62 62
  */
63 63
 
64
-$textobject=$langs->transnoentitiesnoconv("Proposals");
64
+$textobject = $langs->transnoentitiesnoconv("Proposals");
65 65
 
66
-llxHeader('',$langs->trans("PropalSetup"));
66
+llxHeader('', $langs->trans("PropalSetup"));
67 67
 
68
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
69
-print load_fiche_titre($langs->trans("PropalSetup"),$linkback,'title_setup');
68
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
69
+print load_fiche_titre($langs->trans("PropalSetup"), $linkback, 'title_setup');
70 70
 
71 71
 
72 72
 $head = propal_admin_prepare_head();
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 /* Edition of an optional field                                               */
107 107
 /*                                                                            */
108 108
 /* ************************************************************************** */
109
-if ($action == 'edit' && ! empty($attrname))
109
+if ($action == 'edit' && !empty($attrname))
110 110
 {
111 111
     print "<br>";
112 112
     print load_fiche_titre($langs->trans("FieldEdition", $attrname));
Please login to merge, or discard this patch.
dolibarr/htdocs/comm/admin/propaldet_extrafields.php 3 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 
34 34
 
35 35
 if (!$user->admin)
36
-	accessforbidden();
36
+    accessforbidden();
37 37
 
38 38
 // Load translation files required by the page
39 39
 $langs->loadlangs(array('admin', 'other', 'propal'));
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 
100 100
 if ($action == 'create')
101 101
 {
102
-	print '<br><div id="newattrib"></div>';
102
+    print '<br><div id="newattrib"></div>';
103 103
     print load_fiche_titre($langs->trans('NewAttribute'));
104 104
 
105 105
     require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
Please login to merge, or discard this patch.
Braces   +8 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@  discard block
 block discarded – undo
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
33 33
 
34 34
 
35
-if (!$user->admin)
35
+if (!$user->admin) {
36 36
 	accessforbidden();
37
+}
37 38
 
38 39
 // Load translation files required by the page
39 40
 $langs->loadlangs(array('admin', 'other', 'propal'));
@@ -44,14 +45,18 @@  discard block
 block discarded – undo
44 45
 // List of supported format
45 46
 $tmptype2label=ExtraFields::$type2label;
46 47
 $type2label=array('');
47
-foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val);
48
+foreach ($tmptype2label as $key => $val) {
49
+    $type2label[$key]=$langs->transnoentitiesnoconv($val);
50
+}
48 51
 
49 52
 $action=GETPOST('action', 'alpha');
50 53
 $attrname=GETPOST('attrname', 'alpha');
51 54
 
52 55
 $elementtype='propaldet'; //Must be the $table_element of the class that manage extrafield
53 56
 
54
-if (!$user->admin) accessforbidden();
57
+if (!$user->admin) {
58
+    accessforbidden();
59
+}
55 60
 
56 61
 
57 62
 /*
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
 // Copyright (C) 2018 Alxarafe/Alixar  <[email protected]>
32 32
 defined('BASE_PATH') or die('Single entry point through the index.php of the main folder');
33
-require DOL_BASE_PATH . '/main.inc.php';
33
+require DOL_BASE_PATH.'/main.inc.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/lib/propal.lib.php';
35 35
 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
36 36
 
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 $form = new Form($db);
46 46
 
47 47
 // List of supported format
48
-$tmptype2label=ExtraFields::$type2label;
49
-$type2label=array('');
50
-foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->transnoentitiesnoconv($val);
48
+$tmptype2label = ExtraFields::$type2label;
49
+$type2label = array('');
50
+foreach ($tmptype2label as $key => $val) $type2label[$key] = $langs->transnoentitiesnoconv($val);
51 51
 
52
-$action=GETPOST('action', 'alpha');
53
-$attrname=GETPOST('attrname', 'alpha');
52
+$action = GETPOST('action', 'alpha');
53
+$attrname = GETPOST('attrname', 'alpha');
54 54
 
55
-$elementtype='propaldet'; //Must be the $table_element of the class that manage extrafield
55
+$elementtype = 'propaldet'; //Must be the $table_element of the class that manage extrafield
56 56
 
57 57
 if (!$user->admin) accessforbidden();
58 58
 
@@ -69,12 +69,12 @@  discard block
 block discarded – undo
69 69
  * View
70 70
  */
71 71
 
72
-$textobject=$langs->transnoentitiesnoconv("Proposals");
72
+$textobject = $langs->transnoentitiesnoconv("Proposals");
73 73
 
74
-llxHeader('',$langs->trans("PropalSetup"));
74
+llxHeader('', $langs->trans("PropalSetup"));
75 75
 
76
-$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
77
-print load_fiche_titre($langs->trans("PropalSetup"),$linkback,'title_setup');
76
+$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
77
+print load_fiche_titre($langs->trans("PropalSetup"), $linkback, 'title_setup');
78 78
 
79 79
 $head = propal_admin_prepare_head();
80 80
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 /* Edition of an optional field                                               */
114 114
 /*                                                                            */
115 115
 /* ************************************************************************** */
116
-if ($action == 'edit' && ! empty($attrname))
116
+if ($action == 'edit' && !empty($attrname))
117 117
 {
118 118
     print "<br>";
119 119
     print load_fiche_titre($langs->trans("FieldEdition", $attrname));
Please login to merge, or discard this patch.