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