dolibarr  19.0.0-dev
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 $defaultdelay = 1;
85 $defaultdelayunit = 'y';
86 
87 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
88 $hookmanager->initHooks(array('subscription'));
89 
90 // PDF
91 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
92 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
93 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
94 
95 $datefrom = 0;
96 $dateto = 0;
97 $paymentdate = -1;
98 
99 // Fetch object
100 if ($id > 0 || !empty($ref)) {
101  // Load member
102  $result = $object->fetch($id, $ref);
103 
104  // Define variables to know what current user can do on users
105  $canadduser = ($user->admin || $user->hasRight("user", "user", "creer"));
106  // Define variables to know what current user can do on properties of user linked to edited member
107  if ($object->user_id) {
108  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
109  $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer"))
110  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer")));
111  $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password"))
112  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password")));
113  }
114 }
115 
116 // Define variables to determine what the current user can do on the members
117 $canaddmember = $user->hasRight('adherent', 'creer');
118 // Define variables to determine what the current user can do on the properties of a member
119 if ($id) {
120  $caneditfieldmember = $user->hasRight('adherent', 'creer');
121 }
122 
123 // Security check
124 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
125 
126 
127 /*
128  * Actions
129  */
130 
131 $parameters = array();
132 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
133 if ($reshook < 0) {
134  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
135 }
136 
137 // Create third party from a member
138 if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->hasRight('societe', 'creer')) {
139  if ($result > 0) {
140  // Creation of thirdparty
141  $company = new Societe($db);
142  $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
143 
144  if ($result < 0) {
145  $langs->load("errors");
146  setEventMessages($company->error, $company->errors, 'errors');
147  } else {
148  $action = 'addsubscription';
149  }
150  } else {
151  setEventMessages($object->error, $object->errors, 'errors');
152  }
153 }
154 
155 if (empty($reshook) && $action == 'setuserid' && ($user->hasRight('user', 'self', 'creer') || $user->hasRight('user', 'user', 'creer'))) {
156  $error = 0;
157  if (!$user->hasRight('user', 'user', 'creer')) { // If can edit only itself user, we can link to itself only
158  if (GETPOST("userid", 'int') != $user->id && GETPOST("userid", 'int') != $object->user_id) {
159  $error++;
160  setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
161  }
162  }
163 
164  if (!$error) {
165  if (GETPOST("userid", 'int') != $object->user_id) { // If link differs from currently in database
166  $result = $object->setUserId(GETPOST("userid", 'int'));
167  if ($result < 0) {
168  dol_print_error('', $object->error);
169  }
170  $action = '';
171  }
172  }
173 }
174 
175 if (empty($reshook) && $action == 'setsocid') {
176  $error = 0;
177  if (!$error) {
178  if (GETPOST('socid', 'int') != $object->fk_soc) { // If link differs from currently in database
179  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
180  $sql .= " WHERE fk_soc = '".GETPOST('socid', 'int')."'";
181  $resql = $db->query($sql);
182  if ($resql) {
183  $obj = $db->fetch_object($resql);
184  if ($obj && $obj->rowid > 0) {
185  $othermember = new Adherent($db);
186  $othermember->fetch($obj->rowid);
187  $thirdparty = new Societe($db);
188  $thirdparty->fetch(GETPOST('socid', 'int'));
189  $error++;
190  setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
191  }
192  }
193 
194  if (!$error) {
195  $result = $object->setThirdPartyId(GETPOST('socid', 'int'));
196  if ($result < 0) {
197  dol_print_error('', $object->error);
198  }
199  $action = '';
200  }
201  }
202  }
203 }
204 
205 if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'subscription' && !$cancel) {
206  $error = 0;
207 
208  $langs->load("banks");
209 
210  $result = $object->fetch($rowid);
211  $result = $adht->fetch($object->typeid);
212 
213  // Subscription informations
214  $datesubscription = 0;
215  $datesubend = 0;
216  $paymentdate = ''; // Do not use 0 here, default value is '' that means not filled where 0 means 1970-01-01
217  if (GETPOST("reyear", "int") && GETPOST("remonth", "int") && GETPOST("reday", "int")) {
218  $datesubscription = dol_mktime(0, 0, 0, GETPOST("remonth", "int"), GETPOST("reday", "int"), GETPOST("reyear", "int"));
219  }
220  if (GETPOST("endyear", 'int') && GETPOST("endmonth", 'int') && GETPOST("endday", 'int')) {
221  $datesubend = dol_mktime(0, 0, 0, GETPOST("endmonth", 'int'), GETPOST("endday", 'int'), GETPOST("endyear", 'int'));
222  }
223  if (GETPOST("paymentyear", 'int') && GETPOST("paymentmonth", 'int') && GETPOST("paymentday", 'int')) {
224  $paymentdate = dol_mktime(0, 0, 0, GETPOST("paymentmonth", 'int'), GETPOST("paymentday", 'int'), GETPOST("paymentyear", 'int'));
225  }
226  $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
227  $label = GETPOST("label");
228 
229  // Payment informations
230  $accountid = GETPOST("accountid", 'int');
231  $operation = GETPOST("operation", "alphanohtml"); // Payment mode
232  $num_chq = GETPOST("num_chq", "alphanohtml");
233  $emetteur_nom = GETPOST("chqemetteur");
234  $emetteur_banque = GETPOST("chqbank");
235  $option = GETPOST("paymentsave");
236  if (empty($option)) {
237  $option = 'none';
238  }
239  $sendalsoemail = GETPOST("sendmail", 'alpha');
240 
241  // Check parameters
242  if (!$datesubscription) {
243  $error++;
244  $langs->load("errors");
245  $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
246  setEventMessages($errmsg, null, 'errors');
247  $action = 'addsubscription';
248  }
249  if (GETPOST('end') && !$datesubend) {
250  $error++;
251  $langs->load("errors");
252  $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
253  setEventMessages($errmsg, null, 'errors');
254  $action = 'addsubscription';
255  }
256  if (!$datesubend) {
257  $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
258  }
259  if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate) {
260  $error++;
261  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
262  setEventMessages($errmsg, null, 'errors');
263  $action = 'addsubscription';
264  }
265 
266  // Check if a payment is mandatory or not
267  if ($adht->subscription) { // Member type need subscriptions
268  if (!is_numeric($amount)) {
269  // If field is '' or not a numeric value
270  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
271  setEventMessages($errmsg, null, 'errors');
272  $error++;
273  $action = 'addsubscription';
274  } else {
275  // If an amount has been provided, we check also fields that becomes mandatory when amount is not null.
276  if (isModEnabled('banque') && GETPOST("paymentsave") != 'none') {
277  if (GETPOST("subscription")) {
278  if (!GETPOST("label")) {
279  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
280  setEventMessages($errmsg, null, 'errors');
281  $error++;
282  $action = 'addsubscription';
283  }
284  if (GETPOST("paymentsave") != 'invoiceonly' && !GETPOST("operation")) {
285  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
286  setEventMessages($errmsg, null, 'errors');
287  $error++;
288  $action = 'addsubscription';
289  }
290  if (GETPOST("paymentsave") != 'invoiceonly' && !(GETPOST("accountid", 'int') > 0)) {
291  $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
292  setEventMessages($errmsg, null, 'errors');
293  $error++;
294  $action = 'addsubscription';
295  }
296  } else {
297  if (GETPOST("accountid", 'int')) {
298  $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
299  setEventMessages($errmsg, null, 'errors');
300  $error++;
301  $action = 'addsubscription';
302  }
303  }
304  }
305  }
306  }
307 
308  // Record the subscription then complementary actions
309  if (!$error && $action == 'subscription') {
310  $db->begin();
311 
312  // Create subscription
313  $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
314  if ($crowid <= 0) {
315  $error++;
316  $errmsg = $object->error;
317  setEventMessages($object->error, $object->errors, 'errors');
318  }
319 
320  if (!$error) {
321  $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
322  if ($result < 0) {
323  $error++;
324  setEventMessages($object->error, $object->errors, 'errors');
325  } else {
326  // If an invoice was created, it is into $object->invoice
327  }
328  }
329 
330  if (!$error) {
331  $db->commit();
332  } else {
333  $db->rollback();
334  $action = 'addsubscription';
335  }
336 
337  if (!$error) {
338  setEventMessages("SubscriptionRecorded", null, 'mesgs');
339  }
340 
341  // Send email
342  if (!$error) {
343  // Send confirmation Email
344  if ($object->email && $sendalsoemail) { // $object is 'Adherent'
345  $parameters = array(
346  'datesubscription' => $datesubscription,
347  'amount' => $amount,
348  'ccountid' => $accountid,
349  'operation' => $operation,
350  'label' => $label,
351  'num_chq' => $num_chq,
352  'emetteur_nom' => $emetteur_nom,
353  'emetteur_banque' => $emetteur_banque,
354  'datesubend' => $datesubend
355  );
356  $reshook = $hookmanager->executeHooks('sendMail', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
357  if ($reshook < 0) {
358  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
359  }
360 
361  if (empty($reshook)) {
362  $subject = '';
363  $msg = '';
364 
365  // Send subscription email
366  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
367  $formmail = new FormMail($db);
368  // Set output language
369  $outputlangs = new Translate('', $conf);
370  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
371  // Load traductions files required by page
372  $outputlangs->loadLangs(array("main", "members"));
373 
374  // Get email content from template
375  $arraydefaultmessage = null;
376  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
377 
378  if (!empty($labeltouse)) {
379  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
380  }
381 
382  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
383  $subject = $arraydefaultmessage->topic;
384  $msg = $arraydefaultmessage->content;
385  }
386 
387  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
388  complete_substitutions_array($substitutionarray, $outputlangs, $object);
389  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
390  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
391 
392  // Attach a file ?
393  $file = '';
394  $listofpaths = array();
395  $listofnames = array();
396  $listofmimes = array();
397  if (is_object($object->invoice) && (!is_object($arraydefaultmessage) || intval($arraydefaultmessage->joinfiles))) {
398  $invoicediroutput = $conf->facture->dir_output;
399  $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
400  $file = $fileparams['fullname'];
401 
402  $listofpaths = array($file);
403  $listofnames = array(basename($file));
404  $listofmimes = array(dol_mimetype($file));
405  }
406 
407  $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
408 
409  $result = $object->sendEmail($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
410  if ($result < 0) {
411  $errmsg = $object->error;
412  setEventMessages($object->error, $object->errors, 'errors');
413  } else {
414  setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
415  }
416  }
417  } else {
418  setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
419  }
420  }
421 
422  // Clean some POST vars
423  if (!$error) {
424  $_POST["subscription"] = '';
425  $_POST["accountid"] = '';
426  $_POST["operation"] = '';
427  $_POST["label"] = '';
428  $_POST["num_chq"] = '';
429  }
430  }
431 }
432 
433 
434 
435 /*
436  * View
437  */
438 
439 $form = new Form($db);
440 
441 $now = dol_now();
442 
443 $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
444 
445 $help_url = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder";
446 
447 llxHeader("", $title, $help_url);
448 
449 
450 $param = '';
451 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
452  $param .= '&contextpage='.urlencode($contextpage);
453 }
454 if ($limit > 0 && $limit != $conf->liste_limit) {
455  $param .= '&limit='.((int) $limit);
456 }
457 $param .= '&id='.$rowid;
458 if ($optioncss != '') {
459  $param .= '&optioncss='.urlencode($optioncss);
460 }
461 // Add $param from extra fields
462 //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
463 
464 
465 if (! ($object->id > 0)) {
466  $langs->load("errors");
467  print $langs->trans("ErrorRecordNotFound");
468 }
469 
470 /*$res = $object->fetch($rowid);
471  if ($res < 0) {
472  dol_print_error($db, $object->error);
473  exit;
474  }
475 */
476 
477 $adht->fetch($object->typeid);
478 
479 $head = member_prepare_head($object);
480 
481 $rowspan = 10;
482 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
483  $rowspan++;
484 }
485 if (isModEnabled('societe')) {
486  $rowspan++;
487 }
488 
489 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
490 print '<input type="hidden" name="token" value="'.newToken().'">';
491 print '<input type="hidden" name="rowid" value="'.$object->id.'">';
492 
493 print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
494 
495 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
496 
497 $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
498 $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
499 $morehtmlref .= '</a>';
500 
501 dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
502 
503 print '<div class="fichecenter">';
504 print '<div class="fichehalfleft">';
505 
506 print '<div class="underbanner clearboth"></div>';
507 print '<table class="border centpercent tableforfield">';
508 
509 // Login
510 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
511  print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
512 }
513 
514 // Type
515 print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
516 print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
517 
518 // Morphy
519 print '<tr><td>'.$langs->trans("MemberNature").'</td>';
520 print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
521 print '</tr>';
522 
523 // Company
524 print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
525 
526 // Civility
527 print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
528 print '</tr>';
529 
530 // Password
531 if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
532  print '<tr><td>'.$langs->trans("Password").'</td><td>';
533  if ($object->pass) {
534  print preg_replace('/./i', '*', $object->pass);
535  } else {
536  if ($user->admin) {
537  print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
538  }
539  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
540  }
541  if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
542  $langs->load("errors");
543  $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
544  print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
545  }
546  print '</td></tr>';
547 }
548 
549 // Date end subscription
550 print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
551 if ($object->datefin) {
552  print dol_print_date($object->datefin, 'day');
553  if ($object->hasDelay()) {
554  print " ".img_warning($langs->trans("Late"));
555  }
556 } else {
557  if ($object->need_subscription == 0) {
558  print $langs->trans("SubscriptionNotNeeded");
559  } elseif (!$adht->subscription) {
560  print $langs->trans("SubscriptionNotRecorded");
561  if (Adherent::STATUS_VALIDATED == $object->statut) {
562  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
563  }
564  } else {
565  print $langs->trans("SubscriptionNotReceived");
566  if (Adherent::STATUS_VALIDATED == $object->statut) {
567  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
568  }
569  }
570 }
571 print '</td></tr>';
572 
573 print '</table>';
574 
575 print '</div>';
576 
577 print '<div class="fichehalfright">';
578 print '<div class="underbanner clearboth"></div>';
579 
580 print '<table class="border tableforfield centpercent">';
581 
582 // Tags / Categories
583 if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
584  print '<tr><td>'.$langs->trans("Categories").'</td>';
585  print '<td colspan="2">';
586  print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
587  print '</td></tr>';
588 }
589 
590 // Birth Date
591 print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
592 
593 // Default language
594 if (getDolGlobalInt('MAIN_MULTILANGS')) {
595  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
596  print '<tr><td>'.$langs->trans("DefaultLang").'</td><td>';
597  //$s=picto_from_langcode($object->default_lang);
598  //print ($s?$s.' ':'');
599  $langs->load("languages");
600  $labellang = ($object->default_lang ? $langs->trans('Language_'.$object->default_lang) : '');
601  print picto_from_langcode($object->default_lang, 'class="paddingrightonly saturatemedium opacitylow"');
602  print $labellang;
603  print '</td></tr>';
604 }
605 
606 // Public
607 $linkofpubliclist = DOL_MAIN_URL_ROOT.'/public/members/public_list.php'.((isModEnabled('multicompany')) ? '?entity='.$conf->entity : '');
608 print '<tr><td>'.$langs->trans("Public", getDolGlobalString('MAIN_INFO_SOCIETE_NOM'), $linkofpubliclist).'</td><td class="valeur">'.yn($object->public).'</td></tr>';
609 
610 // Other attributes
611 $cols = 2;
612 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
613 
614 // Third party Dolibarr
615 if (isModEnabled('societe')) {
616  print '<tr><td>';
617  print '<table class="nobordernopadding" width="100%"><tr><td>';
618  print $langs->trans("LinkedToDolibarrThirdParty");
619  print '</td>';
620  if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) {
621  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>';
622  }
623  print '</tr></table>';
624  print '</td><td colspan="2" class="valeur">';
625  if ($action == 'editthirdparty') {
626  $htmlname = 'socid';
627  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
628  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
629  print '<input type="hidden" name="action" value="set'.$htmlname.'">';
630  print '<input type="hidden" name="token" value="'.newToken().'">';
631  print '<table class="nobordernopadding">';
632  print '<tr><td>';
633  print $form->select_company($object->fk_soc, 'socid', '', 1);
634  print '</td>';
635  print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
636  print '</tr></table></form>';
637  } else {
638  if ($object->fk_soc) {
639  $company = new Societe($db);
640  $result = $company->fetch($object->fk_soc);
641  print $company->getNomUrl(1);
642 
643  // Show link to invoices
644  $tmparray = $company->getOutstandingBills('customer');
645  if (!empty($tmparray['refs'])) {
646  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']).')';
647  // TODO Add alert if warning on at least one invoice late
648  print '</a>';
649  }
650  } else {
651  print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
652  }
653  }
654  print '</td></tr>';
655 }
656 
657 // Login Dolibarr - Link to user
658 print '<tr><td>';
659 print '<table class="nobordernopadding" width="100%"><tr><td>';
660 print $langs->trans("LinkedToDolibarrUser");
661 print '</td>';
662 if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) {
663  print '<td class="right">';
664  if ($user->hasRight("user", "user", "creer")) {
665  print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
666  }
667  print '</td>';
668 }
669 print '</tr></table>';
670 print '</td><td colspan="2" class="valeur">';
671 if ($action == 'editlogin') {
672  $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
673 } else {
674  if ($object->user_id) {
675  $linkeduser = new User($db);
676  $linkeduser->fetch($object->user_id);
677  print $linkeduser->getNomUrl(-1);
678  } else {
679  print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
680  }
681 }
682 print '</td></tr>';
683 
684 print "</table>\n";
685 
686 print "</div></div>\n";
687 print '<div class="clearboth"></div>';
688 
689 print dol_get_fiche_end();
690 
691 
692 /*
693  * Action bar
694  */
695 
696 // Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2)
697 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
698  if ($action != 'addsubscription' && $action != 'create_thirdparty') {
699  print '<div class="tabsAction">';
700 
701  if ($object->statut > 0) {
702  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription&token='.newToken().'">'.$langs->trans("AddSubscription")."</a></div>";
703  } else {
704  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
705  }
706 
707  print '</div>';
708  }
709 }
710 
711 /*
712  * List of subscriptions
713  */
714 if ($action != 'addsubscription' && $action != 'create_thirdparty') {
715  $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
716  $sql .= " c.rowid as crowid, c.subscription,";
717  $sql .= " c.datec, c.fk_type as cfk_type,";
718  $sql .= " c.dateadh as dateh,";
719  $sql .= " c.datef,";
720  $sql .= " c.fk_bank,";
721  $sql .= " b.rowid as bid,";
722  $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
723  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
724  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
725  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
726  $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid);
727  $sql .= $db->order($sortfield, $sortorder);
728 
729  $result = $db->query($sql);
730  if ($result) {
731  $subscriptionstatic = new Subscription($db);
732 
733  $num = $db->num_rows($result);
734 
735  print '<table class="noborder centpercent">'."\n";
736 
737  print '<tr class="liste_titre">';
738  print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
739  print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
740  print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
741  print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
742  print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
743  print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
744  if (isModEnabled('banque')) {
745  print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
746  }
747  print "</tr>\n";
748 
749  $accountstatic = new Account($db);
750  $adh = new Adherent($db);
751  $adht = new AdherentType($db);
752 
753  $i = 0;
754  while ($i < $num) {
755  $objp = $db->fetch_object($result);
756 
757  $adh->id = $objp->rowid;
758  $adh->typeid = $objp->type;
759 
760  $subscriptionstatic->ref = $objp->crowid;
761  $subscriptionstatic->id = $objp->crowid;
762 
763  $typeid = $objp->cfk_type;
764  if ($typeid > 0) {
765  $adht->fetch($typeid);
766  }
767 
768  print '<tr class="oddeven">';
769  print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
770  print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
771  print '<td class="center">';
772  if ($typeid > 0) {
773  print $adht->getNomUrl(1);
774  }
775  print '</td>';
776  print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
777  print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
778  print '<td class="right amount">'.price($objp->subscription).'</td>';
779  if (isModEnabled('banque')) {
780  print '<td class="right">';
781  if ($objp->bid) {
782  $accountstatic->label = $objp->label;
783  $accountstatic->id = $objp->baid;
784  $accountstatic->number = $objp->number;
785  $accountstatic->account_number = $objp->account_number;
786  $accountstatic->currency_code = $objp->currency_code;
787 
788  if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) {
789  $accountingjournal = new AccountingJournal($db);
790  $accountingjournal->fetch($objp->fk_accountancy_journal);
791 
792  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
793  }
794 
795  $accountstatic->ref = $objp->ref;
796  print $accountstatic->getNomUrl(1);
797  } else {
798  print '&nbsp;';
799  }
800  print '</td>';
801  }
802  print "</tr>";
803  $i++;
804  }
805 
806  if (empty($num)) {
807  $colspan = 6;
808  if (isModEnabled('banque')) {
809  $colspan++;
810  }
811  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
812  }
813 
814  print "</table>";
815  } else {
816  dol_print_error($db);
817  }
818 }
819 
820 
821 if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
822  // Shon online payment link
823  $useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
824 
825  if ($useonlinepayment) {
826  print '<br>';
827 
828  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
829  print showOnlinePaymentUrl('membersubscription', $object->ref);
830  print '<br>';
831  }
832 }
833 
834 /*
835  * Add new subscription form
836  */
837 if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->hasRight('adherent', 'cotisation', 'creer')) {
838  print '<br>';
839 
840  print load_fiche_titre($langs->trans("NewCotisation"));
841 
842  // Define default choice for complementary actions
843  $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
844  $invoiceonly = 0; // 1 means option by default is invoice only
845  $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
846  if (GETPOST('paymentsave')) {
847  if (GETPOST('paymentsave') == 'bankdirect') {
848  $bankdirect = 1;
849  }
850  if (GETPOST('paymentsave') == 'invoiceonly') {
851  $invoiceonly = 1;
852  }
853  if (GETPOST('paymentsave') == 'bankviainvoice') {
854  $bankviainvoice = 1;
855  }
856  } else {
857  if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
858  $bankviainvoice = 1;
859  } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && isModEnabled('banque')) {
860  $bankdirect = 1;
861  } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
862  $invoiceonly = 1;
863  }
864  }
865 
866  print "\n\n<!-- Form add subscription -->\n";
867 
868  if ($conf->use_javascript_ajax) {
869  //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
870  print "\n".'<script type="text/javascript">';
871  print '$(document).ready(function () {
872  $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
873  $("#none, #invoiceonly").click(function() {
874  $(".bankswitchclass").hide();
875  $(".bankswitchclass2").hide();
876  });
877  $("#bankdirect, #bankviainvoice").click(function() {
878  $(".bankswitchclass").show();
879  $(".bankswitchclass2").show();
880  });
881  $("#selectoperation").change(function() {
882  var code = $(this).val();
883  if (code == "CHQ")
884  {
885  $(".fieldrequireddyn").addClass("fieldrequired");
886  if ($("#fieldchqemetteur").val() == "")
887  {
888  $("#fieldchqemetteur").val($("#memberlabel").val());
889  }
890  }
891  else
892  {
893  $(".fieldrequireddyn").removeClass("fieldrequired");
894  }
895  });
896  ';
897  if (GETPOST('paymentsave')) {
898  print '$("#'.GETPOST('paymentsave', 'aZ09').'").prop("checked", true);';
899  }
900  print '});';
901  print '</script>'."\n";
902  }
903 
904 
905  // Confirm create third party
906  if ($action == 'create_thirdparty') {
907  $companyalias = '';
908  $fullname = $object->getFullName($langs);
909 
910  if ($object->morphy == 'mor') {
911  $companyname = $object->company;
912  if (!empty($fullname)) {
913  $companyalias = $fullname;
914  }
915  } else {
916  $companyname = $fullname;
917  if (!empty($object->company)) {
918  $companyalias = $object->company;
919  }
920  }
921 
922  // Create a form array
923  $formquestion = array(
924  array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
925  array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
926  );
927  // If customer code was forced to "required", we ask it at creation to avoid error later
928  if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
929  $tmpcompany = new Societe($db);
930  $tmpcompany->name = $companyname;
931  $tmpcompany->get_codeclient($tmpcompany, 0);
932  $customercode = $tmpcompany->code_client;
933  $formquestion[] = array(
934  'label' => $langs->trans("CustomerCode"),
935  'type' => 'text',
936  'name' => 'customercode',
937  'value' => $customercode,
938  'morecss' => 'minwidth300',
939  'moreattr' => 'maxlength="128"',
940  );
941  }
942  // @todo Add other extrafields mandatory for thirdparty creation
943 
944  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
945  }
946 
947 
948  print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
949  print '<input type="hidden" name="token" value="'.newToken().'">';
950  print '<input type="hidden" name="action" value="subscription">';
951  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
952  print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
953  print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
954 
955  print dol_get_fiche_head('');
956 
957  print '<div class="div-table-responsive">';
958  print '<table class="border centpercent">'."\n";
959  print '<tbody>';
960 
961  $now = dol_now();
962 
963  // Date payment
964  if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
965  $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
966  }
967 
968  print '<tr>';
969  // Date start subscription
970  $currentyear = dol_print_date($now, "%Y");
971  $currentmonth = dol_print_date($now, "%m");
972  print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
973  if (GETPOST('reday')) {
974  $datefrom = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
975  }
976  if (!$datefrom) {
977  $datefrom = $object->datevalid;
978  if ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > dol_now()) {
979  $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
980  } else {
981  $datefrom = dol_get_first_day($currentyear);
982  }
983  }
984  print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
985  print "</td></tr>";
986 
987  // Date end subscription
988  if (GETPOST('endday')) {
989  $dateto = dol_mktime(0, 0, 0, GETPOST('endmonth', 'int'), GETPOST('endday', 'int'), GETPOST('endyear', 'int'));
990  }
991  if (!$dateto) {
992  if (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_MONTH')) {
993  $dateto = dol_get_last_day($currentyear, $currentmonth);
994  } elseif (getDolGlobalInt('MEMBER_SUBSCRIPTION_SUGGEST_END_OF_YEAR')) {
995  $dateto = dol_get_last_day($currentyear);
996  } else {
997  $dateto = -1; // By default, no date is suggested
998  }
999  }
1000  print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
1001  print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
1002  print "</td></tr>";
1003 
1004  if ($adht->subscription) {
1005  // Amount
1006  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>';
1007 
1008  // Label
1009  print '<tr><td>'.$langs->trans("Label").'</td>';
1010  print '<td><input name="label" type="text" size="32" value="';
1011  if (!getDolGlobalString('MEMBER_NO_DEFAULT_LABEL')) {
1012  print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
1013  }
1014  print '"></td></tr>';
1015 
1016  // Complementary action
1017  if ((isModEnabled('banque') || isModEnabled('facture')) && !getDolGlobalString('ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS')) {
1018  $company = new Societe($db);
1019  if ($object->socid) {
1020  $result = $company->fetch($object->socid);
1021  }
1022 
1023  // No more action
1024  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
1025  print '</td>';
1026  print '<td class="line-height-large">';
1027 
1028  print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'>';
1029  print '<label for="none"> '.$langs->trans("None").'</label><br>';
1030  // Add entry into bank accoun
1031  if (isModEnabled('banque')) {
1032  print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
1033  print '><label for="bankdirect"> '.$langs->trans("MoreActionBankDirect").'</label><br>';
1034  }
1035  // Add invoice with no payments
1036  if (isModEnabled('societe') && isModEnabled('facture')) {
1037  print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
1038  //if (empty($object->fk_soc)) print ' disabled';
1039  print '><label for="invoiceonly"> '.$langs->trans("MoreActionInvoiceOnly");
1040  if ($object->fk_soc) {
1041  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1042  } else {
1043  print ' (';
1044  if (empty($object->fk_soc)) {
1045  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1046  }
1047  print $langs->trans("NoThirdPartyAssociatedToMember");
1048  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1049  print $langs->trans("CreateDolibarrThirdParty");
1050  print '</a>)';
1051  }
1052  if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
1053  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1054  }
1055  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product') || isModEnabled('service'))) {
1056  $prodtmp = new Product($db);
1057  $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
1058  if ($result < 0) {
1059  setEventMessage($prodtmp->error, 'errors');
1060  }
1061  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1062  }
1063  print '</label><br>';
1064  }
1065  // Add invoice with payments
1066  if (isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
1067  print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
1068  //if (empty($object->fk_soc)) print ' disabled';
1069  print '><label for="bankviainvoice"> '.$langs->trans("MoreActionBankViaInvoice");
1070  if ($object->socid) {
1071  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1072  } else {
1073  print ' (';
1074  if (empty($object->socid)) {
1075  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1076  }
1077  print $langs->trans("NoThirdPartyAssociatedToMember");
1078  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1079  print $langs->trans("CreateDolibarrThirdParty");
1080  print '</a>)';
1081  }
1082  if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
1083  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1084  }
1085  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product')|| isModEnabled('service'))) {
1086  $prodtmp = new Product($db);
1087  $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
1088  if ($result < 0) {
1089  setEventMessage($prodtmp->error, 'errors');
1090  }
1091  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1092  }
1093  print '</label><br>';
1094  }
1095  print '</td></tr>';
1096 
1097  // Bank account
1098  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
1099  print img_picto('', 'bank_account');
1100  $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200');
1101  print "</td></tr>\n";
1102 
1103  // Payment mode
1104  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
1105  print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1);
1106  print "</td></tr>\n";
1107 
1108  // Date of payment
1109  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
1110  print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
1111  print "</td></tr>\n";
1112 
1113  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
1114  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
1115  print '</td>';
1116  print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
1117 
1118  print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
1119  print ' <em>('.$langs->trans("ChequeMaker").')</em>';
1120  print '</td>';
1121  print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
1122 
1123  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
1124  print ' <em>('.$langs->trans("ChequeBank").')</em>';
1125  print '</td>';
1126  print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
1127  }
1128  }
1129 
1130  print '<tr><td></td><td></td></tr>';
1131 
1132  print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
1133  print '<td>';
1134  if (!$object->email) {
1135  print $langs->trans("NoEMail");
1136  } else {
1137  $adht = new AdherentType($db);
1138  $adht->fetch($object->typeid);
1139 
1140  // Send subscription email
1141  $subject = '';
1142  $msg = '';
1143 
1144  // Send subscription email
1145  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1146  $formmail = new FormMail($db);
1147  // Set output language
1148  $outputlangs = new Translate('', $conf);
1149  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1150  // Load traductions files required by page
1151  $outputlangs->loadLangs(array("main", "members"));
1152  // Get email content from template
1153  $arraydefaultmessage = null;
1154  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
1155 
1156  if (!empty($labeltouse)) {
1157  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1158  }
1159 
1160  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1161  $subject = $arraydefaultmessage->topic;
1162  $msg = $arraydefaultmessage->content;
1163  }
1164 
1165  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1166  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1167  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1168  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
1169 
1170  $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? ' checked' : '')).'>';
1171  $helpcontent = '';
1172  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.getDolGlobalString('ADHERENT_MAIL_FROM').'<br>'."\n";
1173  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1174  $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
1175  if ($subjecttosend) {
1176  $helpcontent .= $subjecttosend."\n";
1177  } else {
1178  $langs->load("errors");
1179  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1180  }
1181  $helpcontent .= "<br>";
1182  $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
1183  if ($texttosend) {
1184  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1185  } else {
1186  $langs->load("errors");
1187  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1188  }
1189  print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
1190  }
1191  print '</td></tr>';
1192  print '</tbody>';
1193  print '</table>';
1194  print '</div>';
1195 
1196  print dol_get_fiche_end();
1197 
1198  print '<div class="center">';
1199  $parameters = array();
1200  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
1201  if (empty($reshook)) {
1202  print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
1203  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1204  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1205  }
1206  print '</div>';
1207 
1208  print '</form>';
1209 
1210  print "\n<!-- End form subscription -->\n\n";
1211 }
1212 
1213 
1214 // End of page
1215 llxFooter();
1216 $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 journals.
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:576
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:595
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:2524
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.