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