dolibarr  17.0.4
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 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
84 $hookmanager->initHooks(array('subscription'));
85 
86 // PDF
87 $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
88 $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
89 $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
90 
91 $datefrom = 0;
92 $dateto = 0;
93 $paymentdate = -1;
94 
95 // Fetch object
96 if ($id > 0 || !empty($ref)) {
97  // Load member
98  $result = $object->fetch($id, $ref);
99 
100  // Define variables to know what current user can do on users
101  $canadduser = ($user->admin || $user->hasRight("user", "user", "creer"));
102  // Define variables to know what current user can do on properties of user linked to edited member
103  if ($object->user_id) {
104  // $User is the user who edits, $object->user_id is the id of the related user in the edited member
105  $caneditfielduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "creer"))
106  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "creer")));
107  $caneditpassworduser = ((($user->id == $object->user_id) && $user->hasRight("user", "self", "password"))
108  || (($user->id != $object->user_id) && $user->hasRight("user", "user", "password")));
109  }
110 }
111 
112 // Define variables to determine what the current user can do on the members
113 $canaddmember = $user->hasRight('adherent', 'creer');
114 // Define variables to determine what the current user can do on the properties of a member
115 if ($id) {
116  $caneditfieldmember = $user->hasRight('adherent', 'creer');
117 }
118 
119 // Security check
120 $result = restrictedArea($user, 'adherent', $object->id, '', '', 'socid', 'rowid', 0);
121 
122 
123 /*
124  * Actions
125  */
126 
127 $parameters = array();
128 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
129 if ($reshook < 0) {
130  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
131 }
132 
133 // Create third party from a member
134 if (empty($reshook) && $action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer) {
135  if ($result > 0) {
136  // Creation of thirdparty
137  $company = new Societe($db);
138  $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
139 
140  if ($result < 0) {
141  $langs->load("errors");
142  setEventMessages($company->error, $company->errors, 'errors');
143  } else {
144  $action = 'addsubscription';
145  }
146  } else {
147  setEventMessages($object->error, $object->errors, 'errors');
148  }
149 }
150 
151 if (empty($reshook) && $action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer)) {
152  $error = 0;
153  if (empty($user->rights->user->user->creer)) { // If can edit only itself user, we can link to itself only
154  if (GETPOST("userid", 'int') != $user->id && GETPOST("userid", 'int') != $object->user_id) {
155  $error++;
156  setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
157  }
158  }
159 
160  if (!$error) {
161  if (GETPOST("userid", 'int') != $object->user_id) { // If link differs from currently in database
162  $result = $object->setUserId(GETPOST("userid", 'int'));
163  if ($result < 0) {
164  dol_print_error('', $object->error);
165  }
166  $action = '';
167  }
168  }
169 }
170 
171 if (empty($reshook) && $action == 'setsocid') {
172  $error = 0;
173  if (!$error) {
174  if (GETPOST('socid', 'int') != $object->fk_soc) { // If link differs from currently in database
175  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
176  $sql .= " WHERE fk_soc = '".GETPOST('socid', 'int')."'";
177  $resql = $db->query($sql);
178  if ($resql) {
179  $obj = $db->fetch_object($resql);
180  if ($obj && $obj->rowid > 0) {
181  $othermember = new Adherent($db);
182  $othermember->fetch($obj->rowid);
183  $thirdparty = new Societe($db);
184  $thirdparty->fetch(GETPOST('socid', 'int'));
185  $error++;
186  setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
187  }
188  }
189 
190  if (!$error) {
191  $result = $object->setThirdPartyId(GETPOST('socid', 'int'));
192  if ($result < 0) {
193  dol_print_error('', $object->error);
194  }
195  $action = '';
196  }
197  }
198  }
199 }
200 
201 if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !$cancel) {
202  $error = 0;
203 
204  $langs->load("banks");
205 
206  $result = $object->fetch($rowid);
207  $result = $adht->fetch($object->typeid);
208 
209  // Subscription informations
210  $datesubscription = 0;
211  $datesubend = 0;
212  $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
213  $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
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 (isModEnabled('banque') && 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  $defaultdelay = !empty($adht->duration_value) ? $adht->duration_value : 1;
473  $defaultdelayunit = !empty($adht->duration_unit) ? $adht->duration_unit : 'y';
474 
475  $head = member_prepare_head($object);
476 
477  $rowspan = 10;
478  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
479  $rowspan++;
480  }
481  if (isModEnabled('societe')) {
482  $rowspan++;
483  }
484 
485  print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
486  print '<input type="hidden" name="token" value="'.newToken().'">';
487  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
488 
489  print dol_get_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
490 
491  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
492 
493  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/adherents/vcard.php?id='.$object->id.'" class="refid">';
494  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
495  $morehtmlref .= '</a>';
496 
497  dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref);
498 
499  print '<div class="fichecenter">';
500  print '<div class="fichehalfleft">';
501 
502  print '<div class="underbanner clearboth"></div>';
503  print '<table class="border centpercent tableforfield">';
504 
505  // Login
506  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
507  print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.dol_escape_htmltag($object->login).'</td></tr>';
508  }
509 
510  // Type
511  print '<tr><td class="titlefield">'.$langs->trans("Type").'</td>';
512  print '<td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
513 
514  // Morphy
515  print '<tr><td>'.$langs->trans("MemberNature").'</td>';
516  print '<td class="valeur" >'.$object->getmorphylib('', 1).'</td>';
517  print '</tr>';
518 
519  // Company
520  print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.dol_escape_htmltag($object->company).'</td></tr>';
521 
522  // Civility
523  print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'</td>';
524  print '</tr>';
525 
526  // Password
527  if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) {
528  print '<tr><td>'.$langs->trans("Password").'</td><td>';
529  if ($object->pass) {
530  print preg_replace('/./i', '*', $object->pass);
531  } else {
532  if ($user->admin) {
533  print '<!-- '.$langs->trans("Crypted").': '.$object->pass_indatabase_crypted.' -->';
534  }
535  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
536  }
537  if (!empty($object->pass_indatabase) && empty($object->user_id)) { // Show warning only for old password still in clear (does not happen anymore)
538  $langs->load("errors");
539  $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
540  print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
541  }
542  print '</td></tr>';
543  }
544 
545  // Date end subscription
546  print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
547  if ($object->datefin) {
548  print dol_print_date($object->datefin, 'day');
549  if ($object->hasDelay()) {
550  print " ".img_warning($langs->trans("Late"));
551  }
552  } else {
553  if ($object->need_subscription == 0) {
554  print $langs->trans("SubscriptionNotNeeded");
555  } elseif (!$adht->subscription) {
556  print $langs->trans("SubscriptionNotRecorded");
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  } else {
561  print $langs->trans("SubscriptionNotReceived");
562  if (Adherent::STATUS_VALIDATED == $object->statut) {
563  print " ".img_warning($langs->trans("Late")); // displays delay Pictogram only if not a draft, not excluded and not resiliated
564  }
565  }
566  }
567  print '</td></tr>';
568 
569  print '</table>';
570 
571  print '</div>';
572 
573  print '<div class="fichehalfright">';
574  print '<div class="underbanner clearboth"></div>';
575 
576  print '<table class="border tableforfield centpercent">';
577 
578  // Tags / Categories
579  if (isModEnabled('categorie') && !empty($user->rights->categorie->lire)) {
580  print '<tr><td>'.$langs->trans("Categories").'</td>';
581  print '<td colspan="2">';
582  print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
583  print '</td></tr>';
584  }
585 
586  // Birth Date
587  print '<tr><td class="titlefield">'.$langs->trans("DateOfBirth").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
588 
589  // Public
590  print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
591 
592  // Other attributes
593  $cols = 2;
594  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
595 
596  // Third party Dolibarr
597  if (isModEnabled('societe')) {
598  print '<tr><td>';
599  print '<table class="nobordernopadding" width="100%"><tr><td>';
600  print $langs->trans("LinkedToDolibarrThirdParty");
601  print '</td>';
602  if ($action != 'editthirdparty' && $user->hasRight('adherent', 'creer')) {
603  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>';
604  }
605  print '</tr></table>';
606  print '</td><td colspan="2" class="valeur">';
607  if ($action == 'editthirdparty') {
608  $htmlname = 'socid';
609  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
610  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
611  print '<input type="hidden" name="action" value="set'.$htmlname.'">';
612  print '<input type="hidden" name="token" value="'.newToken().'">';
613  print '<table class="nobordernopadding">';
614  print '<tr><td>';
615  print $form->select_company($object->fk_soc, 'socid', '', 1);
616  print '</td>';
617  print '<td class="left"><input type="submit" class="button button-edit" value="'.$langs->trans("Modify").'"></td>';
618  print '</tr></table></form>';
619  } else {
620  if ($object->fk_soc) {
621  $company = new Societe($db);
622  $result = $company->fetch($object->fk_soc);
623  print $company->getNomUrl(1);
624 
625  // Show link to invoices
626  $tmparray = $company->getOutstandingBills('customer');
627  if (!empty($tmparray['refs'])) {
628  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']).')';
629  // TODO Add alert if warning on at least one invoice late
630  print '</a>';
631  }
632  } else {
633  print '<span class="opacitymedium">'.$langs->trans("NoThirdPartyAssociatedToMember").'</span>';
634  }
635  }
636  print '</td></tr>';
637  }
638 
639  // Login Dolibarr - Link to user
640  print '<tr><td>';
641  print '<table class="nobordernopadding" width="100%"><tr><td>';
642  print $langs->trans("LinkedToDolibarrUser");
643  print '</td>';
644  if ($action != 'editlogin' && $user->hasRight('adherent', 'creer')) {
645  print '<td class="right">';
646  if ($user->hasRight("user", "user", "creer")) {
647  print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&token='.newToken().'&rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
648  }
649  print '</td>';
650  }
651  print '</tr></table>';
652  print '</td><td colspan="2" class="valeur">';
653  if ($action == 'editlogin') {
654  $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
655  } else {
656  if ($object->user_id) {
657  $linkeduser = new User($db);
658  $linkeduser->fetch($object->user_id);
659  print $linkeduser->getNomUrl(-1);
660  } else {
661  print '<span class="opacitymedium">'.$langs->trans("NoDolibarrAccess").'</span>';
662  }
663  }
664  print '</td></tr>';
665 
666  print "</table>\n";
667 
668  print "</div></div>\n";
669  print '<div style="clear:both"></div>';
670 
671  print dol_get_fiche_end();
672 
673 
674  /*
675  * Action bar
676  */
677 
678  // Button to create a new subscription if member no draft (-1) neither resiliated (0) neither excluded (-2)
679  if ($user->rights->adherent->cotisation->creer) {
680  if ($action != 'addsubscription' && $action != 'create_thirdparty') {
681  print '<div class="tabsAction">';
682 
683  if ($object->statut > 0) {
684  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription&token='.newToken().'">'.$langs->trans("AddSubscription")."</a></div>";
685  } else {
686  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
687  }
688 
689  print '</div>';
690  }
691  }
692 
693  /*
694  * List of subscriptions
695  */
696  if ($action != 'addsubscription' && $action != 'create_thirdparty') {
697  $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
698  $sql .= " c.rowid as crowid, c.subscription,";
699  $sql .= " c.datec, c.fk_type as cfk_type,";
700  $sql .= " c.dateadh as dateh,";
701  $sql .= " c.datef,";
702  $sql .= " c.fk_bank,";
703  $sql .= " b.rowid as bid,";
704  $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
705  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
706  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
707  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
708  $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".((int) $rowid);
709  $sql .= $db->order($sortfield, $sortorder);
710 
711  $result = $db->query($sql);
712  if ($result) {
713  $subscriptionstatic = new Subscription($db);
714 
715  $num = $db->num_rows($result);
716 
717  print '<table class="noborder centpercent">'."\n";
718 
719  print '<tr class="liste_titre">';
720  print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
721  print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
722  print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
723  print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
724  print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
725  print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
726  if (isModEnabled('banque')) {
727  print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
728  }
729  print "</tr>\n";
730 
731  $accountstatic = new Account($db);
732  $adh = new Adherent($db);
733  $adht = new AdherentType($db);
734 
735  $i = 0;
736  while ($i < $num) {
737  $objp = $db->fetch_object($result);
738 
739  $adh->id = $objp->rowid;
740  $adh->typeid = $objp->type;
741 
742  $subscriptionstatic->ref = $objp->crowid;
743  $subscriptionstatic->id = $objp->crowid;
744 
745  $typeid = $objp->cfk_type;
746  if ($typeid > 0) {
747  $adht->fetch($typeid);
748  }
749 
750  print '<tr class="oddeven">';
751  print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
752  print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
753  print '<td class="center">';
754  if ($typeid > 0) {
755  print $adht->getNomUrl(1);
756  }
757  print '</td>';
758  print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
759  print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
760  print '<td class="right">'.price($objp->subscription).'</td>';
761  if (isModEnabled('banque')) {
762  print '<td class="right">';
763  if ($objp->bid) {
764  $accountstatic->label = $objp->label;
765  $accountstatic->id = $objp->baid;
766  $accountstatic->number = $objp->number;
767  $accountstatic->account_number = $objp->account_number;
768  $accountstatic->currency_code = $objp->currency_code;
769 
770  if (isModEnabled('accounting') && $objp->fk_accountancy_journal > 0) {
771  $accountingjournal = new AccountingJournal($db);
772  $accountingjournal->fetch($objp->fk_accountancy_journal);
773 
774  $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
775  }
776 
777  $accountstatic->ref = $objp->ref;
778  print $accountstatic->getNomUrl(1);
779  } else {
780  print '&nbsp;';
781  }
782  print '</td>';
783  }
784  print "</tr>";
785  $i++;
786  }
787 
788  if (empty($num)) {
789  $colspan = 6;
790  if (isModEnabled('banque')) {
791  $colspan++;
792  }
793  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
794  }
795 
796  print "</table>";
797  } else {
798  dol_print_error($db);
799  }
800  }
801 
802 
803  if (($action != 'addsubscription' && $action != 'create_thirdparty')) {
804  // Shon online payment link
805  $useonlinepayment = (isModEnabled('paypal') || isModEnabled('stripe') || isModEnabled('paybox'));
806 
807  if ($useonlinepayment) {
808  print '<br>';
809 
810  require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
811  print showOnlinePaymentUrl('membersubscription', $object->ref);
812  print '<br>';
813  }
814  }
815 
816  /*
817  * Add new subscription form
818  */
819  if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer) {
820  print '<br>';
821 
822  print load_fiche_titre($langs->trans("NewCotisation"));
823 
824  // Define default choice for complementary actions
825  $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
826  $invoiceonly = 0; // 1 means option by default is invoice only
827  $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
828  if (GETPOST('paymentsave')) {
829  if (GETPOST('paymentsave') == 'bankdirect') {
830  $bankdirect = 1;
831  }
832  if (GETPOST('paymentsave') == 'invoiceonly') {
833  $invoiceonly = 1;
834  }
835  if (GETPOST('paymentsave') == 'bankviainvoice') {
836  $bankviainvoice = 1;
837  }
838  } else {
839  if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
840  $bankviainvoice = 1;
841  } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && isModEnabled('banque')) {
842  $bankdirect = 1;
843  } elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
844  $invoiceonly = 1;
845  }
846  }
847 
848  print "\n\n<!-- Form add subscription -->\n";
849 
850  if ($conf->use_javascript_ajax) {
851  //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
852  print "\n".'<script type="text/javascript">';
853  print '$(document).ready(function () {
854  $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
855  $("#none, #invoiceonly").click(function() {
856  $(".bankswitchclass").hide();
857  $(".bankswitchclass2").hide();
858  });
859  $("#bankdirect, #bankviainvoice").click(function() {
860  $(".bankswitchclass").show();
861  $(".bankswitchclass2").show();
862  });
863  $("#selectoperation").change(function() {
864  var code = $(this).val();
865  if (code == "CHQ")
866  {
867  $(".fieldrequireddyn").addClass("fieldrequired");
868  if ($("#fieldchqemetteur").val() == "")
869  {
870  $("#fieldchqemetteur").val($("#memberlabel").val());
871  }
872  }
873  else
874  {
875  $(".fieldrequireddyn").removeClass("fieldrequired");
876  }
877  });
878  ';
879  if (GETPOST('paymentsave')) {
880  print '$("#'.GETPOST('paymentsave', 'aZ09').'").prop("checked", true);';
881  }
882  print '});';
883  print '</script>'."\n";
884  }
885 
886 
887  // Confirm create third party
888  if ($action == 'create_thirdparty') {
889  $companyalias = '';
890  $fullname = $object->getFullName($langs);
891 
892  if ($object->morphy == 'mor') {
893  $companyname = $object->company;
894  if (!empty($fullname)) {
895  $companyalias = $fullname;
896  }
897  } else {
898  $companyname = $fullname;
899  if (!empty($object->company)) {
900  $companyalias = $object->company;
901  }
902  }
903 
904  // Create a form array
905  $formquestion = array(
906  array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
907  array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
908  );
909  // If customer code was forced to "required", we ask it at creation to avoid error later
910  if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) {
911  $tmpcompany = new Societe($db);
912  $tmpcompany->name = $companyname;
913  $tmpcompany->get_codeclient($tmpcompany, 0);
914  $customercode = $tmpcompany->code_client;
915  $formquestion[] = array(
916  'label' => $langs->trans("CustomerCode"),
917  'type' => 'text',
918  'name' => 'customercode',
919  'value' => $customercode,
920  'morecss' => 'minwidth300',
921  'moreattr' => 'maxlength="128"',
922  );
923  }
924  // @todo Add other extrafields mandatory for thirdparty creation
925 
926  print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
927  }
928 
929 
930  print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
931  print '<input type="hidden" name="token" value="'.newToken().'">';
932  print '<input type="hidden" name="action" value="subscription">';
933  print '<input type="hidden" name="rowid" value="'.$rowid.'">';
934  print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
935  print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
936 
937  print dol_get_fiche_head('');
938 
939  print "<table class=\"border\" width=\"100%\">\n";
940  print '<tbody>';
941 
942  $today = dol_now();
943 
944  // Date payment
945  if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday')) {
946  $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
947  }
948 
949  print '<tr>';
950  // Date start subscription
951  print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
952  if (GETPOST('reday')) {
953  $datefrom = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
954  }
955  if (!$datefrom) {
956  $datefrom = $object->datevalid;
957  if ($object->datefin > 0 && dol_time_plus_duree($object->datefin, $defaultdelay, $defaultdelayunit) > dol_now()) {
958  $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
959  } else {
960  $datefrom = dol_get_first_day(dol_print_date(time(), "%Y"));
961  }
962  }
963  print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
964  print "</td></tr>";
965 
966  // Date end subscription
967  if (GETPOST('endday')) {
968  $dateto = dol_mktime(0, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
969  }
970  if (!$dateto) {
971  $dateto = -1; // By default, no date is suggested
972  }
973  print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
974  print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
975  print "</td></tr>";
976 
977  if ($adht->subscription) {
978  // Amount
979  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>';
980 
981  // Label
982  print '<tr><td>'.$langs->trans("Label").'</td>';
983  print '<td><input name="label" type="text" size="32" value="';
984  if (empty($conf->global->MEMBER_NO_DEFAULT_LABEL)) {
985  print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
986  }
987  print '"></td></tr>';
988 
989  // Complementary action
990  if ((isModEnabled('banque') || isModEnabled('facture')) && empty($conf->global->ADHERENT_SUBSCRIPTION_HIDECOMPLEMENTARYACTIONS)) {
991  $company = new Societe($db);
992  if ($object->fk_soc) {
993  $result = $company->fetch($object->fk_soc);
994  }
995 
996  // Title payments
997  //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
998 
999  // No more action
1000  print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
1001  print '</td>';
1002  print '<td>';
1003  print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'>';
1004  print '<label for="none"> '.$langs->trans("None").'</label><br>';
1005  // Add entry into bank accoun
1006  if (isModEnabled('banque')) {
1007  print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
1008  print '><label for="bankdirect"> '.$langs->trans("MoreActionBankDirect").'</label><br>';
1009  }
1010  // Add invoice with no payments
1011  if (isModEnabled('societe') && isModEnabled('facture')) {
1012  print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
1013  //if (empty($object->fk_soc)) print ' disabled';
1014  print '><label for="invoiceonly"> '.$langs->trans("MoreActionInvoiceOnly");
1015  if ($object->fk_soc) {
1016  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1017  } else {
1018  print ' (';
1019  if (empty($object->fk_soc)) {
1020  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1021  }
1022  print $langs->trans("NoThirdPartyAssociatedToMember");
1023  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1024  print $langs->trans("CreateDolibarrThirdParty");
1025  print '</a>)';
1026  }
1027  if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
1028  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1029  }
1030  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product') || isModEnabled('service'))) {
1031  $prodtmp = new Product($db);
1032  $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
1033  if ($result < 0) {
1034  setEventMessage($prodtmp->error, 'errors');
1035  }
1036  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1037  }
1038  print '</label><br>';
1039  }
1040  // Add invoice with payments
1041  if (isModEnabled('banque') && isModEnabled('societe') && isModEnabled('facture')) {
1042  print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
1043  //if (empty($object->fk_soc)) print ' disabled';
1044  print '><label for="bankviainvoice"> '.$langs->trans("MoreActionBankViaInvoice");
1045  if ($object->fk_soc) {
1046  print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
1047  } else {
1048  print ' (';
1049  if (empty($object->fk_soc)) {
1050  print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
1051  }
1052  print $langs->trans("NoThirdPartyAssociatedToMember");
1053  print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
1054  print $langs->trans("CreateDolibarrThirdParty");
1055  print '</a>)';
1056  }
1057  if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') {
1058  print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
1059  }
1060  if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (isModEnabled('product')|| isModEnabled('service'))) {
1061  $prodtmp = new Product($db);
1062  $result = $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
1063  if ($result < 0) {
1064  setEventMessage($prodtmp->error, 'errors');
1065  }
1066  print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
1067  }
1068  print '</label><br>';
1069  }
1070  print '</td></tr>';
1071 
1072  // Bank account
1073  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
1074  print img_picto('', 'bank_account');
1075  $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 2, '', 0, 'minwidth200');
1076  print "</td></tr>\n";
1077 
1078  // Payment mode
1079  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
1080  print $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2, 1, 0, 0, 1, 'minwidth200', 1);
1081  print "</td></tr>\n";
1082 
1083  // Date of payment
1084  print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
1085  print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
1086  print "</td></tr>\n";
1087 
1088  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
1089  print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
1090  print '</td>';
1091  print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
1092 
1093  print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
1094  print ' <em>('.$langs->trans("ChequeMaker").')</em>';
1095  print '</td>';
1096  print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
1097 
1098  print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
1099  print ' <em>('.$langs->trans("ChequeBank").')</em>';
1100  print '</td>';
1101  print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
1102  }
1103  }
1104 
1105  print '<tr><td></td><td></td></tr>';
1106 
1107  print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
1108  print '<td>';
1109  if (!$object->email) {
1110  print $langs->trans("NoEMail");
1111  } else {
1112  $adht = new AdherentType($db);
1113  $adht->fetch($object->typeid);
1114 
1115  // Send subscription email
1116  $subject = '';
1117  $msg = '';
1118 
1119  // Send subscription email
1120  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
1121  $formmail = new FormMail($db);
1122  // Set output language
1123  $outputlangs = new Translate('', $conf);
1124  $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
1125  // Load traductions files required by page
1126  $outputlangs->loadLangs(array("main", "members"));
1127  // Get email content from template
1128  $arraydefaultmessage = null;
1129  $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
1130 
1131  if (!empty($labeltouse)) {
1132  $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
1133  }
1134 
1135  if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
1136  $subject = $arraydefaultmessage->topic;
1137  $msg = $arraydefaultmessage->content;
1138  }
1139 
1140  $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
1141  complete_substitutions_array($substitutionarray, $outputlangs, $object);
1142  $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
1143  $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
1144 
1145  $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? ' checked' : '')).'>';
1146  $helpcontent = '';
1147  $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
1148  $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
1149  $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
1150  if ($subjecttosend) {
1151  $helpcontent .= $subjecttosend."\n";
1152  } else {
1153  $langs->load("errors");
1154  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1155  }
1156  $helpcontent .= "<br>";
1157  $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
1158  if ($texttosend) {
1159  $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
1160  } else {
1161  $langs->load("errors");
1162  $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
1163  }
1164  print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
1165  }
1166  print '</td></tr>';
1167  print '</tbody>';
1168  print '</table>';
1169 
1170  print dol_get_fiche_end();
1171 
1172  print '<div class="center">';
1173  $parameters = array();
1174  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action);
1175  if (empty($reshook)) {
1176  print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
1177  print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
1178  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1179  }
1180  print '</div>';
1181 
1182  print '</form>';
1183 
1184  print "\n<!-- End form subscription -->\n\n";
1185  }
1186 
1187  //print '</td></tr>';
1188  //print '</table>';
1189 } else {
1190  $langs->load("errors");
1191  print $langs->trans("ErrorRecordNotFound");
1192 }
1193 
1194 // End of page
1195 llxFooter();
1196 $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:47
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:2429
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.
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.