dolibarr  18.0.6
subscription.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2012-2017 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
7  * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
8  * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  */
23 
30 // Load Dolibarr environment
31 require '../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
41 
42 $langs->loadLangs(array("companies", "bills", "members", "users", "mails", 'other'));
43 
44 $action = GETPOST('action', 'aZ09');
45 $confirm = GETPOST('confirm', 'alpha');
46 $contextpage = GETPOST('contextpage', 'aZ09');
47 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
48 
49 $id = GETPOST('rowid', 'int') ? GETPOST('rowid', 'int') : GETPOST('id', 'int');
50 $rowid = $id;
51 $ref = GETPOST('ref', 'alphanohtml');
52 $typeid = GETPOST('typeid', 'int');
53 $cancel = GETPOST('cancel');
54 
55 // Load variable for pagination
56 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST('sortfield', 'aZ09comma');
58 $sortorder = GETPOST('sortorder', 'aZ09comma');
59 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
60 if (empty($page) || $page == -1) {
61  $page = 0;
62 } // If $page is not defined, or '' or -1
63 $offset = $limit * $page;
64 $pageprev = $page - 1;
65 $pagenext = $page + 1;
66 
67 // Default sort order (if not yet defined by previous GETPOST)
68 if (!$sortfield) {
69  $sortfield = "c.rowid";
70 }
71 if (!$sortorder) {
72  $sortorder = "DESC";
73 }
74 
75 $object = new Adherent($db);
76 $extrafields = new ExtraFields($db);
77 $adht = new AdherentType($db);
78 
79 // fetch optionals attributes and labels
80 $extrafields->fetch_name_optionals_label($object->table_element);
81 
82 $errmsg = '';
83 
84 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
85 $hookmanager->initHooks(array('subscription'));
86 
87 // PDF
88 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
89 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
90 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
91 
92 $datefrom = 0;
93 $dateto = 0;
94 $paymentdate = -1;
95 
96 // Fetch object
97 if ($id > 0 || !empty($ref)) {
98  // Load member
99  $result = $object->fetch($id, $ref);
100 
101  // Define variables to know what current user can do on users
102  $canadduser = ($user->admin || $user->hasRight("user", "user", "creer"));
103  // Define variables to know what current user can do on properties of user linked to edited member
104  if ($object->user_id) {
105  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
106  $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer"))
107  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer")));
108  $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password"))
109  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password")));
110  }
111 }
112 
113 // Define variables to determine what the current user can do on the members
114 $canaddmember = $user->hasRight('adherent', 'creer');
115 // Define variables to determine what the current user can do on the properties of a member
116 if ($id) {
117  $caneditfieldmember = $user->hasRight('adherent', 'creer');
118 }
119 
120 // Security check
121 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
122 
123 
124 /*
125  * Actions
126  */
127 
128 $parameters = array();
129 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
130 if ($reshook < 0) {
131  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
132 }
133 
134 // Create third party from a member
135 if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
136  if ($result > 0) {
137  // Creation of thirdparty
138  $company = new Societe($db);
139  $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
140 
141  if ($result < 0) {
142  $langs->load("errors");
143  setEventMessages($company->error, $company->errors, 'errors');
144  } else {
145  $action = 'addsubscription';
146  }
147  } else {
148  setEventMessages($object->error, $object->errors, 'errors');
149  }
150 }
151 
152 if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) {
153  $error = 0;
154  if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only
155  if (GETPOST("userid", 'int') != $user->id && GETPOST("userid", 'int') != $object->user_id) {
156  $error++;
157  setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
158  }
159  }
160 
161  if (!$error) {
162  if (GETPOST("userid", 'int') != $object->user_id) { // If link differs from currently in database
163  $result = $object->setUserId(GETPOST("userid", 'int'));
164  if ($result < 0) {
165  dol_print_error('', $object->error);
166  }
167  $action = '';
168  }
169  }
170 }
171 
172 if (empty($reshook) && $action == 'setsocid') {
173  $error = 0;
174  if (!$error) {
175  if (GETPOST('socid', 'int') != $object->fk_soc) { // If link differs from currently in database
176  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
177  $sql .= " WHERE fk_soc = '".GETPOST('socid', 'int')."'";
178  $resql = $db->query($sql);
179  if ($resql) {
180  $obj = $db->fetch_object($resql);
181  if ($obj && $obj->rowid > 0) {
182  $othermember = new Adherent($db);
183  $othermember->fetch($obj->rowid);
184  $thirdparty = new Societe($db);
185  $thirdparty->fetch(GETPOST('socid', 'int'));
186  $error++;
187  setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
188  }
189  }
190 
191  if (!$error) {
192  $result = $object->setThirdPartyId(GETPOST('socid', 'int'));
193  if ($result < 0) {
194  dol_print_error('', $object->error);
195  }
196  $action = '';
197  }
198  }
199  }
200 }
201 
202 if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) {
203  $error = 0;
204 
205  $langs->load("banks");
206 
207  $result = $object->fetch($rowid);
208  $result = $adht->fetch($object->typeid);
209 
210  // Subscription informations
211  $datesubscription = 0;
212  $datesubend = 0;
213  $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
214  $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
215  $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01
216  if (GETPOST("reyear", "int") && GETPOST("remonth", "int") && GETPOST("reday", "int")) {
217  $datesubscription = dol_mktime(0, 0, 0, GETPOST("remonth", "int"), GETPOST("reday", "int"), GETPOST("reyear", "int"));
218  }
219  if (GETPOST("endyear", 'int') && GETPOST("endmonth", 'int') && GETPOST("endday", 'int')) {
220  $datesubend = dol_mktime(0, 0, 0, GETPOST("endmonth", 'int'), GETPOST("endday", 'int'), GETPOST("endyear", 'int'));
221  }
222  if (GETPOST("paymentyear", 'int') && GETPOST("paymentmonth", 'int') && GETPOST("paymentday", 'int')) {
223  $paymentdate = dol_mktime(0, 0, 0, GETPOST("paymentmonth", 'int'), GETPOST("paymentday", 'int'), GETPOST("paymentyear", 'int'));
224  }
225  $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
226  $label = GETPOST("label");
227 
228  // Payment informations
229  $accountid = GETPOST("accountid", 'int');
230  $operation = GETPOST("operation", "alphanohtml"); // Payment mode
231  $num_chq = GETPOST("num_chq", "alphanohtml");
232  $emetteur_nom = GETPOST("chqemetteur");
233  $emetteur_banque = GETPOST("chqbank");
234  $option = GETPOST("paymentsave");
235  if (empty($option)) {
236  $option = 'none';
237  }
238  $sendalsoemail = GETPOST("sendmail", 'alpha');
239 
240  // Check parameters
241  if (!$datesubscription) {
242  $error++;
243  $langs->load("errors");
244  $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
245  setEventMessages($errmsg, null, 'errors');
246  $action = 'addsubscription';
247  }
248  if (GETPOST('end') && !$datesubend) {
249  $error++;
250  $langs->load("errors");
251  $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
252  setEventMessages($errmsg, null, 'errors');
253  $action = 'addsubscription';
254  }
255  if (!$datesubend) {
256  $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
257  }
258  if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) {
259  $error++;
260  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
261  setEventMessages($errmsg, null, 'errors');
262  $action = 'addsubscription';
263  }
264 
265  // Check if a payment is mandatory or not
266  if ($adht->subscription) { // Member type need subscriptions
267  if (!is_numeric($amount)) {
268  // If field is '' or not a numeric value
269  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
270  setEventMessages($errmsg, null, 'errors');
271  $error++;
272  $action = 'addsubscription';
273  } else {
274  // If an amount has been provided, we check also fields that becomes mandatory when amount is not null.
275  if (isModEnabled('banque') && GETPOST("paymentsave") != 'none') {
276  if (GETPOST("subscription")) {
277  if (!GETPOST("label")) {
278  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
279  setEventMessages($errmsg, null, 'errors');
280  $error++;
281  $action = 'addsubscription';
282  }
283  if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation")) {
284  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
285  setEventMessages($errmsg, null, 'errors');
286  $error++;
287  $action = 'addsubscription';
288  }
289  if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOST("accountid", 'int') > 0)) {
290  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
291  setEventMessages($errmsg, null, 'errors');
292  $error++;
293  $action = 'addsubscription';
294  }
295  } else {
296  if (GETPOST("accountid", 'int')) {
297  $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
298  setEventMessages($errmsg, null, 'errors');
299  $error++;
300  $action = 'addsubscription';
301  }
302  }
303  }
304  }
305  }
306 
307  // Record the subscription then complementary actions
308  if (!$error && $action == 'subscription') {
309  $db->begin();
310 
311  // Create subscription
312  $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
313  if ($crowid <= 0) {
314  $error++;
315  $errmsg = $object->error;
316  setEventMessages($object->error, $object->errors, 'errors');
317  }
318 
319  if (!$error) {
320  $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
321  if ($result < 0) {
322  $error++;
323  setEventMessages($object->error, $object->errors, 'errors');
324  } else {
325  // If an invoice was created, it is into $object->invoice
326  }
327  }
328 
329  if (!$error) {
330  $db->commit();
331  } else {
332  $db->rollback();
333  $action = 'addsubscription';
334  }
335 
336  if (!$error) {
337  setEventMessages("SubscriptionRecorded", null, 'mesgs');
338  }
339 
340  // Send email
341  if (!$error) {
342  // Send confirmation Email
343  if ($object->email && $sendalsoemail) { // $object is 'Adherent'
344  $parameters = array(
345  'datesubscription' => $datesubscription,
346  'amount' => $amount,
347  'ccountid' => $accountid,
348  'operation' => $operation,
349  'label' => $label,
350  'num_chq' => $num_chq,
351  'emetteur_nom' => $emetteur_nom,
352  'emetteur_banque' => $emetteur_banque,
353  'datesubend' => $datesubend
354  );
355  $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
356  if ($reshook < 0) {
357  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
358  }
359 
360  if (empty($reshook)) {
361  $subject = '';
362  $msg = '';
363 
364  // Send subscription email
365  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
366  $formmail = new FormMail($db);
367  // Set output language
368  $outputlangs = new Translate('', $conf);
369  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
370  // Load traductions files required by page
371  $outputlangs->loadLangs(array("main", "members"));
372 
373  // Get email content from template
374  $arraydefaultmessage = null;
375  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
376 
377  if (!empty($labeltouse)) {
378  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
379  }
380 
381  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
382  $subject = $arraydefaultmessage->topic;
383  $msg = $arraydefaultmessage->content;
384  }
385 
386  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
387  complete_substitutions_array($substitutionarray, $outputlangs, $object);
388  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
389  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
390 
391  // Attach a file ?
392  $file = '';
393  $listofpaths = array();
394  $listofnames = array();
395  $listofmimes = array();
396  if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
397  $invoicediroutput = $conf->facture->dir_output;
398  $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
399  $file = $fileparams['fullname'];
400 
401  $listofpaths = array($file);
402  $listofnames = array(basename($file));
403  $listofmimes = array(dol_mimetype($file));
404  }
405 
406  $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
407 
408  $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
409  if ($result < 0) {
410  $errmsg = $object->error;
411  setEventMessages($object->error, $object->errors, 'errors');
412  } else {
413  setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
414  }
415  }
416  } else {
417  setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
418  }
419  }
420 
421  // Clean some POST vars
422  if (!$error) {
423  $_POST["subscription"] = '';
424  $_POST["accountid"] = '';
425  $_POST["operation"] = '';
426  $_POST["label"] = '';
427  $_POST["num_chq"] = '';
428  }
429  }
430 }
431 
432 
433 
434 /*
435  * View
436  */
437 
438 $form = new Form($db);
439 
440 $now = dol_now();
441 
442 $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
443 
444 $help_url = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder";
445 
446 llxHeader("", $title, $help_url);
447 
448 
449 $param = '';
450 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
451  $param .= '&contextpage='.urlencode($contextpage);
452 }
453 if ($limit > 0 && $limit != $conf->liste_limit) {
454  $param .= '&limit='.((int) $limit);
455 }
456 $param .= '&id='.$rowid;
457 if ($optioncss != '') {
458  $param .= '&optioncss='.urlencode($optioncss);
459 }
460 // Add $param from extra fields
461 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
462 
463 
464 if (! ($object->id > 0)) {
465  $langs->load("errors");
466  print $langs->trans("ErrorRecordNotFound");
467 }
468 
469 /*$res = $object->fetch($rowid);
470  if ($res < 0) {
471  dol_print_error($db, $object->error);
472  exit;
473  }
474 */
475 
476 $adht->fetch($object->typeid);
477 
478 $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
479 $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
480 
481 $head = member_prepare_head($object);
482 
483 $rowspan = 10;
484 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
485  $rowspan++;
486 }
487 if (isModEnabled('societe')) {
488  $rowspan++;
489 }
490 
491 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
492 print '<input type="hidden" name="token" value="'.newToken().'">';
493 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
494 
495 print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
496 
497 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
498 
499 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
500 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
501 $morehtmlref .= '</a>';
502 
503 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
504 
505 print '<div class="fichecenter">';
506 print '<div class="fichehalfleft">';
507 
508 print '<div class="underbanner clearboth"></div>';
509 print '<table class="border centpercent tableforfield">';
510 
511 // Login
512 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
513  print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
514 }
515 
516 // Type
517 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
518 print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
519 
520 // Morphy
521 print '<tr><td>'.$langs->trans("MemberNature").'</td>';
522 print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
523 print '</tr>';
524 
525 // Company
526 print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
527 
528 // Civility
529 print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
530 print '</tr>';
531 
532 // Password
533 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
534  print '<tr><td>'.$langs->trans("Password").'</td><td>';
535  if ($object->pass) {
536  print preg_replace('/./i', '*', $object->pass);
537  } else {
538  if ($user->admin) {
539  print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
540  }
541  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
542  }
543  if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
544  $langs->load("errors");
545  $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
546  print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
547  }
548  print '</td></tr>';
549 }
550 
551 // Date end subscription
552 print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
553 if ($object->datefin) {
554  print dol_print_date($object->datefin, 'day');
555  if ($object->hasDelay()) {
556  print " ".img_warning($langs->trans("Late"));
557  }
558 } else {
559  if ($object->need_subscription == 0) {
560  print $langs->trans("SubscriptionNotNeeded");
561  } elseif (!$adht->subscription) {
562  print $langs->trans("SubscriptionNotRecorded");
563  if (Adherent::STATUS_VALIDATED == $object->statut) {
564  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
565  }
566  } else {
567  print $langs->trans("SubscriptionNotReceived");
568  if (Adherent::STATUS_VALIDATED == $object->statut) {
569  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
570  }
571  }
572 }
573 print '</td></tr>';
574 
575 print '</table>';
576 
577 print '</div>';
578 
579 print '<div class="fichehalfright">';
580 print '<div class="underbanner clearboth"></div>';
581 
582 print '<table class="border tableforfield centpercent">';
583 
584 // Tags / Categories
585 if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
586  print '<tr><td>'.$langs->trans("Categories").'</td>';
587  print '<td colspan="2">';
588  print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
589  print '</td></tr>';
590 }
591 
592 // Birth Date
593 print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
594 
595 // Default language
596 if (getDolGlobalInt('MAIN_MULTILANGS')) {
597  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
598  print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
599  //$s=picto_from_langcode($object->default_lang);
600  //print ($s?$s.' ':'');
601  $langs->load("languages");
602  $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
603  print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
604  print $labellang;
605  print '</td></tr>';
606 }
607 
608 // Public
609 $linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : '');
610 print '<tr><td>'.$langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist).'</td><td class="valeur">'.yn($object->public).'</td></tr>';
611 
612 // Other attributes
613 $cols = 2;
614 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
615 
616 // Third party Dolibarr
617 if (isModEnabled('societe')) {
618  print '<tr><td>';
619  print '<table class="nobordernopadding" width="100%"><tr><td>';
620  print $langs->trans("LinkedToDolibarrThirdParty");
621  print '</td>';
622  if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) {
623  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'</a></td>';
624  }
625  print '</tr></table>';
626  print '</td><td colspan="2" class="valeur">';
627  if ($action == 'editthirdparty') {
628  $htmlname = 'socid';
629  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
630  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
631  print '<input type="hidden" name="action" value="set'.$htmlname.'">';
632  print '<input type="hidden" name="token" value="'.newToken().'">';
633  print '<table class="nobordernopadding">';
634  print '<tr><td>';
635  print $form->select_company($object->fk_soc, 'socid', '', 1);
636  print '</td>';
637  print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
638  print '</tr></table></form>';
639  } else {
640  if ($object->fk_soc) {
641  $company = new Societe($db);
642  $result = $company->fetch($object->fk_soc);
643  print $company->getNomUrl(1);
644 
645  // Show link to invoices
646  $tmparray = $company->getOutstandingBills('customer');
647  if (!empty($tmparray['refs'])) {
648  print ' - '.img_picto($langs->trans("Invoices"), 'bill', 'class="paddingright"').'<a href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->socid.'">'.$langs->trans("Invoices").' ('.count($tmparray['refs']).')';
649  // TODO Add alert if warning on at least one invoice late
650  print '</a>';
651  }
652  } else {
653  print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
654  }
655  }
656  print '</td></tr>';
657 }
658 
659 // Login Dolibarr - Link to user
660 print '<tr><td>';
661 print '<table class="nobordernopadding" width="100%"><tr><td>';
662 print $langs->trans("LinkedToDolibarrUser");
663 print '</td>';
664 if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) {
665  print '<td class="right">';
666  if ($user->hasRight("user", "user", "creer")) {
667  print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
668  }
669  print '</td>';
670 }
671 print '</tr></table>';
672 print '</td><td colspan="2" class="valeur">';
673 if ($action == 'editlogin') {
674  $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
675 } else {
676  if ($object->user_id) {
677  $linkeduser = new User($db);
678  $linkeduser->fetch($object->user_id);
679  print $linkeduser->getNomUrl(-1);
680  } else {
681  print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
682  }
683 }
684 print '</td></tr>';
685 
686 print "</table>\n";
687 
688 print "</div></div>\n";
689 print '<div class="clearboth"></div>';
690 
691 print dol_get_fiche_end();
692 
693 
694 /*
695  * Action bar
696  */
697 
698 // Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2)
699 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
700  if ($action != 'addsubscription' && $action != 'create_thirdparty') {
701  print '<div class="tabsAction">';
702 
703  if ($object->statut > 0) {
704  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription&token='.newToken().'">'.$langs->trans("AddSubscription")."</a></div>";
705  } else {
706  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
707  }
708 
709  print '</div>';
710  }
711 }
712 
713 /*
714  * List of subscriptions
715  */
716 if ($action != 'addsubscription' && $action != 'create_thirdparty') {
717  $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
718  $sql .= " c.rowid as crowid, c.subscription,";
719  $sql .= " c.datec, c.fk_type as cfk_type,";
720  $sql .= " c.dateadh as dateh,";
721  $sql .= " c.datef,";
722  $sql .= " c.fk_bank,";
723  $sql .= " b.rowid as bid,";
724  $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
725  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
726  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
727  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
728  $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid);
729  $sql .= $db->order($sortfield, $sortorder);
730 
731  $result = $db->query($sql);
732  if ($result) {
733  $subscriptionstatic = new Subscription($db);
734 
735  $num = $db->num_rows($result);
736 
737  print '<table class="noborder centpercent">'."\n";
738 
739  print '<tr class="liste_titre">';
740  print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
741  print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
742  print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
743  print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
744  print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
745  print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
746  if (isModEnabled('banque')) {
747  print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
748  }
749  print "</tr>\n";
750 
751  $accountstatic = new Account($db);
752  $adh = new Adherent($db);
753  $adht = new AdherentType($db);
754 
755  $i = 0;
756  while ($i < $num) {
757  $objp = $db->fetch_object($result);
758 
759  $adh->id = $objp->rowid;
760  $adh->typeid = $objp->type;
761 
762  $subscriptionstatic->ref = $objp->crowid;
763  $subscriptionstatic->id = $objp->crowid;
764 
765  $typeid = $objp->cfk_type;
766  if ($typeid > 0) {
767  $adht->fetch($typeid);
768  }
769 
770  print '<tr class="oddeven">';
771  print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
772  print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
773  print '<td class="center">';
774  if ($typeid > 0) {
775  print $adht->getNomUrl(1);
776  }
777  print '</td>';
778  print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
779  print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
780  print '<td class="right amount">'.price($objp->subscription).'</td>';
781  if (isModEnabled('banque')) {
782  print '<td class="right">';
783  if ($objp->bid) {
784  $accountstatic->label = $objp->label;
785  $accountstatic->id = $objp->baid;
786  $accountstatic->number = $objp->number;
787  $accountstatic->account_number = $objp->account_number;
788  $accountstatic->currency_code = $objp->currency_code;
789 
790  if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) {
791  $accountingjournal = new AccountingJournal($db);
792  $accountingjournal->fetch($objp->fk_accountancy_journal);
793 
794  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
795  }
796 
797  $accountstatic->ref = $objp->ref;
798  print $accountstatic->getNomUrl(1);
799  } else {
800  print '&nbsp;';
801  }
802  print '</td>';
803  }
804  print "</tr>";
805  $i++;
806  }
807 
808  if (empty($num)) {
809  $colspan = 6;
810  if (isModEnabled('banque')) {
811  $colspan++;
812  }
813  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
814  }
815 
816  print "</table>";
817  } else {
818  dol_print_error($db);
819  }
820 }
821 
822 
823 if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
824  // Shon online payment link
825  $useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
826 
827  if ($useonlinepayment) {
828  print '<br>';
829 
830  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
831  print showOnlinePaymentUrl('membersubscription', $object->ref);
832  print '<br>';
833  }
834 }
835 
836 /*
837  * Add new subscription form
838  */
839 if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->hasRight('adherent', 'cotisation', 'creer')) {
840  print '<br>';
841 
842  print load_fiche_titre($langs->trans("NewCotisation"));
843 
844  // Define default choice for complementary actions
845  $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
846  $invoiceonly = 0; // 1 means option by default is invoice only
847  $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
848  if (GETPOST('paymentsave')) {
849  if (GETPOST('paymentsave') == 'bankdirect') {
850  $bankdirect = 1;
851  }
852  if (GETPOST('paymentsave') == 'invoiceonly') {
853  $invoiceonly = 1;
854  }
855  if (GETPOST('paymentsave') == 'bankviainvoice') {
856  $bankviainvoice = 1;
857  }
858  } else {
859  if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
860  $bankviainvoice = 1;
861  } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && isModEnabled('banque')) {
862  $bankdirect = 1;
863  } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
864  $invoiceonly = 1;
865  }
866  }
867 
868  print "\n\n<!-- Form add subscription -->\n";
869 
870  if ($conf->use_javascript_ajax) {
871  //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
872  print "\n".'<script type="text/javascript">';
873  print '$(document).ready(function () {
874  $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
875  $("#none, #invoiceonly").click(function() {
876  $(".bankswitchclass").hide();
877  $(".bankswitchclass2").hide();
878  });
879  $("#bankdirect, #bankviainvoice").click(function() {
880  $(".bankswitchclass").show();
881  $(".bankswitchclass2").show();
882  });
883  $("#selectoperation").change(function() {
884  var code = $(this).val();
885  if (code == "CHQ")
886  {
887  $(".fieldrequireddyn").addClass("fieldrequired");
888  if ($("#fieldchqemetteur").val() == "")
889  {
890  $("#fieldchqemetteur").val($("#memberlabel").val());
891  }
892  }
893  else
894  {
895  $(".fieldrequireddyn").removeClass("fieldrequired");
896  }
897  });
898  ';
899  if (GETPOST('paymentsave')) {
900  print '$("#'.GETPOST('paymentsave', 'aZ09').'").prop("checked", true);';
901  }
902  print '});';
903  print '</script>'."\n";
904  }
905 
906 
907  // Confirm create third party
908  if ($action == 'create_thirdparty') {
909  $companyalias = '';
910  $fullname = $object->getFullName($langs);
911 
912  if ($object->morphy == 'mor') {
913  $companyname = $object->company;
914  if (!empty($fullname)) {
915  $companyalias = $fullname;
916  }
917  } else {
918  $companyname = $fullname;
919  if (!empty($object->company)) {
920  $companyalias = $object->company;
921  }
922  }
923 
924  // Create a form array
925  $formquestion = array(
926  array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
927  array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
928  );
929  // If customer code was forced to "required", we ask it at creation to avoid error later
930  if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
931  $tmpcompany = new Societe($db);
932  $tmpcompany->name = $companyname;
933  $tmpcompany->get_codeclient($tmpcompany, 0);
934  $customercode = $tmpcompany->code_client;
935  $formquestion[] = array(
936  'label' => $langs->trans("CustomerCode"),
937  'type' => 'text',
938  'name' => 'customercode',
939  'value' => $customercode,
940  'morecss' => 'minwidth300',
941  'moreattr' => 'maxlength="128"',
942  );
943  }
944  // @todo Add other extrafields mandatory for thirdparty creation
945 
946  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
947  }
948 
949 
950  print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
951  print '<input type="hidden" name="token" value="'.newToken().'">';
952  print '<input type="hidden" name="action" value="subscription">';
953  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
954  print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
955  print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
956 
957  print dol_get_fiche_head('');
958 
959  print '<div class="div-table-responsive">';
960  print '<table class="border centpercent">'."\n";
961  print '<tbody>';
962 
963  $now = dol_now();
964 
965  // Date payment
966  if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
967  $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
968  }
969 
970  print '<tr>';
971  // Date start subscription
972  $currentyear = dol_print_date($now, "%Y");
973  $currentmonth = dol_print_date($now, "%m");
974  print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
975  if (GETPOST('reday')) {
976  $datefrom = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
977  }
978  if (!$datefrom) {
979  $datefrom = $object->datevalid;
980  if ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > dol_now()) {
981  $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
982  } else {
983  $datefrom = dol_get_first_day($currentyear);
984  }
985  }
986  print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
987  print "</td></tr>";
988 
989  // Date end subscription
990  if (GETPOST('endday')) {
991  $dateto = dol_mktime(0, 0, 0, GETPOST('endmonth', 'int'), GETPOST('endday', 'int'), GETPOST('endyear', 'int'));
992  }
993  if (!$dateto) {
994  if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) {
995  $dateto = dol_get_last_day(dol_print_date($datefrom, "%Y"), dol_print_date($datefrom, "%m"));
996  } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) {
997  $dateto = dol_get_last_day(dol_print_date($datefrom, "%Y"));
998  } else {
999  $dateto = -1; // By default, no date is suggested
1000  }
1001  }
1002  print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
1003  print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
1004  print "</td></tr>";
1005 
1006  if ($adht->subscription) {
1007  // Amount
1008  print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="subscription" size="6" value="'.(GETPOSTISSET('subscription') ? GETPOST('subscription') : price($adht->amount, 0, '', 0)).'"> '.$langs->trans("Currency".$conf->currency) .'</td></tr>';
1009 
1010  // Label
1011  print '<tr><td>'.$langs->trans("Label").'</td>';
1012  print '<td><input name="label" type="text" size="32" value="';
1013  if (!getDolGlobalString('MEMBER_NO_DEFAULT_LABEL')) {
1014  print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
1015  }
1016  print '"></td></tr>';
1017 
1018  // Complementary action
1019  if ((isModEnabled('banque') || isModEnabled('facture')) && !getDolGlobalString('ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS')) {
1020  $company = new Societe($db);
1021  if ($object->socid) {
1022  $result = $company->fetch($object->socid);
1023  }
1024 
1025  // No more action
1026  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
1027  print '</td>';
1028  print '<td class="line-height-large">';
1029 
1030  print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'>';
1031  print '<label for="none"> '.$langs->trans("None").'</label><br>';
1032  // Add entry into bank accoun
1033  if (isModEnabled('banque')) {
1034  print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
1035  print '><label for="bankdirect"> '.$langs->trans("MoreActionBankDirect").'</label><br>';
1036  }
1037  // Add invoice with no payments
1038  if (isModEnabled('societe') && isModEnabled('facture')) {
1039  print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
1040  //if (empty($object->fk_soc)) print ' disabled';
1041  print '><label for="invoiceonly"> '.$langs->trans("MoreActionInvoiceOnly");
1042  if ($object->fk_soc) {
1043  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1044  } else {
1045  print ' (';
1046  if (empty($object->fk_soc)) {
1047  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1048  }
1049  print $langs->trans("NoThirdPartyAssociatedToMember");
1050  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1051  print $langs->trans("CreateDolibarrThirdParty");
1052  print '</a>)';
1053  }
1054  if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
1055  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1056  }
1057  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product') || isModEnabled('service'))) {
1058  $prodtmp = new Product($db);
1059  $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
1060  if ($result < 0) {
1061  setEventMessage($prodtmp->error, 'errors');
1062  }
1063  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1064  }
1065  print '</label><br>';
1066  }
1067  // Add invoice with payments
1068  if (isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
1069  print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
1070  //if (empty($object->fk_soc)) print ' disabled';
1071  print '><label for="bankviainvoice"> '.$langs->trans("MoreActionBankViaInvoice");
1072  if ($object->socid) {
1073  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1074  } else {
1075  print ' (';
1076  if (empty($object->socid)) {
1077  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1078  }
1079  print $langs->trans("NoThirdPartyAssociatedToMember");
1080  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1081  print $langs->trans("CreateDolibarrThirdParty");
1082  print '</a>)';
1083  }
1084  if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
1085  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1086  }
1087  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product')|| isModEnabled('service'))) {
1088  $prodtmp = new Product($db);
1089  $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
1090  if ($result < 0) {
1091  setEventMessage($prodtmp->error, 'errors');
1092  }
1093  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1094  }
1095  print '</label><br>';
1096  }
1097  print '</td></tr>';
1098 
1099  // Bank account
1100  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
1101  print img_picto('', 'bank_account');
1102  $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200');
1103  print "</td></tr>\n";
1104 
1105  // Payment mode
1106  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
1107  print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1);
1108  print "</td></tr>\n";
1109 
1110  // Date of payment
1111  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
1112  print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
1113  print "</td></tr>\n";
1114 
1115  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
1116  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
1117  print '</td>';
1118  print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
1119 
1120  print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
1121  print ' <em>('.$langs->trans("ChequeMaker").')</em>';
1122  print '</td>';
1123  print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
1124 
1125  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
1126  print ' <em>('.$langs->trans("ChequeBank").')</em>';
1127  print '</td>';
1128  print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
1129  }
1130  }
1131 
1132  print '<tr><td></td><td></td></tr>';
1133 
1134  print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
1135  print '<td>';
1136  if (!$object->email) {
1137  print $langs->trans("NoEMail");
1138  } else {
1139  $adht = new AdherentType($db);
1140  $adht->fetch($object->typeid);
1141 
1142  // Send subscription email
1143  $subject = '';
1144  $msg = '';
1145 
1146  // Send subscription email
1147  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1148  $formmail = new FormMail($db);
1149  // Set output language
1150  $outputlangs = new Translate('', $conf);
1151  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1152  // Load traductions files required by page
1153  $outputlangs->loadLangs(array("main", "members"));
1154  // Get email content from template
1155  $arraydefaultmessage = null;
1156  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
1157 
1158  if (!empty($labeltouse)) {
1159  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1160  }
1161 
1162  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1163  $subject = $arraydefaultmessage->topic;
1164  $msg = $arraydefaultmessage->content;
1165  }
1166 
1167  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1168  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1169  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1170  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
1171 
1172  $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? ' checked' : '')).'>';
1173  $helpcontent = '';
1174  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
1175  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1176  $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
1177  if ($subjecttosend) {
1178  $helpcontent .= $subjecttosend."\n";
1179  } else {
1180  $langs->load("errors");
1181  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1182  }
1183  $helpcontent .= "<br>";
1184  $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
1185  if ($texttosend) {
1186  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1187  } else {
1188  $langs->load("errors");
1189  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1190  }
1191  print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
1192  }
1193  print '</td></tr>';
1194  print '</tbody>';
1195  print '</table>';
1196  print '</div>';
1197 
1198  print dol_get_fiche_end();
1199 
1200  print '<div class="center">';
1201  $parameters = array();
1202  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
1203  if (empty($reshook)) {
1204  print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
1205  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1206  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1207  }
1208  print '</div>';
1209 
1210  print '</form>';
1211 
1212  print "\n<!-- End form subscription -->\n\n";
1213 }
1214 
1215 
1216 // End of page
1217 llxFooter();
1218 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage members of a foundation.
const STATUS_VALIDATED
Validated status.
Class to manage members type.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation du formulaire html d'envoi de mail unitaire Usage: $formail = new For...
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage subscriptions of foundation members.
Class to manage translations.
Class to manage Dolibarr users.
Definition: user.class.php:48
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:577
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:596
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode='')
Return file(s) into a directory (by default most recent)
Definition: files.lib.php:2546
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0)
Set event message in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
member_prepare_head(Adherent $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:33
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.