1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* Copyright (C) 2002 Rodolphe Quiedeville <[email protected]> |
4
|
|
|
* Copyright (C) 2004-2008 Laurent Destailleur <[email protected]> |
5
|
|
|
* Copyright (C) 2009-2017 Regis Houssin <[email protected]> |
6
|
|
|
* Copyright (C) 2016 Charlie Benke <[email protected]> |
7
|
|
|
* Copyright (C) 2018-2019 Thibault Foucart <[email protected]> |
8
|
|
|
* Copyright (C) 2021 Waël Almoman <[email protected]> |
9
|
|
|
* Copyright (C) 2024 Frédéric France <[email protected]> |
10
|
|
|
* Copyright (C) 2024 Rafael San José <[email protected]> |
11
|
|
|
* |
12
|
|
|
* This program is free software; you can redistribute it and/or modify |
13
|
|
|
* it under the terms of the GNU General Public License as published by |
14
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
15
|
|
|
* (at your option) any later version. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, |
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20
|
|
|
* GNU General Public License for more details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU General Public License |
23
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace Dolibarr\Code\Adherents\Classes; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* \file htdocs/adherents/class/adherent_type.class.php |
30
|
|
|
* \ingroup member |
31
|
|
|
* \brief File of class to manage members types |
32
|
|
|
*/ |
33
|
|
|
|
34
|
|
|
use Dolibarr\Core\Base\CommonObject; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Class to manage members type |
39
|
|
|
*/ |
40
|
|
|
class AdherentType extends CommonObject |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* @var string Name of table without prefix where object is stored |
44
|
|
|
*/ |
45
|
|
|
public $table_element = 'adherent_type'; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string ID to identify managed object |
49
|
|
|
*/ |
50
|
|
|
public $element = 'adherent_type'; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png |
54
|
|
|
*/ |
55
|
|
|
public $picto = 'members'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var string |
59
|
|
|
* @deprecated Use label |
60
|
|
|
* @see $label |
61
|
|
|
*/ |
62
|
|
|
public $libelle; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string Adherent type label |
66
|
|
|
*/ |
67
|
|
|
public $label; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var string Adherent type nature |
71
|
|
|
*/ |
72
|
|
|
public $morphy; |
73
|
|
|
|
74
|
|
|
public $duration; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* type expiration |
78
|
|
|
*/ |
79
|
|
|
public $duration_value; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Expiration unit |
83
|
|
|
*/ |
84
|
|
|
public $duration_unit; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var int Subscription required (0 or 1) |
88
|
|
|
*/ |
89
|
|
|
public $subscription; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var float|string Amount for subscription (null or '' means not defined) |
93
|
|
|
*/ |
94
|
|
|
public $amount; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var int Amount can be chosen by the visitor during subscription (0 or 1) |
98
|
|
|
*/ |
99
|
|
|
public $caneditamount; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var string Public note |
103
|
|
|
* @deprecated |
104
|
|
|
*/ |
105
|
|
|
public $note; |
106
|
|
|
|
107
|
|
|
/** @var string Public note */ |
108
|
|
|
public $note_public; |
109
|
|
|
|
110
|
|
|
/** @var integer Can vote */ |
111
|
|
|
public $vote; |
112
|
|
|
|
113
|
|
|
/** @var string Email sent during validation of member */ |
114
|
|
|
public $mail_valid; |
115
|
|
|
|
116
|
|
|
/** @var string Email sent after recording a new subscription */ |
117
|
|
|
public $mail_subscription = ''; |
118
|
|
|
|
119
|
|
|
/** @var string Email sent after resiliation */ |
120
|
|
|
public $mail_resiliate = ''; |
121
|
|
|
|
122
|
|
|
/** @var string Email sent after exclude */ |
123
|
|
|
public $mail_exclude = ''; |
124
|
|
|
|
125
|
|
|
/** @var array Array of members */ |
126
|
|
|
public $members = array(); |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @var string description |
130
|
|
|
*/ |
131
|
|
|
public $description; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @var string email |
135
|
|
|
*/ |
136
|
|
|
public $email; |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @var array multilangs |
140
|
|
|
*/ |
141
|
|
|
public $multilangs = array(); |
142
|
|
|
|
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Constructor |
146
|
|
|
* |
147
|
|
|
* @param DoliDB $db Database handler |
|
|
|
|
148
|
|
|
*/ |
149
|
|
|
public function __construct($db) |
150
|
|
|
{ |
151
|
|
|
$this->db = $db; |
152
|
|
|
|
153
|
|
|
$this->ismultientitymanaged = 1; |
154
|
|
|
$this->status = 1; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Load array this->multilangs |
159
|
|
|
* |
160
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
161
|
|
|
*/ |
162
|
|
|
public function getMultiLangs() |
163
|
|
|
{ |
164
|
|
|
global $langs; |
165
|
|
|
|
166
|
|
|
$current_lang = $langs->getDefaultLang(); |
167
|
|
|
|
168
|
|
|
$sql = "SELECT lang, label, description, email"; |
169
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type_lang"; |
170
|
|
|
$sql .= " WHERE fk_type = " . ((int) $this->id); |
171
|
|
|
|
172
|
|
|
$result = $this->db->query($sql); |
173
|
|
|
if ($result) { |
174
|
|
|
while ($obj = $this->db->fetch_object($result)) { |
175
|
|
|
//print 'lang='.$obj->lang.' current='.$current_lang.'<br>'; |
176
|
|
|
if ($obj->lang == $current_lang) { // si on a les traduct. dans la langue courante on les charge en infos principales. |
177
|
|
|
$this->label = $obj->label; |
178
|
|
|
$this->description = $obj->description; |
179
|
|
|
$this->email = $obj->email; |
180
|
|
|
} |
181
|
|
|
$this->multilangs["$obj->lang"]["label"] = $obj->label; |
182
|
|
|
$this->multilangs["$obj->lang"]["description"] = $obj->description; |
183
|
|
|
$this->multilangs["$obj->lang"]["email"] = $obj->email; |
184
|
|
|
} |
185
|
|
|
return 1; |
186
|
|
|
} else { |
187
|
|
|
$this->error = "Error: " . $this->db->lasterror() . " - " . $sql; |
188
|
|
|
return -1; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Update or add a translation for this member type |
194
|
|
|
* |
195
|
|
|
* @param User $user Object user making update |
|
|
|
|
196
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
197
|
|
|
*/ |
198
|
|
|
public function setMultiLangs($user) |
199
|
|
|
{ |
200
|
|
|
global $langs; |
201
|
|
|
|
202
|
|
|
$langs_available = $langs->get_available_languages(DOL_DOCUMENT_ROOT, 0, 2); |
203
|
|
|
$current_lang = $langs->getDefaultLang(); |
204
|
|
|
|
205
|
|
|
foreach ($langs_available as $key => $value) { |
206
|
|
|
if ($key == $current_lang) { |
207
|
|
|
$sql = "SELECT rowid"; |
208
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type_lang"; |
209
|
|
|
$sql .= " WHERE fk_type = " . ((int) $this->id); |
210
|
|
|
$sql .= " AND lang = '" . $this->db->escape($key) . "'"; |
211
|
|
|
|
212
|
|
|
$result = $this->db->query($sql); |
213
|
|
|
|
214
|
|
|
if ($this->db->num_rows($result)) { // if there is already a description line for this language |
215
|
|
|
$sql2 = "UPDATE " . MAIN_DB_PREFIX . "adherent_type_lang"; |
216
|
|
|
$sql2 .= " SET"; |
217
|
|
|
$sql2 .= " label = '" . $this->db->escape($this->label) . "',"; |
218
|
|
|
$sql2 .= " description = '" . $this->db->escape($this->description) . "'"; |
219
|
|
|
$sql2 .= " WHERE fk_type = " . ((int) $this->id) . " AND lang='" . $this->db->escape($key) . "'"; |
220
|
|
|
} else { |
221
|
|
|
$sql2 = "INSERT INTO " . MAIN_DB_PREFIX . "adherent_type_lang (fk_type, lang, label, description"; |
222
|
|
|
$sql2 .= ")"; |
223
|
|
|
$sql2 .= " VALUES(" . ((int) $this->id) . ",'" . $this->db->escape($key) . "','" . $this->db->escape($this->label) . "',"; |
224
|
|
|
$sql2 .= " '" . $this->db->escape($this->description) . "'"; |
225
|
|
|
$sql2 .= ")"; |
226
|
|
|
} |
227
|
|
|
dol_syslog(get_class($this) . '::setMultiLangs key = current_lang = ' . $key); |
228
|
|
|
if (!$this->db->query($sql2)) { |
229
|
|
|
$this->error = $this->db->lasterror(); |
230
|
|
|
return -1; |
231
|
|
|
} |
232
|
|
|
} elseif (isset($this->multilangs[$key])) { |
233
|
|
|
$sql = "SELECT rowid"; |
234
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type_lang"; |
235
|
|
|
$sql .= " WHERE fk_type = " . ((int) $this->id); |
236
|
|
|
$sql .= " AND lang = '" . $this->db->escape($key) . "'"; |
237
|
|
|
|
238
|
|
|
$result = $this->db->query($sql); |
239
|
|
|
|
240
|
|
|
if ($this->db->num_rows($result)) { // if there is already a description line for this language |
241
|
|
|
$sql2 = "UPDATE " . MAIN_DB_PREFIX . "adherent_type_lang"; |
242
|
|
|
$sql2 .= " SET "; |
243
|
|
|
$sql2 .= " label = '" . $this->db->escape($this->multilangs["$key"]["label"]) . "',"; |
244
|
|
|
$sql2 .= " description = '" . $this->db->escape($this->multilangs["$key"]["description"]) . "'"; |
245
|
|
|
$sql2 .= " WHERE fk_type = " . ((int) $this->id) . " AND lang='" . $this->db->escape($key) . "'"; |
246
|
|
|
} else { |
247
|
|
|
$sql2 = "INSERT INTO " . MAIN_DB_PREFIX . "adherent_type_lang (fk_type, lang, label, description"; |
248
|
|
|
$sql2 .= ")"; |
249
|
|
|
$sql2 .= " VALUES(" . ((int) $this->id) . ",'" . $this->db->escape($key) . "','" . $this->db->escape($this->multilangs["$key"]["label"]) . "',"; |
250
|
|
|
$sql2 .= " '" . $this->db->escape($this->multilangs["$key"]["description"]) . "'"; |
251
|
|
|
$sql2 .= ")"; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
// We do not save if main fields are empty |
255
|
|
|
if ($this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"]) { |
256
|
|
|
if (!$this->db->query($sql2)) { |
257
|
|
|
$this->error = $this->db->lasterror(); |
258
|
|
|
return -1; |
259
|
|
|
} |
260
|
|
|
} |
261
|
|
|
} else { |
262
|
|
|
// language is not current language and we didn't provide a multilang description for this language |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
// Call trigger |
267
|
|
|
$result = $this->call_trigger('MEMBER_TYPE_SET_MULTILANGS', $user); |
268
|
|
|
if ($result < 0) { |
269
|
|
|
$this->error = $this->db->lasterror(); |
270
|
|
|
return -1; |
271
|
|
|
} |
272
|
|
|
// End call triggers |
273
|
|
|
|
274
|
|
|
return 1; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Delete a language for this member type |
279
|
|
|
* |
280
|
|
|
* @param string $langtodelete Language code to delete |
281
|
|
|
* @param User $user Object user making delete |
282
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
283
|
|
|
*/ |
284
|
|
|
public function delMultiLangs($langtodelete, $user) |
285
|
|
|
{ |
286
|
|
|
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "adherent_type_lang"; |
287
|
|
|
$sql .= " WHERE fk_type = " . ((int) $this->id) . " AND lang = '" . $this->db->escape($langtodelete) . "'"; |
288
|
|
|
|
289
|
|
|
dol_syslog(get_class($this) . '::delMultiLangs', LOG_DEBUG); |
290
|
|
|
$result = $this->db->query($sql); |
291
|
|
|
if ($result) { |
292
|
|
|
// Call trigger |
293
|
|
|
$result = $this->call_trigger('MEMBER_TYPE_DEL_MULTILANGS', $user); |
294
|
|
|
if ($result < 0) { |
295
|
|
|
$this->error = $this->db->lasterror(); |
296
|
|
|
dol_syslog(get_class($this) . '::delMultiLangs error=' . $this->error, LOG_ERR); |
297
|
|
|
return -1; |
298
|
|
|
} |
299
|
|
|
// End call triggers |
300
|
|
|
return 1; |
301
|
|
|
} else { |
302
|
|
|
$this->error = $this->db->lasterror(); |
303
|
|
|
dol_syslog(get_class($this) . '::delMultiLangs error=' . $this->error, LOG_ERR); |
304
|
|
|
return -1; |
305
|
|
|
} |
306
|
|
|
} |
307
|
|
|
|
308
|
|
|
/** |
309
|
|
|
* Function to create the member type |
310
|
|
|
* |
311
|
|
|
* @param User $user User making creation |
312
|
|
|
* @param int $notrigger 1=do not execute triggers, 0 otherwise |
313
|
|
|
* @return int >0 if OK, < 0 if KO |
314
|
|
|
*/ |
315
|
|
|
public function create($user, $notrigger = 0) |
316
|
|
|
{ |
317
|
|
|
global $conf; |
318
|
|
|
|
319
|
|
|
$error = 0; |
320
|
|
|
|
321
|
|
|
$this->status = (int) $this->status; |
322
|
|
|
$this->label = trim($this->label); |
323
|
|
|
|
324
|
|
|
$this->db->begin(); |
325
|
|
|
|
326
|
|
|
$sql = "INSERT INTO " . MAIN_DB_PREFIX . "adherent_type ("; |
327
|
|
|
$sql .= " morphy"; |
328
|
|
|
$sql .= ", libelle"; |
329
|
|
|
$sql .= ", entity"; |
330
|
|
|
$sql .= ") VALUES ("; |
331
|
|
|
$sql .= "'" . $this->db->escape($this->morphy) . "'"; |
332
|
|
|
$sql .= ", '" . $this->db->escape($this->label) . "'"; |
333
|
|
|
$sql .= ", " . ((int) $conf->entity); |
334
|
|
|
$sql .= ")"; |
335
|
|
|
|
336
|
|
|
dol_syslog("Adherent_type::create", LOG_DEBUG); |
337
|
|
|
$result = $this->db->query($sql); |
338
|
|
|
if ($result) { |
339
|
|
|
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "adherent_type"); |
340
|
|
|
|
341
|
|
|
$result = $this->update($user, 1); |
342
|
|
|
if ($result < 0) { |
343
|
|
|
$this->db->rollback(); |
344
|
|
|
return -3; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
if (!$notrigger) { |
348
|
|
|
// Call trigger |
349
|
|
|
$result = $this->call_trigger('MEMBER_TYPE_CREATE', $user); |
350
|
|
|
if ($result < 0) { |
351
|
|
|
$error++; |
352
|
|
|
} |
353
|
|
|
// End call triggers |
354
|
|
|
} |
355
|
|
|
|
356
|
|
|
if (!$error) { |
357
|
|
|
$this->db->commit(); |
358
|
|
|
return $this->id; |
359
|
|
|
} else { |
360
|
|
|
dol_syslog(get_class($this) . "::create " . $this->error, LOG_ERR); |
361
|
|
|
$this->db->rollback(); |
362
|
|
|
return -2; |
363
|
|
|
} |
364
|
|
|
} else { |
365
|
|
|
$this->error = $this->db->lasterror(); |
366
|
|
|
$this->db->rollback(); |
367
|
|
|
return -1; |
368
|
|
|
} |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* Updating the type in the database |
373
|
|
|
* |
374
|
|
|
* @param User $user Object user making change |
375
|
|
|
* @param int $notrigger 1=do not execute triggers, 0 otherwise |
376
|
|
|
* @return int >0 if OK, < 0 if KO |
377
|
|
|
*/ |
378
|
|
|
public function update($user, $notrigger = 0) |
379
|
|
|
{ |
380
|
|
|
global $langs; |
381
|
|
|
|
382
|
|
|
$error = 0; |
383
|
|
|
|
384
|
|
|
$this->label = trim($this->label); |
385
|
|
|
|
386
|
|
|
if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility |
387
|
|
|
$this->note_public = $this->note; |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
$this->db->begin(); |
391
|
|
|
|
392
|
|
|
$sql = "UPDATE " . MAIN_DB_PREFIX . "adherent_type "; |
393
|
|
|
$sql .= "SET "; |
394
|
|
|
$sql .= "statut = " . ((int) $this->status) . ","; |
395
|
|
|
$sql .= "libelle = '" . $this->db->escape($this->label) . "',"; |
396
|
|
|
$sql .= "morphy = '" . $this->db->escape($this->morphy) . "',"; |
397
|
|
|
$sql .= "subscription = '" . $this->db->escape($this->subscription) . "',"; |
398
|
|
|
$sql .= "amount = " . ((empty($this->amount) && $this->amount == '') ? "null" : ((float) $this->amount)) . ","; |
399
|
|
|
$sql .= "caneditamount = " . ((int) $this->caneditamount) . ","; |
400
|
|
|
$sql .= "duration = '" . $this->db->escape($this->duration_value . $this->duration_unit) . "',"; |
401
|
|
|
$sql .= "note = '" . $this->db->escape($this->note_public) . "',"; |
402
|
|
|
$sql .= "vote = " . (int) $this->db->escape($this->vote) . ","; |
403
|
|
|
$sql .= "mail_valid = '" . $this->db->escape($this->mail_valid) . "'"; |
404
|
|
|
$sql .= " WHERE rowid =" . ((int) $this->id); |
405
|
|
|
|
406
|
|
|
$result = $this->db->query($sql); |
407
|
|
|
if ($result) { |
408
|
|
|
$this->description = $this->db->escape($this->note_public); |
409
|
|
|
|
410
|
|
|
// Multilangs |
411
|
|
|
if (getDolGlobalInt('MAIN_MULTILANGS')) { |
412
|
|
|
if ($this->setMultiLangs($user) < 0) { |
413
|
|
|
$this->error = $langs->trans("Error") . " : " . $this->db->error() . " - " . $sql; |
414
|
|
|
return -2; |
415
|
|
|
} |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
// Actions on extra fields |
419
|
|
|
if (!$error) { |
420
|
|
|
$result = $this->insertExtraFields(); |
421
|
|
|
if ($result < 0) { |
422
|
|
|
$error++; |
423
|
|
|
} |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
if (!$error && !$notrigger) { |
427
|
|
|
// Call trigger |
428
|
|
|
$result = $this->call_trigger('MEMBER_TYPE_MODIFY', $user); |
429
|
|
|
if ($result < 0) { |
430
|
|
|
$error++; |
431
|
|
|
} |
432
|
|
|
// End call triggers |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
if (!$error) { |
436
|
|
|
$this->db->commit(); |
437
|
|
|
return 1; |
438
|
|
|
} else { |
439
|
|
|
$this->db->rollback(); |
440
|
|
|
dol_syslog(get_class($this) . "::update " . $this->error, LOG_ERR); |
441
|
|
|
return -$error; |
442
|
|
|
} |
443
|
|
|
} else { |
444
|
|
|
$this->error = $this->db->lasterror(); |
445
|
|
|
$this->db->rollback(); |
446
|
|
|
return -1; |
447
|
|
|
} |
448
|
|
|
} |
449
|
|
|
|
450
|
|
|
/** |
451
|
|
|
* Function to delete the member's status |
452
|
|
|
* |
453
|
|
|
* @param User $user User making the deletion |
454
|
|
|
* @return int > 0 if OK, 0 if not found, < 0 if KO |
455
|
|
|
*/ |
456
|
|
|
public function delete($user) |
457
|
|
|
{ |
458
|
|
|
$error = 0; |
459
|
|
|
|
460
|
|
|
$sql = "DELETE FROM " . MAIN_DB_PREFIX . "adherent_type"; |
461
|
|
|
$sql .= " WHERE rowid = " . ((int) $this->id); |
462
|
|
|
|
463
|
|
|
$resql = $this->db->query($sql); |
464
|
|
|
if ($resql) { |
465
|
|
|
// Call trigger |
466
|
|
|
$result = $this->call_trigger('MEMBER_TYPE_DELETE', $user); |
467
|
|
|
if ($result < 0) { |
468
|
|
|
$error++; |
469
|
|
|
$this->db->rollback(); |
470
|
|
|
return -2; |
471
|
|
|
} |
472
|
|
|
// End call triggers |
473
|
|
|
|
474
|
|
|
$this->db->commit(); |
475
|
|
|
return 1; |
476
|
|
|
} else { |
477
|
|
|
$this->db->rollback(); |
478
|
|
|
$this->error = $this->db->lasterror(); |
479
|
|
|
return -1; |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Function that retrieves the properties of a membership type |
485
|
|
|
* |
486
|
|
|
* @param int $rowid Id of member type to load |
487
|
|
|
* @return int Return integer <0 if KO, >0 if OK |
488
|
|
|
*/ |
489
|
|
|
public function fetch($rowid) |
490
|
|
|
{ |
491
|
|
|
$sql = "SELECT d.rowid, d.libelle as label, d.morphy, d.statut as status, d.duration, d.subscription, d.amount, d.caneditamount, d.mail_valid, d.note as note_public, d.vote"; |
492
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type as d"; |
493
|
|
|
$sql .= " WHERE d.rowid = " . (int) $rowid; |
494
|
|
|
|
495
|
|
|
dol_syslog("Adherent_type::fetch", LOG_DEBUG); |
496
|
|
|
|
497
|
|
|
$resql = $this->db->query($sql); |
498
|
|
|
if ($resql) { |
499
|
|
|
if ($this->db->num_rows($resql)) { |
500
|
|
|
$obj = $this->db->fetch_object($resql); |
501
|
|
|
|
502
|
|
|
$this->id = $obj->rowid; |
503
|
|
|
$this->ref = $obj->rowid; |
504
|
|
|
$this->label = $obj->label; |
505
|
|
|
$this->morphy = $obj->morphy; |
506
|
|
|
$this->status = $obj->status; |
507
|
|
|
$this->duration = $obj->duration; |
508
|
|
|
$this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1); |
509
|
|
|
$this->duration_unit = substr($obj->duration, -1); |
510
|
|
|
$this->subscription = $obj->subscription; |
511
|
|
|
$this->amount = $obj->amount; |
512
|
|
|
$this->caneditamount = $obj->caneditamount; |
513
|
|
|
$this->mail_valid = $obj->mail_valid; |
514
|
|
|
$this->note = $obj->note_public; // deprecated |
515
|
|
|
$this->note_public = $obj->note_public; |
516
|
|
|
$this->vote = $obj->vote; |
517
|
|
|
|
518
|
|
|
// multilangs |
519
|
|
|
if (getDolGlobalInt('MAIN_MULTILANGS')) { |
520
|
|
|
$this->getMultiLangs(); |
521
|
|
|
} |
522
|
|
|
|
523
|
|
|
// fetch optionals attributes and labels |
524
|
|
|
$this->fetch_optionals(); |
525
|
|
|
return $this->id; |
526
|
|
|
} else { |
527
|
|
|
return 0; |
528
|
|
|
} |
529
|
|
|
} else { |
530
|
|
|
$this->error = $this->db->lasterror(); |
531
|
|
|
return -1; |
532
|
|
|
} |
533
|
|
|
} |
534
|
|
|
|
535
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
536
|
|
|
/** |
537
|
|
|
* Return list of members' type |
538
|
|
|
* |
539
|
|
|
* @param int $status Filter on status of type |
540
|
|
|
* @return array List of types of members |
541
|
|
|
*/ |
542
|
|
|
public function liste_array($status = -1) |
543
|
|
|
{ |
544
|
|
|
// phpcs:enable |
545
|
|
|
global $langs; |
546
|
|
|
|
547
|
|
|
$adherenttypes = array(); |
548
|
|
|
|
549
|
|
|
$sql = "SELECT rowid, libelle as label"; |
550
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type"; |
551
|
|
|
$sql .= " WHERE entity IN (" . getEntity('member_type') . ")"; |
552
|
|
|
if ($status >= 0) { |
553
|
|
|
$sql .= " AND statut = " . ((int) $status); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
$resql = $this->db->query($sql); |
557
|
|
|
if ($resql) { |
558
|
|
|
$nump = $this->db->num_rows($resql); |
559
|
|
|
|
560
|
|
|
if ($nump) { |
561
|
|
|
$i = 0; |
562
|
|
|
while ($i < $nump) { |
563
|
|
|
$obj = $this->db->fetch_object($resql); |
564
|
|
|
|
565
|
|
|
$adherenttypes[$obj->rowid] = $langs->trans($obj->label); |
566
|
|
|
$i++; |
567
|
|
|
} |
568
|
|
|
} |
569
|
|
|
} else { |
570
|
|
|
print $this->db->error(); |
571
|
|
|
} |
572
|
|
|
return $adherenttypes; |
573
|
|
|
} |
574
|
|
|
|
575
|
|
|
/** |
576
|
|
|
* Return the array of all amounts per membership type id |
577
|
|
|
* |
578
|
|
|
* @param int $status Filter on status of type |
579
|
|
|
* @return array Array of membership type |
580
|
|
|
*/ |
581
|
|
|
public function amountByType($status = null) |
582
|
|
|
{ |
583
|
|
|
$amountbytype = array(); |
584
|
|
|
|
585
|
|
|
$sql = "SELECT rowid, amount"; |
586
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent_type"; |
587
|
|
|
$sql .= " WHERE entity IN (" . getEntity('member_type') . ")"; |
588
|
|
|
if ($status !== null) { |
589
|
|
|
$sql .= " AND statut = " . ((int) $status); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
$resql = $this->db->query($sql); |
593
|
|
|
if ($resql) { |
594
|
|
|
$nump = $this->db->num_rows($resql); |
595
|
|
|
|
596
|
|
|
if ($nump) { |
597
|
|
|
$i = 0; |
598
|
|
|
while ($i < $nump) { |
599
|
|
|
$obj = $this->db->fetch_object($resql); |
600
|
|
|
|
601
|
|
|
$amountbytype[$obj->rowid] = $obj->amount; |
602
|
|
|
$i++; |
603
|
|
|
} |
604
|
|
|
} |
605
|
|
|
} else { |
606
|
|
|
print $this->db->error(); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
return $amountbytype; |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Return array of Member objects for member type this->id (or all if this->id not defined) |
614
|
|
|
* |
615
|
|
|
* @param string $excludefilter Filter to exclude. This value must not come from a user input. |
616
|
|
|
* @param int $mode 0=Return array of member instance |
617
|
|
|
* 1=Return array of member instance without extra data |
618
|
|
|
* 2=Return array of members id only |
619
|
|
|
* @return mixed Array of members or -1 on error |
620
|
|
|
*/ |
621
|
|
|
public function listMembersForMemberType($excludefilter = '', $mode = 0) |
622
|
|
|
{ |
623
|
|
|
$ret = array(); |
624
|
|
|
|
625
|
|
|
$sql = "SELECT a.rowid"; |
626
|
|
|
$sql .= " FROM " . MAIN_DB_PREFIX . "adherent as a"; |
627
|
|
|
$sql .= " WHERE a.entity IN (" . getEntity('member') . ")"; |
628
|
|
|
$sql .= " AND a.fk_adherent_type = " . ((int) $this->id); |
629
|
|
|
if (!empty($excludefilter)) { |
630
|
|
|
$sql .= ' AND (' . $excludefilter . ')'; |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
dol_syslog(get_class($this) . "::listMembersForMemberType", LOG_DEBUG); |
634
|
|
|
$resql = $this->db->query($sql); |
635
|
|
|
if ($resql) { |
636
|
|
|
while ($obj = $this->db->fetch_object($resql)) { |
637
|
|
|
if (!array_key_exists($obj->rowid, $ret)) { |
638
|
|
|
if ($mode < 2) { |
639
|
|
|
$memberstatic = new Adherent($this->db); |
640
|
|
|
if ($mode == 1) { |
641
|
|
|
$memberstatic->fetch($obj->rowid, '', '', '', false, false); |
642
|
|
|
} else { |
643
|
|
|
$memberstatic->fetch($obj->rowid); |
644
|
|
|
} |
645
|
|
|
$ret[$obj->rowid] = $memberstatic; |
646
|
|
|
} else { |
647
|
|
|
$ret[$obj->rowid] = $obj->rowid; |
648
|
|
|
} |
649
|
|
|
} |
650
|
|
|
} |
651
|
|
|
|
652
|
|
|
$this->db->free($resql); |
653
|
|
|
|
654
|
|
|
$this->members = $ret; |
655
|
|
|
|
656
|
|
|
return $ret; |
657
|
|
|
} else { |
658
|
|
|
$this->error = $this->db->lasterror(); |
659
|
|
|
return -1; |
660
|
|
|
} |
661
|
|
|
} |
662
|
|
|
|
663
|
|
|
/** |
664
|
|
|
* Return translated label by the nature of a adherent (physical or moral) |
665
|
|
|
* |
666
|
|
|
* @param string $morphy Nature of the adherent (physical or moral) |
667
|
|
|
* @return string Label |
668
|
|
|
*/ |
669
|
|
|
public function getmorphylib($morphy = '') |
670
|
|
|
{ |
671
|
|
|
global $langs; |
672
|
|
|
if ($morphy == 'phy') { |
673
|
|
|
return $langs->trans("Physical"); |
674
|
|
|
} elseif ($morphy == 'mor') { |
675
|
|
|
return $langs->trans("Moral"); |
676
|
|
|
} else { |
677
|
|
|
return $langs->trans("MorAndPhy"); |
678
|
|
|
} |
679
|
|
|
//return $morphy; |
680
|
|
|
} |
681
|
|
|
|
682
|
|
|
/** |
683
|
|
|
* getTooltipContentArray |
684
|
|
|
* @param array $params params to construct tooltip data |
685
|
|
|
* @since v18 |
686
|
|
|
* @return array |
687
|
|
|
*/ |
688
|
|
|
public function getTooltipContentArray($params) |
689
|
|
|
{ |
690
|
|
|
global $langs; |
691
|
|
|
|
692
|
|
|
$langs->load('members'); |
693
|
|
|
|
694
|
|
|
$datas = []; |
695
|
|
|
$datas['picto'] = img_picto('', $this->picto) . ' <u class="paddingrightonly">' . $langs->trans("MemberType") . '</u> ' . $this->getLibStatut(4); |
696
|
|
|
$datas['label'] = '<br>' . $langs->trans("Label") . ': ' . $this->label; |
697
|
|
|
if (isset($this->subscription)) { |
698
|
|
|
$datas['subscription'] = '<br>' . $langs->trans("SubscriptionRequired") . ': ' . yn($this->subscription); |
699
|
|
|
} |
700
|
|
|
if (isset($this->vote)) { |
701
|
|
|
$datas['vote'] = '<br>' . $langs->trans("VoteAllowed") . ': ' . yn($this->vote); |
702
|
|
|
} |
703
|
|
|
if (isset($this->duration)) { |
704
|
|
|
$datas['duration'] = '<br>' . $langs->trans("Duration") . ': ' . $this->duration_value; |
705
|
|
|
if ($this->duration_value > 1) { |
706
|
|
|
$dur = array("i" => $langs->trans("Minutes"), "h" => $langs->trans("Hours"), "d" => $langs->trans("Days"), "w" => $langs->trans("Weeks"), "m" => $langs->trans("Months"), "y" => $langs->trans("Years")); |
707
|
|
|
} elseif ($this->duration_value > 0) { |
708
|
|
|
$dur = array("i" => $langs->trans("Minute"), "h" => $langs->trans("Hour"), "d" => $langs->trans("Day"), "w" => $langs->trans("Week"), "m" => $langs->trans("Month"), "y" => $langs->trans("Year")); |
709
|
|
|
} |
710
|
|
|
$datas['duration'] .= " " . (!empty($this->duration_unit) && isset($dur[$this->duration_unit]) ? $langs->trans($dur[$this->duration_unit]) : ''); |
711
|
|
|
} |
712
|
|
|
|
713
|
|
|
return $datas; |
714
|
|
|
} |
715
|
|
|
|
716
|
|
|
/** |
717
|
|
|
* Return clicable name (with picto eventually) |
718
|
|
|
* |
719
|
|
|
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto |
720
|
|
|
* @param int $maxlen length max label |
721
|
|
|
* @param int $notooltip 1=Disable tooltip |
722
|
|
|
* @param string $morecss Add more css on link |
723
|
|
|
* @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
724
|
|
|
* @return string String with URL |
725
|
|
|
*/ |
726
|
|
|
public function getNomUrl($withpicto = 0, $maxlen = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1) |
727
|
|
|
{ |
728
|
|
|
$result = ''; |
729
|
|
|
$option = ''; |
730
|
|
|
|
731
|
|
|
$classfortooltip = 'classfortooltip'; |
732
|
|
|
$dataparams = ''; |
733
|
|
|
$params = [ |
734
|
|
|
'id' => $this->id, |
735
|
|
|
'objecttype' => $this->element, |
736
|
|
|
'option' => $option, |
737
|
|
|
'nofetch' => 1, |
738
|
|
|
]; |
739
|
|
|
if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) { |
740
|
|
|
$classfortooltip = 'classforajaxtooltip'; |
741
|
|
|
$dataparams = ' data-params="' . dol_escape_htmltag(json_encode($params)) . '"'; |
742
|
|
|
$label = ''; |
743
|
|
|
} else { |
744
|
|
|
$label = implode($this->getTooltipContentArray($params)); |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
$url = constant('BASE_URL') . '/adherents/type.php?rowid=' . ((int) $this->id); |
748
|
|
|
if ($option != 'nolink') { |
749
|
|
|
// Add param to save lastsearch_values or not |
750
|
|
|
$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0); |
751
|
|
|
if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) { |
752
|
|
|
$add_save_lastsearch_values = 1; |
753
|
|
|
} |
754
|
|
|
if ($add_save_lastsearch_values) { |
755
|
|
|
$url .= '&save_lastsearch_values=1'; |
756
|
|
|
} |
757
|
|
|
} |
758
|
|
|
$linkstart = '<a href="' . $url . '"'; |
759
|
|
|
$linkstart .= ($label ? ' title="' . dol_escape_htmltag($label, 1) . '"' : ' title="tocomplete"'); |
760
|
|
|
$linkstart .= $dataparams . ' class="' . $classfortooltip . '">'; |
761
|
|
|
|
762
|
|
|
$linkend = '</a>'; |
763
|
|
|
|
764
|
|
|
$result .= $linkstart; |
765
|
|
|
if ($withpicto) { |
766
|
|
|
$result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (' class="' . (($withpicto != 2) ? 'paddingright' : '') . '"'), 0, 0, $notooltip ? 0 : 1); |
767
|
|
|
} |
768
|
|
|
if ($withpicto != 2) { |
769
|
|
|
$result .= ($maxlen ? dol_trunc($this->label, $maxlen) : $this->label); |
770
|
|
|
} |
771
|
|
|
$result .= $linkend; |
772
|
|
|
|
773
|
|
|
return $result; |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
/** |
777
|
|
|
* Return label of status (activity, closed) |
778
|
|
|
* |
779
|
|
|
* @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto |
780
|
|
|
* @return string Label of status |
781
|
|
|
*/ |
782
|
|
|
public function getLibStatut($mode = 0) |
783
|
|
|
{ |
784
|
|
|
return $this->LibStatut($this->status, $mode); |
785
|
|
|
} |
786
|
|
|
|
787
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
788
|
|
|
/** |
789
|
|
|
* Return the label of a given status |
790
|
|
|
* |
791
|
|
|
* @param int $status Status id |
792
|
|
|
* @param int $mode 0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto |
793
|
|
|
* @return string Status label |
794
|
|
|
*/ |
795
|
|
|
public function LibStatut($status, $mode = 0) |
796
|
|
|
{ |
797
|
|
|
// phpcs:enable |
798
|
|
|
global $langs; |
799
|
|
|
$langs->load('companies'); |
800
|
|
|
|
801
|
|
|
$statusType = 'status4'; |
802
|
|
|
if ($status == 0) { |
803
|
|
|
$statusType = 'status5'; |
804
|
|
|
} |
805
|
|
|
|
806
|
|
|
if (empty($this->labelStatus) || empty($this->labelStatusShort)) { |
807
|
|
|
$this->labelStatus[0] = $langs->transnoentitiesnoconv("ActivityCeased"); |
808
|
|
|
$this->labelStatus[1] = $langs->transnoentitiesnoconv("InActivity"); |
809
|
|
|
$this->labelStatusShort[0] = $langs->transnoentitiesnoconv("ActivityCeased"); |
810
|
|
|
$this->labelStatusShort[1] = $langs->transnoentitiesnoconv("InActivity"); |
811
|
|
|
} |
812
|
|
|
|
813
|
|
|
return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); |
814
|
|
|
} |
815
|
|
|
|
816
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
817
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
818
|
|
|
/** |
819
|
|
|
* Retourne chaine DN complete dans l'annuaire LDAP pour l'objet |
820
|
|
|
* |
821
|
|
|
* @param array $info Info array loaded by _load_ldap_info |
822
|
|
|
* @param int $mode 0=Return full DN (uid=qqq,ou=xxx,dc=aaa,dc=bbb) |
823
|
|
|
* 1=Return DN without key inside (ou=xxx,dc=aaa,dc=bbb) |
824
|
|
|
* 2=Return key only (uid=qqq) |
825
|
|
|
* @return string DN |
826
|
|
|
*/ |
827
|
|
|
public function _load_ldap_dn($info, $mode = 0) |
828
|
|
|
{ |
829
|
|
|
// phpcs:enable |
830
|
|
|
$dn = ''; |
831
|
|
|
if ($mode == 0) { |
832
|
|
|
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=" . $info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')] . "," . getDolGlobalString('LDAP_MEMBER_TYPE_DN'); |
833
|
|
|
} |
834
|
|
|
if ($mode == 1) { |
835
|
|
|
$dn = getDolGlobalString('LDAP_MEMBER_TYPE_DN'); |
836
|
|
|
} |
837
|
|
|
if ($mode == 2) { |
838
|
|
|
$dn = getDolGlobalString('LDAP_KEY_MEMBERS_TYPES') . "=" . $info[getDolGlobalString('LDAP_KEY_MEMBERS_TYPES')]; |
839
|
|
|
} |
840
|
|
|
return $dn; |
841
|
|
|
} |
842
|
|
|
|
843
|
|
|
|
844
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps |
845
|
|
|
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore |
846
|
|
|
/** |
847
|
|
|
* Initialize the info array (array of LDAP values) that will be used to call LDAP functions |
848
|
|
|
* |
849
|
|
|
* @return array Tableau info des attributes |
850
|
|
|
*/ |
851
|
|
|
public function _load_ldap_info() |
852
|
|
|
{ |
853
|
|
|
// phpcs:enable |
854
|
|
|
$info = array(); |
855
|
|
|
|
856
|
|
|
// Object classes |
857
|
|
|
$info["objectclass"] = explode(',', getDolGlobalString('LDAP_MEMBER_TYPE_OBJECT_CLASS')); |
858
|
|
|
|
859
|
|
|
if (empty($this->note_public) && !empty($this->note)) { // For backward compatibility |
860
|
|
|
$this->note_public = $this->note; |
861
|
|
|
} |
862
|
|
|
|
863
|
|
|
// Champs |
864
|
|
|
if ($this->label && getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME')) { |
865
|
|
|
$info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_FULLNAME')] = $this->label; |
866
|
|
|
} |
867
|
|
|
if ($this->note_public && getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')) { |
868
|
|
|
$info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_DESCRIPTION')] = dol_string_nohtmltag($this->note_public, 0, 'UTF-8', 1); |
869
|
|
|
} |
870
|
|
|
if (getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')) { |
871
|
|
|
$valueofldapfield = array(); |
872
|
|
|
foreach ($this->members as $key => $val) { // This is array of users for group into dolibarr database. |
873
|
|
|
$member = new Adherent($this->db); |
874
|
|
|
$member->fetch($val->id, '', '', '', false, false); |
875
|
|
|
$info2 = $member->_load_ldap_info(); |
876
|
|
|
$valueofldapfield[] = $member->_load_ldap_dn($info2); |
877
|
|
|
} |
878
|
|
|
$info[getDolGlobalString('LDAP_MEMBER_TYPE_FIELD_GROUPMEMBERS')] = (!empty($valueofldapfield) ? $valueofldapfield : ''); |
879
|
|
|
} |
880
|
|
|
return $info; |
881
|
|
|
} |
882
|
|
|
|
883
|
|
|
/** |
884
|
|
|
* Initialise an instance with random values. |
885
|
|
|
* Used to build previews or test instances. |
886
|
|
|
* id must be 0 if object instance is a specimen. |
887
|
|
|
* |
888
|
|
|
* @return int |
889
|
|
|
*/ |
890
|
|
|
public function initAsSpecimen() |
891
|
|
|
{ |
892
|
|
|
global $user; |
893
|
|
|
|
894
|
|
|
// Initialise parameters |
895
|
|
|
$this->id = 0; |
896
|
|
|
$this->ref = 'MTSPEC'; |
897
|
|
|
$this->specimen = 1; |
898
|
|
|
|
899
|
|
|
$this->label = 'MEMBERS TYPE SPECIMEN'; |
900
|
|
|
$this->note_public = 'This is a public note'; |
901
|
|
|
$this->mail_valid = 'This is welcome email'; |
902
|
|
|
$this->subscription = 1; |
903
|
|
|
$this->caneditamount = 0; |
904
|
|
|
$this->vote = 0; |
905
|
|
|
|
906
|
|
|
$this->status = 1; |
907
|
|
|
|
908
|
|
|
// Members of this member type is just me |
909
|
|
|
$this->members = array( |
910
|
|
|
$user->id => $user |
911
|
|
|
); |
912
|
|
|
|
913
|
|
|
return 1; |
914
|
|
|
} |
915
|
|
|
|
916
|
|
|
/** |
917
|
|
|
* getMailOnValid |
918
|
|
|
* |
919
|
|
|
* @return string Return mail content of type or empty |
920
|
|
|
*/ |
921
|
|
|
public function getMailOnValid() |
922
|
|
|
{ |
923
|
|
|
if (!empty($this->mail_valid) && trim(dol_htmlentitiesbr_decode($this->mail_valid))) { |
924
|
|
|
return $this->mail_valid; |
925
|
|
|
} |
926
|
|
|
|
927
|
|
|
return ''; |
928
|
|
|
} |
929
|
|
|
|
930
|
|
|
/** |
931
|
|
|
* getMailOnSubscription |
932
|
|
|
* |
933
|
|
|
* @return string Return mail content of type or empty |
934
|
|
|
*/ |
935
|
|
|
public function getMailOnSubscription() |
936
|
|
|
{ |
937
|
|
|
// mail_subscription not defined so never used |
938
|
|
|
if (!empty($this->mail_subscription) && trim(dol_htmlentitiesbr_decode($this->mail_subscription))) { // Property not yet defined |
939
|
|
|
return $this->mail_subscription; |
940
|
|
|
} |
941
|
|
|
|
942
|
|
|
return ''; |
943
|
|
|
} |
944
|
|
|
|
945
|
|
|
/** |
946
|
|
|
* getMailOnResiliate |
947
|
|
|
* |
948
|
|
|
* @return string Return mail model content of type or empty |
949
|
|
|
*/ |
950
|
|
|
public function getMailOnResiliate() |
951
|
|
|
{ |
952
|
|
|
// NOTE mail_resiliate not defined so never used |
953
|
|
|
if (!empty($this->mail_resiliate) && trim(dol_htmlentitiesbr_decode($this->mail_resiliate))) { // Property not yet defined |
954
|
|
|
return $this->mail_resiliate; |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
return ''; |
958
|
|
|
} |
959
|
|
|
|
960
|
|
|
/** |
961
|
|
|
* getMailOnExclude |
962
|
|
|
* |
963
|
|
|
* @return string Return mail model content of type or empty |
964
|
|
|
*/ |
965
|
|
|
public function getMailOnExclude() |
966
|
|
|
{ |
967
|
|
|
// NOTE mail_exclude not defined so never used |
968
|
|
|
if (!empty($this->mail_exclude) && trim(dol_htmlentitiesbr_decode($this->mail_exclude))) { // Property not yet defined |
969
|
|
|
return $this->mail_exclude; |
970
|
|
|
} |
971
|
|
|
|
972
|
|
|
return ''; |
973
|
|
|
} |
974
|
|
|
|
975
|
|
|
|
976
|
|
|
/** |
977
|
|
|
* Return clicable link of object (with eventually picto) |
978
|
|
|
* |
979
|
|
|
* @param string $option Where point the link (0=> main card, 1,2 => shipment, 'nolink'=>No link) |
980
|
|
|
* @param array $arraydata Array of data |
981
|
|
|
* @return string HTML Code for Kanban thumb. |
982
|
|
|
*/ |
983
|
|
|
public function getKanbanView($option = '', $arraydata = null) |
984
|
|
|
{ |
985
|
|
|
global $langs, $user; |
986
|
|
|
|
987
|
|
|
//$selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']); |
988
|
|
|
|
989
|
|
|
$return = '<div class="box-flex-item box-flex-grow-zero">'; |
990
|
|
|
$return .= '<div class="info-box info-box-sm">'; |
991
|
|
|
$return .= '<span class="info-box-icon bg-infobox-action">'; |
992
|
|
|
$return .= img_picto('', $this->picto); |
993
|
|
|
$return .= '</span>'; |
994
|
|
|
$return .= '<div class="info-box-content">'; |
995
|
|
|
$return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">' . (method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref) . '</span>'; |
996
|
|
|
|
997
|
|
|
//$return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>'; |
998
|
|
|
|
999
|
|
|
if ($user->hasRight('adherent', 'configurer')) { |
1000
|
|
|
$return .= '<span class="right paddingleft"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=edit&rowid=' . urlencode($this->ref) . '">' . img_edit() . '</a></span>'; |
1001
|
|
|
} else { |
1002
|
|
|
$return .= '<span class="right"> </span>'; |
1003
|
|
|
} |
1004
|
|
|
if (property_exists($this, 'vote')) { |
1005
|
|
|
$return .= '<br><span class="info-box-label opacitymedium">' . $langs->trans("VoteAllowed") . ' : ' . yn($this->vote) . '</span>'; |
1006
|
|
|
} |
1007
|
|
|
if (property_exists($this, 'amount')) { |
1008
|
|
|
if (is_null($this->amount) || $this->amount === '') { |
1009
|
|
|
$return .= '<br>'; |
1010
|
|
|
} else { |
1011
|
|
|
$return .= '<br><span class="info-box-label opacitymedium">' . $langs->trans("Amount") . '</span>'; |
1012
|
|
|
$return .= '<span class="amount"> : ' . price($this->amount) . '</span>'; |
1013
|
|
|
} |
1014
|
|
|
} |
1015
|
|
|
if (method_exists($this, 'getLibStatut')) { |
1016
|
|
|
$return .= '<br><div class="info-box-status">' . $this->getLibStatut(3) . '</div>'; |
1017
|
|
|
} |
1018
|
|
|
$return .= '</div>'; |
1019
|
|
|
$return .= '</div>'; |
1020
|
|
|
$return .= '</div>'; |
1021
|
|
|
return $return; |
1022
|
|
|
} |
1023
|
|
|
} |
1024
|
|
|
|