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