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