dolibarr 21.0.0-beta
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2019 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2018-2024 Frédéric France <frederic.france@free.fr>
4 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
29require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
30require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
31require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
32if (isModEnabled("bank")) {
33 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
34}
35
44// Load translation files required by the page
45$langs->loadLangs(array("companies", "members", "bills", "users", "banks"));
46
47$adh = new Adherent($db);
48$adht = new AdherentType($db);
49$object = new Subscription($db);
50$errmsg = '';
51
52$action = GETPOST("action", 'alpha');
53$rowid = GETPOSTINT("rowid") ? GETPOSTINT("rowid") : GETPOSTINT("id");
54$typeid = GETPOSTINT("typeid");
55$cancel = GETPOST('cancel', 'alpha');
56$confirm = GETPOST('confirm');
57$note = GETPOST('note', 'alpha');
58$typeid = GETPOSTINT('typeid');
59$amount = (float) price2num(GETPOST('amount', 'alpha'), 'MT');
60
61if (!$user->hasRight('adherent', 'cotisation', 'lire')) {
63}
64
65$permissionnote = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_setnotes.inc.php
66$permissiondellink = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_dellink.inc.php
67$permissiontoedit = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_lineupdonw.inc.php
68
69$hookmanager->initHooks(array('subscriptioncard', 'globalcard'));
70
71// Security check
72$result = restrictedArea($user, 'subscription', 0); // TODO Check on object id
73
74
75/*
76 * Actions
77 */
78
79if ($cancel) {
80 $action = '';
81}
82
83//include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
84
85include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
86
87//include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
88
89
90if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'update' && !$cancel) {
91 // Load current object
92 $result = $object->fetch($rowid);
93 if ($result > 0) {
94 $db->begin();
95
96 $errmsg = '';
97
98 $newdatestart = dol_mktime(GETPOSTINT('datesubhour'), GETPOSTINT('datesubmin'), 0, GETPOSTINT('datesubmonth'), GETPOSTINT('datesubday'), GETPOSTINT('datesubyear'));
99 $newdateend = dol_mktime(GETPOSTINT('datesubendhour'), GETPOSTINT('datesubendmin'), 0, GETPOSTINT('datesubendmonth'), GETPOSTINT('datesubendday'), GETPOSTINT('datesubendyear'));
100
101 if ($object->fk_bank > 0) {
102 $accountline = new AccountLine($db);
103 $result = $accountline->fetch($object->fk_bank);
104
105 // If transaction consolidated
106 if ($accountline->rappro) {
107 $errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
108 } else {
109 $accountline->datev = $newdatestart;
110 $accountline->dateo = $newdatestart;
111 $accountline->amount = $amount;
112
113 $result = $accountline->update($user);
114 if ($result < 0) {
115 $errmsg = $accountline->error;
116 }
117 }
118 }
119
120 if (!$errmsg) {
121 // Modify values
122 $object->dateh = $newdatestart;
123 $object->datef = $newdateend;
124 $object->fk_type = $typeid;
125 $object->note_public = $note;
126 $object->note_private = $note;
127
128 $object->amount = $amount;
129
130 $result = $object->update($user);
131 if ($result >= 0 && !count($object->errors)) {
132 $db->commit();
133
134 header("Location: card.php?rowid=".$object->id);
135 exit;
136 } else {
137 $db->rollback();
138
139 if ($object->error) {
140 $errmsg = $object->error;
141 } else {
142 foreach ($object->errors as $error) {
143 if ($errmsg) {
144 $errmsg .= '<br>';
145 }
146 $errmsg .= $error;
147 }
148 }
149 $action = '';
150 }
151 } else {
152 $db->rollback();
153 }
154 }
155}
156
157if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('adherent', 'cotisation', 'creer')) {
158 $result = $object->fetch($rowid);
159 $result = $object->delete($user);
160 if ($result > 0) {
161 header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
162 exit;
163 } else {
164 $errmesg = $adh->error;
165 }
166}
167
168
169
170/*
171 * View
172 */
173
174$form = new Form($db);
175
176$title = $langs->trans("SubscriptionCard");
177$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
178
179llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-subscription-card');
180
181
182dol_htmloutput_errors($errmsg);
183
184
185if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'edit') {
186 /********************************************
187 *
188 * Subscription card in edit mode
189 *
190 ********************************************/
191
192 $object->fetch($rowid);
193 $result = $adh->fetch($object->fk_adherent);
194
196
197 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
198 print '<input type="hidden" name="token" value="'.newToken().'">';
199 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
200 print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
201 print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
202
203 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
204
205 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
206
207 print "\n";
208 print '<table class="border centpercent">';
209
210 // Ref
211 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
212 print '<td class="valeur">';
213 print $form->showrefnav($object, 'rowid', $linkback, 1);
214 print '</td></tr>';
215
216 // Member
217 $adh->ref = $adh->getFullName($langs);
218 print '<tr>';
219 print '<td>'.$langs->trans("Member").'</td>';
220 print '<td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
221 print '</tr>';
222
223 // Type
224 print '<tr>';
225 print '<td>'.$langs->trans("Type").'</td>';
226 print '<td class="valeur">';
227 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
228 print'</td></tr>';
229
230 // Date start subscription
231 print '<tr><td>'.$langs->trans("DateSubscription").'</td>';
232 print '<td class="valeur">';
233 print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
234 print '</td>';
235 print '</tr>';
236
237 // Date end subscription
238 print '<tr><td>'.$langs->trans("DateEndSubscription").'</td>';
239 print '<td class="valeur">';
240 print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
241 print '</td>';
242 print '</tr>';
243
244 // Amount
245 print '<tr><td>'.$langs->trans("Amount").'</td>';
246 print '<td class="valeur">';
247 print '<input type="text" class="flat width200" name="amount" value="'.price($object->amount).'"></td></tr>';
248
249 // Label
250 print '<tr><td>'.$langs->trans("Label").'</td>';
251 print '<td class="valeur">';
252 print '<input type="text" class="flat" name="note" value="'.$object->note_public.'"></td></tr>';
253
254 // Bank line
255 if (isModEnabled("bank") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
256 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
257 if ($object->fk_bank) {
258 $bankline = new AccountLine($db);
259 $result = $bankline->fetch($object->fk_bank);
260 print $bankline->getNomUrl(1, 0, 'showall');
261 } else {
262 print $langs->trans("NoneF");
263 }
264 print '</td></tr>';
265 }
266
267 print '</table>';
268
269 print dol_get_fiche_end();
270
271 print $form->buttonsSaveCancel();
272
273 print '</form>';
274 print "\n";
275}
276
277if ($rowid && $action != 'edit') {
278 /********************************************
279 *
280 * Subscription card in view mode
281 *
282 ********************************************/
283
284 $result = $object->fetch($rowid);
285 $result = $adh->fetch($object->fk_adherent);
286
288
289 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
290
291 // Confirmation to delete subscription
292 if ($action == 'delete') {
293 $formquestion=array();
294 //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
295 $text = $langs->trans("ConfirmDeleteSubscription");
296 if (isModEnabled("bank") && getDolGlobalString('ADHERENT_BANK_USE')) {
297 $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
298 }
299 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
300 }
301
302 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
303 print '<input type="hidden" name="token" value="'.newToken().'">';
304
305 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
306
307 dol_banner_tab($object, 'rowid', $linkback, 1);
308
309 print '<div class="fichecenter">';
310
311 print '<div class="underbanner clearboth"></div>';
312
313 print '<table class="border centpercent tableforfield">';
314
315 // Member
316 $adh->ref = $adh->getFullName($langs);
317 print '<tr>';
318 print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
319 print '</tr>';
320
321 // Type
322 print '<tr>';
323 print '<td class="titlefield">'.$langs->trans("Type").'</td>';
324 print '<td class="valeur">';
325 if ($object->fk_type > 0 || $adh->typeid > 0) {
326 $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
327 $adht->fetch($typeid);
328 print $adht->getNomUrl(1);
329 } else {
330 print $langs->trans("NoType");
331 }
332 print '</td></tr>';
333
334 // Date subscription
335 print '<tr>';
336 print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
337 print '</tr>';
338
339 // Date end subscription
340 print '<tr>';
341 print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
342 print '</tr>';
343
344 // Amount
345 print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur"><span class="amount">'.price($object->amount).'</span></td></tr>';
346
347 // Label
348 print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
349
350 // Bank line
351 if (isModEnabled("bank") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
352 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
353 if ($object->fk_bank > 0) {
354 $bankline = new AccountLine($db);
355 $result = $bankline->fetch($object->fk_bank);
356 print $bankline->getNomUrl(1, 0, 'showall');
357 } else {
358 print $langs->trans("NoneF");
359 }
360 print '</td></tr>';
361 }
362
363 print "</table>\n";
364 print '</div>';
365
366 print '</form>';
367
368 print dol_get_fiche_end();
369
370 /*
371 * Action bar
372 */
373 print '<div class="tabsAction">';
374
375 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
376 if (empty($bankline->rappro) || empty($bankline)) {
377 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"]."?rowid=".((int) $object->id).'&action=edit&token='.newToken().'">'.$langs->trans("Modify")."</a></div>";
378 } else {
379 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated").'" href="#">'.$langs->trans("Modify")."</a></div>";
380 }
381 }
382
383 // Delete
384 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
385 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"]."?rowid=".((int) $object->id).'&action=delete&token='.newToken().'">'.$langs->trans("Delete")."</a></div>\n";
386 }
387
388 print '</div>';
389
390
391 print '<div class="fichecenter"><div class="fichehalfleft">';
392 print '<a name="builddoc"></a>'; // ancre
393
394 // Generated documents
395 /*
396 $filename = dol_sanitizeFileName($object->ref);
397 $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
398 $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
399 $genallowed = $user->hasRight('facture', 'lire');
400 $delallowed = $user->hasRight('facture', 'creer');
401
402 print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
403 $somethingshown = $formfile->numoffiles;
404 */
405 // Show links to link elements
406 //$tmparray = $form->showLinkToObjectBlock($object, null, array('subscription'), 1);
407 $somethingshown = $form->showLinkedObjectBlock($object, '');
408
409
410 print '</div><div class="fichehalfright">';
411
412 // List of actions on element
413 /*
414 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
415 $formactions = new FormActions($db);
416 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
417 */
418
419 print '</div></div>';
420}
421
422// End of page
423llxFooter();
424$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:71
Class to manage bank transaction lines.
Class to manage members of a foundation.
Class to manage members type.
Class to manage generation of HTML components Only common components must be here.
Class to manage subscriptions of foundation members.
llxFooter()
Footer empty.
Definition document.php:107
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0)
Clean a string to keep only desirable HTML tags.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
Print formatted error messages to output (Used to show messages on html output).
subscription_prepare_head(Subscription $object)
Return array head with list of tabs to view object information.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.