dolibarr 23.0.3
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';
35require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
37require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
38require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
39if (isModEnabled("bank")) {
40 require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
41}
42
43// Load translation files required by the page
44$langs->loadLangs(array("companies", "members", "bills", "users", "banks"));
45
46$adh = new Adherent($db);
47$adht = new AdherentType($db);
48$object = new Subscription($db);
49$errmsg = '';
50
51$action = GETPOST("action", 'alpha');
52$rowid = GETPOSTINT("rowid") ? GETPOSTINT("rowid") : GETPOSTINT("id");
53$typeid = GETPOSTINT("typeid");
54$cancel = GETPOST('cancel', 'alpha');
55$confirm = GETPOST('confirm');
56$note = GETPOST('note', 'alpha');
57$typeid = GETPOSTINT('typeid');
58$amount = (float) price2num(GETPOST('amount', 'alpha'), 'MT');
59
60if (!$user->hasRight('adherent', 'cotisation', 'lire')) {
62}
63
64$permissionnote = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_setnotes.inc.php
65$permissiondellink = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_dellink.inc.php
66$permissiontoedit = $user->hasRight('adherent', 'cotisation', 'creer'); // Used by the include of actions_lineupdonw.inc.php
67
68$hookmanager->initHooks(array('subscriptioncard', 'globalcard'));
69
70// Security check
71$result = restrictedArea($user, 'subscription', 0); // TODO Check on object id
72
73
74/*
75 * Actions
76 */
77
78if ($cancel) {
79 $action = '';
80}
81
82//include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
83
84include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
85
86//include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
87
88
89if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'update' && !$cancel) {
90 // Load current object
91 $result = $object->fetch($rowid);
92 if ($result > 0) {
93 $db->begin();
94
95 $errmsg = '';
96
97 $newdatestart = dol_mktime(GETPOSTINT('datesubhour'), GETPOSTINT('datesubmin'), 0, GETPOSTINT('datesubmonth'), GETPOSTINT('datesubday'), GETPOSTINT('datesubyear'));
98 $newdateend = dol_mktime(GETPOSTINT('datesubendhour'), GETPOSTINT('datesubendmin'), 0, GETPOSTINT('datesubendmonth'), GETPOSTINT('datesubendday'), GETPOSTINT('datesubendyear'));
99
100 if ($object->fk_bank > 0) {
101 $accountline = new AccountLine($db);
102 $result = $accountline->fetch($object->fk_bank);
103
104 // If transaction consolidated
105 if ($accountline->rappro) {
106 $errmsg = $langs->trans("SubscriptionLinkedToConciliatedTransaction");
107 } else {
108 $accountline->datev = $newdatestart;
109 $accountline->dateo = $newdatestart;
110 $accountline->amount = $amount;
111
112 $result = $accountline->update($user);
113 if ($result < 0) {
114 $errmsg = $accountline->error;
115 }
116 }
117 }
118
119 if (!$errmsg) {
120 // Modify values
121 $object->dateh = $newdatestart;
122 $object->datef = $newdateend;
123 $object->fk_type = $typeid;
124 $object->note_public = $note;
125 $object->note_private = $note;
126
127 $object->amount = $amount;
128
129 $result = $object->update($user);
130 if ($result >= 0 && !count($object->errors)) {
131 $db->commit();
132
133 header("Location: card.php?rowid=".$object->id);
134 exit;
135 } else {
136 $db->rollback();
137
138 if ($object->error) {
139 $errmsg = $object->error;
140 } else {
141 foreach ($object->errors as $error) {
142 if ($errmsg) {
143 $errmsg .= '<br>';
144 }
145 $errmsg .= $error;
146 }
147 }
148 $action = '';
149 }
150 } else {
151 $db->rollback();
152 }
153 }
154}
155
156if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('adherent', 'cotisation', 'creer')) {
157 $result = $object->fetch($rowid);
158 $result = $object->delete($user);
159 if ($result > 0) {
160 header("Location: ".DOL_URL_ROOT."/adherents/card.php?rowid=".$object->fk_adherent);
161 exit;
162 } else {
163 $errmesg = $adh->error;
164 }
165}
166
167
168
169/*
170 * View
171 */
172
173$form = new Form($db);
174
175$title = $langs->trans("SubscriptionCard");
176$help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
177
178llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-member page-subscription-card');
179
180
181dol_htmloutput_errors($errmsg);
182
183
184if ($user->hasRight('adherent', 'cotisation', 'creer') && $action == 'edit') {
185 /********************************************
186 *
187 * Subscription card in edit mode
188 *
189 ********************************************/
190
191 $object->fetch($rowid);
192 $result = $adh->fetch($object->fk_adherent);
193
194 $head = subscription_prepare_head($object);
195
196 print '<form name="update" action="'.$_SERVER["PHP_SELF"].'" method="post">';
197 print '<input type="hidden" name="token" value="'.newToken().'">';
198 print "<input type=\"hidden\" name=\"action\" value=\"update\">";
199 print "<input type=\"hidden\" name=\"rowid\" value=\"$rowid\">";
200 print "<input type=\"hidden\" name=\"fk_bank\" value=\"".$object->fk_bank."\">";
201
202 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), 0, 'payment');
203
204 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
205
206 print "\n";
207 print '<table class="border centpercent">';
208
209 // Ref
210 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
211 print '<td class="valeur">';
212 print $form->showrefnav($object, 'rowid', $linkback, 1);
213 print '</td></tr>';
214
215 // Member
216 $adh->ref = $adh->getFullName($langs);
217 print '<tr>';
218 print '<td>'.$langs->trans("Member").'</td>';
219 print '<td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
220 print '</tr>';
221
222 // Type
223 print '<tr>';
224 print '<td>'.$langs->trans("Type").'</td>';
225 print '<td class="valeur">';
226 print $form->selectarray("typeid", $adht->liste_array(), (GETPOSTISSET("typeid") ? GETPOST("typeid") : $object->fk_type));
227 print'</td></tr>';
228
229 // Date start subscription
230 print '<tr><td>'.$langs->trans("DateSubscription").'</td>';
231 print '<td class="valeur">';
232 print $form->selectDate($object->dateh, 'datesub', 1, 1, 0, 'update', 1);
233 print '</td>';
234 print '</tr>';
235
236 // Date end subscription
237 print '<tr><td>'.$langs->trans("DateEndSubscription").'</td>';
238 print '<td class="valeur">';
239 print $form->selectDate($object->datef, 'datesubend', 0, 0, 0, 'update', 1);
240 print '</td>';
241 print '</tr>';
242
243 // Amount
244 print '<tr><td>'.$langs->trans("Amount").'</td>';
245 print '<td class="valeur">';
246 print '<input type="text" class="flat width200" name="amount" value="'.price($object->amount).'"></td></tr>';
247
248 // Label
249 print '<tr><td>'.$langs->trans("Label").'</td>';
250 print '<td class="valeur">';
251 print '<input type="text" class="flat" name="note" value="'.$object->note_public.'"></td></tr>';
252
253 // Bank line
254 if (isModEnabled("bank") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
255 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
256 if ($object->fk_bank) {
257 $bankline = new AccountLine($db);
258 $result = $bankline->fetch($object->fk_bank);
259 print $bankline->getNomUrl(1, 0, 'showall');
260 } else {
261 print $langs->trans("NoneF");
262 }
263 print '</td></tr>';
264 }
265
266 print '</table>';
267
268 print dol_get_fiche_end();
269
270 print $form->buttonsSaveCancel();
271
272 print '</form>';
273 print "\n";
274}
275
276if ($rowid && $action != 'edit') {
277 /********************************************
278 *
279 * Subscription card in view mode
280 *
281 ********************************************/
282
283 $result = $object->fetch($rowid);
284 $result = $adh->fetch($object->fk_adherent);
285
286 $head = subscription_prepare_head($object);
287
288 print dol_get_fiche_head($head, 'general', $langs->trans("Subscription"), -1, 'payment');
289
290 // Confirmation to delete subscription
291 if ($action == 'delete') {
292 $formquestion=array();
293 //$formquestion['text']='<b>'.$langs->trans("ThisWillAlsoDeleteBankRecord").'</b>';
294 $text = $langs->trans("ConfirmDeleteSubscription");
295 if (isModEnabled("bank") && getDolGlobalString('ADHERENT_BANK_USE')) {
296 $text .= '<br>'.img_warning().' '.$langs->trans("ThisWillAlsoDeleteBankRecord");
297 }
298 print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("DeleteSubscription"), $text, "confirm_delete", $formquestion, 0, 1);
299 }
300
301 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
302 print '<input type="hidden" name="token" value="'.newToken().'">';
303
304 $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/subscription/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
305
306 dol_banner_tab($object, 'rowid', $linkback, 1);
307
308 print '<div class="fichecenter">';
309
310 print '<div class="underbanner clearboth"></div>';
311
312 print '<table class="border centpercent tableforfield">';
313
314 // Member
315 $adh->ref = $adh->getFullName($langs);
316 print '<tr>';
317 print '<td class="titlefield">'.$langs->trans("Member").'</td><td class="valeur">'.$adh->getNomUrl(-1, 0, 'subscription').'</td>';
318 print '</tr>';
319
320 // Type
321 print '<tr>';
322 print '<td class="titlefield">'.$langs->trans("Type").'</td>';
323 print '<td class="valeur">';
324 if ($object->fk_type > 0 || $adh->typeid > 0) {
325 $typeid = ($object->fk_type > 0 ? $object->fk_type : $adh->typeid);
326 $adht->fetch($typeid);
327 print $adht->getNomUrl(1);
328 } else {
329 print $langs->trans("NoType");
330 }
331 print '</td></tr>';
332
333 // Date subscription
334 print '<tr>';
335 print '<td>'.$langs->trans("DateSubscription").'</td><td class="valeur">'.dol_print_date($object->dateh, 'day').'</td>';
336 print '</tr>';
337
338 // Date end subscription
339 print '<tr>';
340 print '<td>'.$langs->trans("DateEndSubscription").'</td><td class="valeur">'.dol_print_date($object->datef, 'day').'</td>';
341 print '</tr>';
342
343 // Amount
344 print '<tr><td>'.$langs->trans("Amount").'</td><td class="valeur"><span class="amount">'.price($object->amount).'</span></td></tr>';
345
346 // Label
347 print '<tr><td>'.$langs->trans("Label").'</td><td class="valeur sensiblehtmlcontent">'.dol_string_onlythesehtmltags(dol_htmlentitiesbr($object->note_public)).'</td></tr>';
348
349 // Bank line
350 if (isModEnabled("bank") && (getDolGlobalString('ADHERENT_BANK_USE') || $object->fk_bank)) {
351 print '<tr><td>'.$langs->trans("BankTransactionLine").'</td><td class="valeur">';
352 if ($object->fk_bank > 0) {
353 $bankline = new AccountLine($db);
354 $result = $bankline->fetch($object->fk_bank);
355 print $bankline->getNomUrl(1, 0, 'showall');
356 } else {
357 print $langs->trans("NoneF");
358 }
359 print '</td></tr>';
360 }
361
362 print "</table>\n";
363 print '</div>';
364
365 print '</form>';
366
367 print dol_get_fiche_end();
368
369 /*
370 * Action bar
371 */
372 print '<div class="tabsAction">';
373
374 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
375 if (empty($bankline) || empty($bankline->rappro)) {
376 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>";
377 } else {
378 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.$langs->trans("BankLineConciliated").'" href="#">'.$langs->trans("Modify")."</a></div>";
379 }
380 }
381
382 // Delete
383 if ($user->hasRight('adherent', 'cotisation', 'creer')) {
384 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";
385 }
386
387 print '</div>';
388
389
390 print '<div class="fichecenter"><div class="fichehalfleft">';
391 print '<a name="builddoc"></a>'; // ancre
392
393 // Generated documents
394 /*
395 $filename = dol_sanitizeFileName($object->ref);
396 $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref);
397 $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id;
398 $genallowed = $user->hasRight('facture', 'lire');
399 $delallowed = $user->hasRight('facture', 'creer');
400
401 print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
402 $somethingshown = $formfile->numoffiles;
403 */
404 // Show links to link elements
405 //$tmparray = $form->showLinkToObjectBlock($object, null, array('subscription'), 1);
406 $somethingshown = $form->showLinkedObjectBlock($object, '');
407
408
409 print '</div><div class="fichehalfright">';
410
411 // List of actions on element
412 /*
413 include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
414 $formactions = new FormActions($db);
415 $somethingshown = $formactions->showactions($object, $object->element, $socid, 1, '', $MAXEVENT);
416 */
417
418 print '</div></div>';
419}
420
421// End of page
422llxFooter();
423$db->close();
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
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:73
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.
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_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
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.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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...
dol_string_onlythesehtmltags($stringtoclean, $cleanalsosomestyles=1, $removeclassattribute=1, $cleanalsojavascript=0, $allowiframe=0, $allowed_tags=array(), $allowlink=0, $allowscript=0, $allowstyle=0, $allowphp=0)
Clean a string to keep only desirable HTML tags.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.