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