dolibarr  x.y.z
type.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
6  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
7  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
8  * Copyright (C) 2019-2022 Thibault Foucart <support@ptibogxiv.net>
9  * Copyright (C) 2020 Josep Lluís Amador <joseplluis@lliuretic.cat>
10  * Copyright (C) 2021 Waël Almoman <info@almoman.com>
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 3 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>.
24  */
25 
32 // Load Dolibarr environment
33 require '../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
35 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
39 
40 $langs->load("members");
41 
42 $rowid = GETPOST('rowid', 'int');
43 $action = GETPOST('action', 'aZ09');
44 $cancel = GETPOST('cancel', 'alpha');
45 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
46 $backtopage = GETPOST('backtopage', 'alpha');
47 $mode = GETPOST('mode', 'alopha');
48 
49 $sall = GETPOST("sall", "alpha");
50 $filter = GETPOST("filter", 'alpha');
51 $search_lastname = GETPOST('search_lastname', 'alpha');
52 $search_login = GETPOST('search_login', 'alpha');
53 $search_email = GETPOST('search_email', 'alpha');
54 $type = GETPOST('type', 'intcomma');
55 $status = GETPOST('status', 'alpha');
56 $optioncss = GETPOST('optioncss', 'alpha');
57 
58 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
59 $sortfield = GETPOST('sortfield', 'aZ09comma');
60 $sortorder = GETPOST('sortorder', 'aZ09comma');
61 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
62 if (empty($page) || $page == -1) {
63  $page = 0;
64 } // If $page is not defined, or '' or -1
65 $offset = $limit * $page;
66 $pageprev = $page - 1;
67 $pagenext = $page + 1;
68 if (!$sortorder) {
69  $sortorder = "DESC";
70 }
71 if (!$sortfield) {
72  $sortfield = "d.lastname";
73 }
74 
75 $label = GETPOST("label", "alpha");
76 $morphy = GETPOST("morphy", "alpha");
77 $status = GETPOST("status", "int");
78 $subscription = GETPOST("subscription", "int");
79 $amount = GETPOST('amount', 'alpha');
80 $duration_value = GETPOST('duration_value', 'int');
81 $duration_unit = GETPOST('duration_unit', 'alpha');
82 $vote = GETPOST("vote", "int");
83 $comment = GETPOST("comment", 'restricthtml');
84 $mail_valid = GETPOST("mail_valid", 'restricthtml');
85 $caneditamount = GETPOSTINT("caneditamount");
86 
87 // Security check
88 $result = restrictedArea($user, 'adherent', $rowid, 'adherent_type');
89 
90 $object = new AdherentType($db);
91 
92 $extrafields = new ExtraFields($db);
93 
94 // fetch optionals attributes and labels
95 $extrafields->fetch_name_optionals_label($object->table_element);
96 
97 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
98  $search_lastname = "";
99  $search_login = "";
100  $search_email = "";
101  $type = "";
102  $sall = "";
103 }
104 
105 
106 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
107 $hookmanager->initHooks(array('membertypecard', 'globalcard'));
108 
109 
110 /*
111  * Actions
112  */
113 
114 if ($cancel) {
115  $action = '';
116 
117  if (!empty($backtopage)) {
118  header("Location: ".$backtopage);
119  exit;
120  }
121 }
122 
123 if ($action == 'add' && $user->hasRight('adherent', 'configurer')) {
124  $object->label = trim($label);
125  $object->morphy = trim($morphy);
126  $object->status = (int) $status;
127  $object->subscription = (int) $subscription;
128  $object->amount = ($amount == '' ? '' : price2num($amount, 'MT'));
129  $object->caneditamount = $caneditamount;
130  $object->duration_value = $duration_value;
131  $object->duration_unit = $duration_unit;
132  $object->note_public = trim($comment);
133  $object->note_private = '';
134  $object->mail_valid = trim($mail_valid);
135  $object->vote = (int) $vote;
136 
137  // Fill array 'array_options' with data from add form
138  $ret = $extrafields->setOptionalsFromPost(null, $object);
139  if ($ret < 0) {
140  $error++;
141  }
142 
143  if (empty($object->label)) {
144  $error++;
145  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
146  } else {
147  $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."adherent_type WHERE libelle = '".$db->escape($object->label)."'";
148  $sql .= " WHERE entity IN (".getEntity('member_type').")";
149  $result = $db->query($sql);
150  $num = null;
151  if ($result) {
152  $num = $db->num_rows($result);
153  }
154  if ($num) {
155  $error++;
156  $langs->load("errors");
157  setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors');
158  }
159  }
160 
161  if (!$error) {
162  $id = $object->create($user);
163  if ($id > 0) {
164  header("Location: ".$_SERVER["PHP_SELF"]);
165  exit;
166  } else {
167  setEventMessages($object->error, $object->errors, 'errors');
168  $action = 'create';
169  }
170  } else {
171  $action = 'create';
172  }
173 }
174 
175 if ($action == 'update' && $user->hasRight('adherent', 'configurer')) {
176  $object->fetch($rowid);
177 
178  $object->oldcopy = dol_clone($object);
179 
180  $object->label= trim($label);
181  $object->morphy = trim($morphy);
182  $object->status = (int) $status;
183  $object->subscription = (int) $subscription;
184  $object->amount = ($amount == '' ? '' : price2num($amount, 'MT'));
185  $object->caneditamount = $caneditamount;
186  $object->duration_value = $duration_value;
187  $object->duration_unit = $duration_unit;
188  $object->note_public = trim($comment);
189  $object->note_private = '';
190  $object->mail_valid = trim($mail_valid);
191  $object->vote = (boolean) trim($vote);
192 
193  // Fill array 'array_options' with data from add form
194  $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
195  if ($ret < 0) {
196  $error++;
197  }
198 
199  $ret = $object->update($user);
200 
201  if ($ret >= 0 && !count($object->errors)) {
202  setEventMessages($langs->trans("MemberTypeModified"), null, 'mesgs');
203  } else {
204  setEventMessages($object->error, $object->errors, 'errors');
205  }
206 
207  header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$object->id);
208  exit;
209 }
210 
211 if ($action == 'confirm_delete' && $user->hasRight('adherent', 'configurer')) {
212  $object->fetch($rowid);
213  $res = $object->delete();
214 
215  if ($res > 0) {
216  setEventMessages($langs->trans("MemberTypeDeleted"), null, 'mesgs');
217  header("Location: ".$_SERVER["PHP_SELF"]);
218  exit;
219  } else {
220  setEventMessages($langs->trans("MemberTypeCanNotBeDeleted"), null, 'errors');
221  $action = '';
222  }
223 }
224 
225 
226 /*
227  * View
228  */
229 
230 $form = new Form($db);
231 $formproduct = new FormProduct($db);
232 
233 $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
234 
235 llxHeader('', $langs->trans("MembersTypeSetup"), $help_url);
236 
237 // List of members type
238 if (!$rowid && $action != 'create' && $action != 'edit') {
239  //print dol_get_fiche_head('');
240 
241  $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.caneditamount, d.vote, d.statut as status, d.morphy";
242  $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
243  $sql .= " WHERE d.entity IN (".getEntity('member_type').")";
244 
245  $result = $db->query($sql);
246  if ($result) {
247  $num = $db->num_rows($result);
248  $nbtotalofrecords = $num;
249 
250  $i = 0;
251 
252  $param = '';
253  if (!empty($mode)) {
254  $param .= '&mode'.urlencode($mode);
255  }
256  if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
257  $param .= '&contextpage='.$contextpage;
258  }
259  if ($limit > 0 && $limit != $conf->liste_limit) {
260  $param .= '&limit='.$limit;
261  }
262 
263  $newcardbutton = '';
264 
265  $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
266  $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
267 
268  if ($user->hasRight('adherent', 'configurer')) {
269  $newcardbutton .= dolGetButtonTitle($langs->trans('NewMemberType'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/type.php?action=create');
270  }
271 
272  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
273  if ($optioncss != '') {
274  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
275  }
276  print '<input type="hidden" name="token" value="'.newToken().'">';
277  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
278  print '<input type="hidden" name="action" value="list">';
279  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
280  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
281  print '<input type="hidden" name="mode" value="'.$mode.'">';
282 
283 
284  print_barre_liste($langs->trans("MembersTypes"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'members', 0, $newcardbutton, '', $limit, 0, 0, 1);
285 
286  $moreforfilter = '';
287 
288  print '<div class="div-table-responsive">';
289  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
290 
291  print '<tr class="liste_titre">';
292  print '<th>'.$langs->trans("Ref").'</th>';
293  print '<th>'.$langs->trans("Label").'</th>';
294  print '<th class="center">'.$langs->trans("MembersNature").'</th>';
295  print '<th class="center">'.$langs->trans("SubscriptionRequired").'</th>';
296  print '<th class="center">'.$langs->trans("Amount").'</th>';
297  print '<th class="center">'.$langs->trans("CanEditAmountShort").'</th>';
298  print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
299  print '<th class="center">'.$langs->trans("Status").'</th>';
300  print '<th>&nbsp;</th>';
301  print "</tr>\n";
302 
303  $membertype = new AdherentType($db);
304 
305  while ($i < $num) {
306  $objp = $db->fetch_object($result);
307 
308  $membertype->id = $objp->rowid;
309  $membertype->ref = $objp->rowid;
310  $membertype->label = $objp->rowid;
311  $membertype->status = $objp->status;
312  $membertype->subscription = $objp->subscription;
313  $membertype->amount = $objp->amount;
314  $membertype->caneditamount = $objp->caneditamount;
315 
316 
317  if ($mode == 'kanban') {
318  if ($i == 0) {
319  print '<tr><td colspan="12">';
320  print '<div class="box-flex-container">';
321  }
322  //output kanban
323  $membertype->label = $objp->label;
324  $membertype->getKanbanView('');
325  if ($i == ($imaxinloop - 1)) {
326  print '</div>';
327  print '</td></tr>';
328  }
329  } else {
330  print '<tr class="oddeven">';
331  print '<td class="nowraponall">';
332  print $membertype->getNomUrl(1);
333  //<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$objp->rowid.'">'.img_object($langs->trans("ShowType"),'group').' '.$objp->rowid.'</a>
334  print '</td>';
335  print '<td>'.dol_escape_htmltag($objp->label).'</td>';
336  print '<td class="center">';
337  if ($objp->morphy == 'phy') {
338  print $langs->trans("Physical");
339  } elseif ($objp->morphy == 'mor') {
340  print $langs->trans("Moral");
341  } else {
342  print $langs->trans("MorAndPhy");
343  }
344  print '</td>';
345  print '<td class="center">'.yn($objp->subscription).'</td>';
346  print '<td class="center"><span class="amount">'.(is_null($objp->amount) || $objp->amount === '' ? '' : price($objp->amount)).'</span></td>';
347  print '<td class="center">'.yn($objp->caneditamount).'</td>';
348  print '<td class="center">'.yn($objp->vote).'</td>';
349  print '<td class="center">'.$membertype->getLibStatut(5).'</td>';
350  if ($user->rights->adherent->configurer) {
351  print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit&rowid='.$objp->rowid.'">'.img_edit().'</a></td>';
352  } else {
353  print '<td class="right">&nbsp;</td>';
354  }
355  print "</tr>";
356  }
357  $i++;
358  }
359 
360  // If no record found
361  if ($num == 0) {
362  /*$colspan = 1;
363  foreach ($arrayfields as $key => $val) {
364  if (!empty($val['checked'])) {
365  $colspan++;
366  }
367  }*/
368  $colspan = 8;
369  print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
370  }
371 
372  print "</table>";
373  print '</div>';
374 
375  print '</form>';
376  } else {
377  dol_print_error($db);
378  }
379 }
380 
381 // Creation
382 if ($action == 'create') {
383  $object = new AdherentType($db);
384 
385  print load_fiche_titre($langs->trans("NewMemberType"), '', 'members');
386 
387  print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
388  print '<input type="hidden" name="token" value="'.newToken().'">';
389  print '<input type="hidden" name="action" value="add">';
390 
391  print dol_get_fiche_head('');
392 
393  print '<table class="border centpercent">';
394  print '<tbody>';
395 
396  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth200" name="label" autofocus="autofocus"></td></tr>';
397 
398  print '<tr><td>'.$langs->trans("Status").'</td><td>';
399  print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
400  print '</td></tr>';
401 
402  // Morphy
403  $morphys = array();
404  $morphys[""] = $langs->trans("MorAndPhy");
405  $morphys["phy"] = $langs->trans("Physical");
406  $morphys["mor"] = $langs->trans("Moral");
407  print '<tr><td><span>'.$langs->trans("MembersNature").'</span></td><td>';
408  print $form->selectarray("morphy", $morphys, GETPOSTISSET("morphy") ? GETPOST("morphy", 'aZ09') : 'morphy');
409  print "</td></tr>";
410 
411  print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
412  print $form->selectyesno("subscription", 1, 1);
413  print '</td></tr>';
414 
415  print '<tr><td>'.$langs->trans("Amount").'</td><td>';
416  print '<input name="amount" size="5" value="'.(GETPOSTISSET('amount') ? GETPOST('amount') : price($amount)).'">';
417  print '</td></tr>';
418 
419  print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).'</td><td>';
420  print $form->selectyesno("caneditamount", GETPOSTISSET('caneditamount') ? GETPOST('caneditamount') : 0, 1);
421  print '</td></tr>';
422 
423  print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
424  print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1);
425  print '</td></tr>';
426 
427  print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="3">';
428  print '<input name="duration_value" size="5" value="'.GETPOST('duraction_unit', 'aZ09').'"> ';
429  print $formproduct->selectMeasuringUnits("duration_unit", "time", GETPOSTISSET("duration_unit") ? GETPOST('duration_unit', 'aZ09') : 'y', 0, 1);
430  print '</td></tr>';
431 
432  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
433  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
434  $doleditor = new DolEditor('comment', (GETPOSTISSET('comment') ? GETPOST('comment', 'restricthtml') : $object->note_public), '', 200, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
435  $doleditor->Create();
436 
437  print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
438  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
439  $doleditor = new DolEditor('mail_valid', GETPOSTISSET('mail_valid') ? GETPOST('mail_valid') : $object->mail_valid, '', 250, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
440  $doleditor->Create();
441  print '</td></tr>';
442 
443  // Other attributes
444  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
445 
446  print '<tbody>';
447  print "</table>\n";
448 
449  print dol_get_fiche_end();
450 
451  print $form->buttonsSaveCancel();
452 
453  print "</form>\n";
454 }
455 
456 // View
457 if ($rowid > 0) {
458  if ($action != 'edit') {
459  $object = new AdherentType($db);
460  $object->fetch($rowid);
461  $object->fetch_optionals();
462 
463  /*
464  * Confirmation deletion
465  */
466  if ($action == 'delete') {
467  print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$object->id, $langs->trans("DeleteAMemberType"), $langs->trans("ConfirmDeleteMemberType", $object->label), "confirm_delete", '', 0, 1);
468  }
469 
470  $head = member_type_prepare_head($object);
471 
472  print dol_get_fiche_head($head, 'card', $langs->trans("MemberType"), -1, 'group');
473 
474  $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
475 
476  dol_banner_tab($object, 'rowid', $linkback);
477 
478  print '<div class="fichecenter">';
479  print '<div class="underbanner clearboth"></div>';
480 
481  print '<table class="tableforfield border centpercent">';
482 
483  // Morphy
484  print '<tr><td>'.$langs->trans("MembersNature").'</td><td class="valeur" >'.$object->getmorphylib($object->morphy).'</td>';
485  print '</tr>';
486 
487  print '<tr><td class="titlefield">'.$langs->trans("SubscriptionRequired").'</td><td>';
488  print yn($object->subscription);
489  print '</tr>';
490 
491  // Amount
492  print '<tr><td class="titlefield">'.$langs->trans("Amount").'</td><td>';
493  print ((is_null($object->amount) || $object->amount === '') ? '' : '<span class="amount">'.price($object->amount).'</span>');
494  print '</tr>';
495 
496  print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmount")).'</td><td>';
497  print yn($object->caneditamount);
498  print '</td></tr>';
499 
500  print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
501  print yn($object->vote);
502  print '</tr>';
503 
504  print '<tr><td class="titlefield">'.$langs->trans("Duration").'</td><td colspan="2">'.$object->duration_value.'&nbsp;';
505  if ($object->duration_value > 1) {
506  $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hours"), "d"=>$langs->trans("Days"), "w"=>$langs->trans("Weeks"), "m"=>$langs->trans("Months"), "y"=>$langs->trans("Years"));
507  } elseif ($object->duration_value > 0) {
508  $dur = array("i"=>$langs->trans("Minute"), "h"=>$langs->trans("Hour"), "d"=>$langs->trans("Day"), "w"=>$langs->trans("Week"), "m"=>$langs->trans("Month"), "y"=>$langs->trans("Year"));
509  }
510  print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')."&nbsp;";
511  print '</td></tr>';
512 
513  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
514  print nl2br($object->note)."</td></tr>";
515 
516  print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
517  print nl2br($object->mail_valid)."</td></tr>";
518 
519  // Other attributes
520  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
521 
522  print '</table>';
523  print '</div>';
524 
525  print dol_get_fiche_end();
526 
527  /*
528  * Buttons
529  */
530 
531  print '<div class="tabsAction">';
532 
533  // Edit
534  if ($user->hasRight('adherent', 'configurer')) {
535  print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&rowid='.$object->id.'">'.$langs->trans("Modify").'</a></div>';
536  }
537 
538  // Add
539  if ($user->hasRight('adherent', 'configurer')&& !empty($object->status)) {
540  print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=create&token='.newToken().'&typeid='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?rowid='.$object->id).'">'.$langs->trans("AddMember").'</a></div>';
541  } else {
542  print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoAddMember")).'">'.$langs->trans("AddMember").'</a></div>';
543  }
544 
545  // Delete
546  if ($user->hasRight('adherent', 'configurer')) {
547  print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&rowid='.$object->id.'">'.$langs->trans("DeleteType").'</a></div>';
548  }
549 
550  print "</div>";
551 
552 
553  // Show list of members (nearly same code than in page list.php)
554 
555  $membertypestatic = new AdherentType($db);
556 
557  $now = dol_now();
558 
559  $sql = "SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe as company,";
560  $sql .= " d.datefin,";
561  $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut as status,";
562  $sql .= " t.libelle as type, t.subscription, t.amount";
563  $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
564  $sql .= " WHERE d.fk_adherent_type = t.rowid ";
565  $sql .= " AND d.entity IN (".getEntity('adherent').")";
566  $sql .= " AND t.rowid = ".((int) $object->id);
567  if ($sall) {
568  $sql .= natural_search(array("d.firstname", "d.lastname", "d.societe", "d.email", "d.login", "d.address", "d.town", "d.note_public", "d.note_private"), $sall);
569  }
570  if ($status != '') {
571  $sql .= natural_search('d.statut', $status, 2);
572  }
573  if ($action == 'search') {
574  if (GETPOST('search', 'alpha')) {
575  $sql .= natural_search(array("d.firstname", "d.lastname"), GETPOST('search', 'alpha'));
576  }
577  }
578  if (!empty($search_lastname)) {
579  $sql .= natural_search(array("d.firstname", "d.lastname"), $search_lastname);
580  }
581  if (!empty($search_login)) {
582  $sql .= natural_search("d.login", $search_login);
583  }
584  if (!empty($search_email)) {
585  $sql .= natural_search("d.email", $search_email);
586  }
587  if ($filter == 'uptodate') {
588  $sql .= " AND (datefin >= '".$db->idate($now)."') OR t.subscription = 0)";
589  }
590  if ($filter == 'outofdate') {
591  $sql .= " AND (datefin < '".$db->idate($now)."' AND t.subscription = 1)";
592  }
593 
594  $sql .= " ".$db->order($sortfield, $sortorder);
595 
596  // Count total nb of records
597  $nbtotalofrecords = '';
598  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
599  $resql = $db->query($sql);
600  if ($resql) {
601  $nbtotalofrecords = $db->num_rows($result);
602  } else {
603  dol_print_error($db);
604  }
605  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
606  $page = 0;
607  $offset = 0;
608  }
609  }
610 
611  $sql .= " ".$db->plimit($conf->liste_limit + 1, $offset);
612 
613  $resql = $db->query($sql);
614  if ($resql) {
615  $num = $db->num_rows($resql);
616  $i = 0;
617 
618  $titre = $langs->trans("MembersList");
619  if ($status != '') {
620  if ($status == '-1,1') {
621  $titre = $langs->trans("MembersListQualified");
622  } elseif ($status == '-1') {
623  $titre = $langs->trans("MembersListToValid");
624  } elseif ($status == '1' && !$filter) {
625  $titre = $langs->trans("MembersListValid");
626  } elseif ($status == '1' && $filter == 'uptodate') {
627  $titre = $langs->trans("MembersListUpToDate");
628  } elseif ($status == '1' && $filter == 'outofdate') {
629  $titre = $langs->trans("MembersListNotUpToDate");
630  } elseif ($status == '0') {
631  $titre = $langs->trans("MembersListResiliated");
632  } elseif ($status == '-2') {
633  $titre = $langs->trans("MembersListExcluded");
634  }
635  } elseif ($action == 'search') {
636  $titre = $langs->trans("MembersListQualified");
637  }
638 
639  if ($type > 0) {
640  $membertype = new AdherentType($db);
641  $result = $membertype->fetch($type);
642  $titre .= " (".$membertype->label.")";
643  }
644 
645  $param = "&rowid=".urlencode($object->id);
646  if (!empty($status)) {
647  $param .= "&status=".urlencode($status);
648  }
649  if (!empty($search_lastname)) {
650  $param .= "&search_lastname=".urlencode($search_lastname);
651  }
652  if (!empty($search_firstname)) {
653  $param .= "&search_firstname=".urlencode($search_firstname);
654  }
655  if (!empty($search_login)) {
656  $param .= "&search_login=".urlencode($search_login);
657  }
658  if (!empty($search_email)) {
659  $param .= "&search_email=".urlencode($search_email);
660  }
661  if (!empty($filter)) {
662  $param .= "&filter=".urlencode($filter);
663  }
664 
665  if ($sall) {
666  print $langs->trans("Filter")." (".$langs->trans("Lastname").", ".$langs->trans("Firstname").", ".$langs->trans("EMail").", ".$langs->trans("Address")." ".$langs->trans("or")." ".$langs->trans("Town")."): ".$sall;
667  }
668 
669  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
670  print '<input type="hidden" name="token" value="'.newToken().'">';
671  print '<input class="flat" type="hidden" name="rowid" value="'.$object->id.'" size="12"></td>';
672 
673  print '<br>';
674  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
675 
676  $moreforfilter = '';
677 
678  print '<div class="div-table-responsive">';
679  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
680 
681  // Fields title search
682  print '<tr class="liste_titre_filter">';
683 
684  print '<td class="liste_titre left">';
685  print '<input class="flat" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'" size="12"></td>';
686 
687  print '<td class="liste_titre left">';
688  print '<input class="flat" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'" size="7"></td>';
689 
690  print '<td class="liste_titre">&nbsp;</td>';
691 
692  print '<td class="liste_titre left">';
693  print '<input class="flat" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'" size="12"></td>';
694 
695  print '<td class="liste_titre">&nbsp;</td>';
696 
697  print '<td class="liste_titre right" colspan="2">';
698  print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
699  print '&nbsp; ';
700  print '<input type="image" class="liste_titre" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" name="button_removefilter" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
701  print '</td>';
702 
703  print "</tr>\n";
704 
705  print '<tr class="liste_titre">';
706  print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
707  print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
708  print_liste_field_titre("MemberNature", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
709  print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
710  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
711  print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", 'align="center"', $sortfield, $sortorder);
712  print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", $param, "", 'width="60" align="center"', $sortfield, $sortorder);
713  print "</tr>\n";
714 
715  $adh = new Adherent($db);
716 
717  $imaxinloop = ($limit ? min($num, $limit) : $num);
718  while ($i < $imaxinloop) {
719  $objp = $db->fetch_object($resql);
720 
721  $datefin = $db->jdate($objp->datefin);
722 
723  $adh->lastname = $objp->lastname;
724  $adh->firstname = $objp->firstname;
725  $adh->datefin = $datefin;
726  $adh->need_subscription = $objp->subscription;
727  $adh->statut = $objp->status;
728 
729  print '<tr class="oddeven">';
730 
731  // Lastname
732  if ($objp->company != '') {
733  print '<td><a href="card.php?rowid='.$objp->rowid.'">'.img_object($langs->trans("ShowMember"), "user", 'class="paddingright"').$adh->getFullName($langs, 0, -1, 20).' / '.dol_trunc($objp->company, 12).'</a></td>'."\n";
734  } else {
735  print '<td><a href="card.php?rowid='.$objp->rowid.'">'.img_object($langs->trans("ShowMember"), "user", 'class="paddingright"').$adh->getFullName($langs, 0, -1, 32).'</a></td>'."\n";
736  }
737 
738  // Login
739  print "<td>".dol_escape_htmltag($objp->login)."</td>\n";
740 
741  // Type
742  /*print '<td class="nowrap">';
743  $membertypestatic->id=$objp->type_id;
744  $membertypestatic->label=$objp->type;
745  print $membertypestatic->getNomUrl(1,12);
746  print '</td>';
747  */
748 
749  // Moral/Physique
750  print "<td>".$adh->getmorphylib($objp->morphy, 1)."</td>\n";
751 
752  // EMail
753  print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
754 
755  // Status
756  print '<td class="nowrap">';
757  print $adh->getLibStatut(2);
758  print "</td>";
759 
760  // Date end subscription
761  if ($datefin) {
762  print '<td class="nowrap center">';
763  if ($datefin < dol_now() && $objp->status > 0) {
764  print dol_print_date($datefin, 'day')." ".img_warning($langs->trans("SubscriptionLate"));
765  } else {
766  print dol_print_date($datefin, 'day');
767  }
768  print '</td>';
769  } else {
770  print '<td class="nowrap center">';
771  if (!empty($objp->subscription)) {
772  print '<span class="opacitymedium">'.$langs->trans("SubscriptionNotReceived").'</span>';
773  if ($objp->status > 0) {
774  print " ".img_warning();
775  }
776  } else {
777  print '&nbsp;';
778  }
779  print '</td>';
780  }
781 
782  // Actions
783  print '<td class="center">';
784  if ($user->hasRight('adherent', 'creer')) {
785  print '<a class="editfielda marginleftonly" href="card.php?rowid='.$objp->rowid.'&action=edit&token='.newToken().'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?rowid='.$object->id).'">'.img_edit().'</a>';
786  }
787  if ($user->hasRight('adherent', 'supprimer')) {
788  print '<a class="marginleftonly" href="card.php?rowid='.$objp->rowid.'&action=resiliate&token='.newToken().'">'.img_picto($langs->trans("Resiliate"), 'disable.png').'</a>';
789  }
790  print "</td>";
791 
792  print "</tr>\n";
793  $i++;
794  }
795 
796  if ($i == 0) {
797  print '<tr><td colspan="7"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
798  }
799 
800  print "</table>\n";
801  print '</div>';
802  print '</form>';
803 
804  if ($num > $limit) {
805  print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
806  }
807  } else {
808  dol_print_error($db);
809  }
810  }
811 
812  /* ************************************************************************** */
813  /* */
814  /* Edition mode */
815  /* */
816  /* ************************************************************************** */
817 
818  if ($action == 'edit') {
819  $object = new AdherentType($db);
820  $object->fetch($rowid);
821  $object->fetch_optionals();
822 
823  $head = member_type_prepare_head($object);
824 
825  print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'">';
826  print '<input type="hidden" name="token" value="'.newToken().'">';
827  print '<input type="hidden" name="rowid" value="'.$object->id.'">';
828  print '<input type="hidden" name="action" value="update">';
829 
830  print dol_get_fiche_head($head, 'card', $langs->trans("MemberType"), 0, 'group');
831 
832  print '<table class="border centpercent">';
833 
834  print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->id.'</td></tr>';
835 
836  print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth300" name="label" value="'.dol_escape_htmltag($object->label).'"></td></tr>';
837 
838  print '<tr><td>'.$langs->trans("Status").'</td><td>';
839  print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
840  print '</td></tr>';
841 
842  // Morphy
843  $morphys[""] = $langs->trans("MorAndPhy");
844  $morphys["phy"] = $langs->trans("Physical");
845  $morphys["mor"] = $langs->trans("Moral");
846  print '<tr><td><span>'.$langs->trans("MembersNature").'</span></td><td>';
847  print $form->selectarray("morphy", $morphys, GETPOSTISSET("morphy") ? GETPOST("morphy", 'aZ09') : $object->morphy);
848  print "</td></tr>";
849 
850  print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
851  print $form->selectyesno("subscription", $object->subscription, 1);
852  print '</td></tr>';
853 
854  print '<tr><td>'.$langs->trans("Amount").'</td><td>';
855  print '<input name="amount" size="5" value="';
856  print ((is_null($object->amount) || $object->amount === '') ? '' : price($object->amount));
857  print '">';
858  print '</td></tr>';
859 
860  print '<tr><td>'.$form->textwithpicto($langs->trans("CanEditAmountShort"), $langs->transnoentities("CanEditAmountDetail")).'</td><td>';
861  print $form->selectyesno("caneditamount", $object->caneditamount, 1);
862  print '</td></tr>';
863 
864  print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
865  print $form->selectyesno("vote", $object->vote, 1);
866  print '</td></tr>';
867 
868  print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="3">';
869  print '<input name="duration_value" size="5" value="'.$object->duration_value.'"> ';
870  print $formproduct->selectMeasuringUnits("duration_unit", "time", ($object->duration_unit === '' ? 'y' : $object->duration_unit), 0, 1);
871  print '</td></tr>';
872 
873  print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
874  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
875  $doleditor = new DolEditor('comment', $object->note_public, '', 220, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
876  $doleditor->Create();
877  print "</td></tr>";
878 
879  print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
880  $doleditor = new DolEditor('mail_valid', $object->mail_valid, '', 280, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
881  $doleditor->Create();
882  print "</td></tr>";
883 
884  // Other attributes
885  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
886 
887  print '</table>';
888 
889  print dol_get_fiche_end();
890 
891  print $form->buttonsSaveCancel();
892 
893  print "</form>";
894  }
895 }
896 
897 // End of page
898 llxFooter();
899 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage members of a foundation.
Class to manage members type.
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
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.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
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='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
member_type_prepare_head(AdherentType $object)
Return array head with list of tabs to view object informations.
Definition: member.lib.php:153
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
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.