type.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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 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. /**
  26. * \file htdocs/adherents/type.php
  27. * \ingroup member
  28. * \brief Member's type setup
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  36. $langs->load("members");
  37. $rowid = GETPOST('rowid', 'int');
  38. $action = GETPOST('action', 'aZ09');
  39. $cancel = GETPOST('cancel', 'alpha');
  40. $backtopage = GETPOST('backtopage', 'alpha');
  41. $sall = GETPOST("sall", "alpha");
  42. $filter = GETPOST("filter", 'alpha');
  43. $search_lastname = GETPOST('search_lastname', 'alpha');
  44. $search_login = GETPOST('search_login', 'alpha');
  45. $search_email = GETPOST('search_email', 'alpha');
  46. $type = GETPOST('type', 'intcomma');
  47. $status = GETPOST('status', 'alpha');
  48. $optioncss = GETPOST('optioncss', 'alpha');
  49. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  50. $sortfield = GETPOST('sortfield', 'aZ09comma');
  51. $sortorder = GETPOST('sortorder', 'aZ09comma');
  52. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  53. if (empty($page) || $page == -1) {
  54. $page = 0;
  55. } // If $page is not defined, or '' or -1
  56. $offset = $limit * $page;
  57. $pageprev = $page - 1;
  58. $pagenext = $page + 1;
  59. if (!$sortorder) {
  60. $sortorder = "DESC";
  61. }
  62. if (!$sortfield) {
  63. $sortfield = "d.lastname";
  64. }
  65. $label = GETPOST("label", "alpha");
  66. $morphy = GETPOST("morphy", "alpha");
  67. $status = GETPOST("status", "int");
  68. $subscription = GETPOST("subscription", "int");
  69. $amount = GETPOST('amount', 'alpha');
  70. $duration_value = GETPOST('duration_value', 'int');
  71. $duration_unit = GETPOST('duration_unit', 'alpha');
  72. $vote = GETPOST("vote", "int");
  73. $comment = GETPOST("comment", 'restricthtml');
  74. $mail_valid = GETPOST("mail_valid", 'restricthtml');
  75. // Security check
  76. $result = restrictedArea($user, 'adherent', $rowid, 'adherent_type');
  77. $object = new AdherentType($db);
  78. $extrafields = new ExtraFields($db);
  79. // fetch optionals attributes and labels
  80. $extrafields->fetch_name_optionals_label($object->table_element);
  81. 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
  82. $search_lastname = "";
  83. $search_login = "";
  84. $search_email = "";
  85. $type = "";
  86. $sall = "";
  87. }
  88. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  89. $hookmanager->initHooks(array('membertypecard', 'globalcard'));
  90. /*
  91. * Actions
  92. */
  93. if ($cancel) {
  94. $action = '';
  95. if (!empty($backtopage)) {
  96. header("Location: ".$backtopage);
  97. exit;
  98. }
  99. }
  100. if ($action == 'add' && $user->rights->adherent->configurer) {
  101. $object->label = trim($label);
  102. $object->morphy = trim($morphy);
  103. $object->status = (int) $status;
  104. $object->subscription = (int) $subscription;
  105. $object->amount = ($amount == '' ? '' : price2num($amount, 'MT'));
  106. $object->duration_value = $duration_value;
  107. $object->duration_unit = $duration_unit;
  108. $object->note = trim($comment);
  109. $object->mail_valid = trim($mail_valid);
  110. $object->vote = (int) $vote;
  111. // Fill array 'array_options' with data from add form
  112. $ret = $extrafields->setOptionalsFromPost(null, $object);
  113. if ($ret < 0) {
  114. $error++;
  115. }
  116. if (empty($object->label)) {
  117. $error++;
  118. setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors');
  119. } else {
  120. $sql = "SELECT libelle FROM ".MAIN_DB_PREFIX."adherent_type WHERE libelle='".$db->escape($object->label)."'";
  121. $result = $db->query($sql);
  122. if ($result) {
  123. $num = $db->num_rows($result);
  124. }
  125. if ($num) {
  126. $error++;
  127. $langs->load("errors");
  128. setEventMessages($langs->trans("ErrorLabelAlreadyExists", $login), null, 'errors');
  129. }
  130. }
  131. if (!$error) {
  132. $id = $object->create($user);
  133. if ($id > 0) {
  134. header("Location: ".$_SERVER["PHP_SELF"]);
  135. exit;
  136. } else {
  137. setEventMessages($object->error, $object->errors, 'errors');
  138. $action = 'create';
  139. }
  140. } else {
  141. $action = 'create';
  142. }
  143. }
  144. if ($action == 'update' && $user->rights->adherent->configurer) {
  145. $object->fetch($rowid);
  146. $object->oldcopy = clone $object;
  147. $object->label= trim($label);
  148. $object->morphy = trim($morphy);
  149. $object->status = (int) $status;
  150. $object->subscription = (int) $subscription;
  151. $object->amount = ($amount == '' ? '' : price2num($amount, 'MT'));
  152. $object->duration_value = $duration_value;
  153. $object->duration_unit = $duration_unit;
  154. $object->note = trim($comment);
  155. $object->mail_valid = trim($mail_valid);
  156. $object->vote = (boolean) trim($vote);
  157. // Fill array 'array_options' with data from add form
  158. $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
  159. if ($ret < 0) {
  160. $error++;
  161. }
  162. $ret = $object->update($user);
  163. if ($ret >= 0 && !count($object->errors)) {
  164. setEventMessages($langs->trans("MemberTypeModified"), null, 'mesgs');
  165. } else {
  166. setEventMessages($object->error, $object->errors, 'errors');
  167. }
  168. header("Location: ".$_SERVER["PHP_SELF"]."?rowid=".$object->id);
  169. exit;
  170. }
  171. if ($action == 'confirm_delete' && $user->rights->adherent->configurer) {
  172. $object->fetch($rowid);
  173. $res = $object->delete();
  174. if ($res > 0) {
  175. setEventMessages($langs->trans("MemberTypeDeleted"), null, 'mesgs');
  176. header("Location: ".$_SERVER["PHP_SELF"]);
  177. exit;
  178. } else {
  179. setEventMessages($langs->trans("MemberTypeCanNotBeDeleted"), null, 'errors');
  180. $action = '';
  181. }
  182. }
  183. /*
  184. * View
  185. */
  186. $form = new Form($db);
  187. $formproduct = new FormProduct($db);
  188. $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
  189. llxHeader('', $langs->trans("MembersTypeSetup"), $help_url);
  190. // List of members type
  191. if (!$rowid && $action != 'create' && $action != 'edit') {
  192. //print dol_get_fiche_head('');
  193. $sql = "SELECT d.rowid, d.libelle as label, d.subscription, d.amount, d.vote, d.statut as status, d.morphy";
  194. $sql .= " FROM ".MAIN_DB_PREFIX."adherent_type as d";
  195. $sql .= " WHERE d.entity IN (".getEntity('member_type').")";
  196. $result = $db->query($sql);
  197. if ($result) {
  198. $num = $db->num_rows($result);
  199. $nbtotalofrecords = $num;
  200. $i = 0;
  201. $param = '';
  202. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  203. $param .= '&contextpage='.$contextpage;
  204. }
  205. if ($limit > 0 && $limit != $conf->liste_limit) {
  206. $param .= '&limit='.$limit;
  207. }
  208. $newcardbutton = '';
  209. if ($user->rights->adherent->configurer) {
  210. $newcardbutton .= dolGetButtonTitle($langs->trans('NewMemberType'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/type.php?action=create');
  211. }
  212. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  213. if ($optioncss != '') {
  214. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  215. }
  216. print '<input type="hidden" name="token" value="'.newToken().'">';
  217. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  218. print '<input type="hidden" name="action" value="list">';
  219. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  220. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  221. print_barre_liste($langs->trans("MembersTypes"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'members', 0, $newcardbutton, '', $limit, 0, 0, 1);
  222. $moreforfilter = '';
  223. print '<div class="div-table-responsive">';
  224. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  225. print '<tr class="liste_titre">';
  226. print '<th>'.$langs->trans("Ref").'</th>';
  227. print '<th>'.$langs->trans("Label").'</th>';
  228. print '<th class="center">'.$langs->trans("MembersNature").'</th>';
  229. print '<th class="center">'.$langs->trans("SubscriptionRequired").'</th>';
  230. print '<th class="center">'.$langs->trans("Amount").'</th>';
  231. print '<th class="center">'.$langs->trans("VoteAllowed").'</th>';
  232. print '<th class="center">'.$langs->trans("Status").'</th>';
  233. print '<th>&nbsp;</th>';
  234. print "</tr>\n";
  235. $membertype = new AdherentType($db);
  236. while ($i < $num) {
  237. $objp = $db->fetch_object($result);
  238. $membertype->id = $objp->rowid;
  239. $membertype->ref = $objp->rowid;
  240. $membertype->label = $objp->rowid;
  241. $membertype->status = $objp->status;
  242. $membertype->subscription = $objp->subscription;
  243. $membertype->amount = $objp->amount;
  244. print '<tr class="oddeven">';
  245. print '<td class="nowraponall">';
  246. print $membertype->getNomUrl(1);
  247. //<a href="'.$_SERVER["PHP_SELF"].'?rowid='.$objp->rowid.'">'.img_object($langs->trans("ShowType"),'group').' '.$objp->rowid.'</a>
  248. print '</td>';
  249. print '<td>'.dol_escape_htmltag($objp->label).'</td>';
  250. print '<td class="center">';
  251. if ($objp->morphy == 'phy') {
  252. print $langs->trans("Physical");
  253. } elseif ($objp->morphy == 'mor') {
  254. print $langs->trans("Moral");
  255. } else {
  256. print $langs->trans("MorAndPhy");
  257. }
  258. print '</td>';
  259. print '<td class="center">'.yn($objp->subscription).'</td>';
  260. print '<td class="center"><span class="amount">'.(is_null($objp->amount) || $objp->amount === '' ? '' : price($objp->amount)).'</span></td>';
  261. print '<td class="center">'.yn($objp->vote).'</td>';
  262. print '<td class="center">'.$membertype->getLibStatut(5).'</td>';
  263. if ($user->rights->adherent->configurer) {
  264. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edit&rowid='.$objp->rowid.'">'.img_edit().'</a></td>';
  265. } else {
  266. print '<td class="right">&nbsp;</td>';
  267. }
  268. print "</tr>";
  269. $i++;
  270. }
  271. // If no record found
  272. if ($num == 0) {
  273. /*$colspan = 1;
  274. foreach ($arrayfields as $key => $val) {
  275. if (!empty($val['checked'])) {
  276. $colspan++;
  277. }
  278. }*/
  279. $colspan = 8;
  280. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  281. }
  282. print "</table>";
  283. print '</div>';
  284. print '</form>';
  285. } else {
  286. dol_print_error($db);
  287. }
  288. }
  289. // Creation
  290. if ($action == 'create') {
  291. $object = new AdherentType($db);
  292. print load_fiche_titre($langs->trans("NewMemberType"), '', 'members');
  293. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  294. print '<input type="hidden" name="token" value="'.newToken().'">';
  295. print '<input type="hidden" name="action" value="add">';
  296. print dol_get_fiche_head('');
  297. print '<table class="border centpercent">';
  298. print '<tbody>';
  299. print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" class="minwidth200" name="label" autofocus="autofocus"></td></tr>';
  300. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  301. print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), 1);
  302. print '</td></tr>';
  303. // Morphy
  304. $morphys = array();
  305. $morphys[""] = $langs->trans("MorAndPhy");
  306. $morphys["phy"] = $langs->trans("Physical");
  307. $morphys["mor"] = $langs->trans("Moral");
  308. print '<tr><td><span>'.$langs->trans("MembersNature").'</span></td><td>';
  309. print $form->selectarray("morphy", $morphys, GETPOSTISSET("morphy") ? GETPOST("morphy", 'aZ09') : 'morphy');
  310. print "</td></tr>";
  311. print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
  312. print $form->selectyesno("subscription", 1, 1);
  313. print '</td></tr>';
  314. print '<tr><td>'.$langs->trans("Amount").'</td><td>';
  315. print '<input name="amount" size="5" value="'.price($amount).'">';
  316. print '</td></tr>';
  317. print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
  318. print $form->selectyesno("vote", GETPOSTISSET("vote") ? GETPOST('vote', 'aZ09') : 1, 1);
  319. print '</td></tr>';
  320. print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="3">';
  321. print '<input name="duration_value" size="5" value="'.GETPOST('duraction_unit', 'aZ09').'"> ';
  322. print $formproduct->selectMeasuringUnits("duration_unit", "time", GETPOSTISSET("duration_unit") ? GETPOST('duration_unit', 'aZ09') : 'y', 0, 1);
  323. print '</td></tr>';
  324. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  325. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  326. $doleditor = new DolEditor('comment', $object->note, '', 200, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
  327. $doleditor->Create();
  328. print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
  329. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  330. $doleditor = new DolEditor('mail_valid', $object->mail_valid, '', 250, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
  331. $doleditor->Create();
  332. print '</td></tr>';
  333. // Other attributes
  334. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  335. print '<tbody>';
  336. print "</table>\n";
  337. print dol_get_fiche_end();
  338. print $form->buttonsSaveCancel();
  339. print "</form>\n";
  340. }
  341. // View
  342. if ($rowid > 0) {
  343. if ($action != 'edit') {
  344. $object = new AdherentType($db);
  345. $object->fetch($rowid);
  346. $object->fetch_optionals();
  347. /*
  348. * Confirmation deletion
  349. */
  350. if ($action == 'delete') {
  351. print $form->formconfirm($_SERVER['PHP_SELF']."?rowid=".$object->id, $langs->trans("DeleteAMemberType"), $langs->trans("ConfirmDeleteMemberType", $object->label), "confirm_delete", '', 0, 1);
  352. }
  353. $head = member_type_prepare_head($object);
  354. print dol_get_fiche_head($head, 'card', $langs->trans("MemberType"), -1, 'group');
  355. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/type.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  356. dol_banner_tab($object, 'rowid', $linkback);
  357. print '<div class="fichecenter">';
  358. print '<div class="underbanner clearboth"></div>';
  359. print '<table class="border centpercent">';
  360. // Morphy
  361. print '<tr><td>'.$langs->trans("MembersNature").'</td><td class="valeur" >'.$object->getmorphylib($object->morphy).'</td>';
  362. print '</tr>';
  363. print '<tr><td class="titlefield">'.$langs->trans("SubscriptionRequired").'</td><td>';
  364. print yn($object->subscription);
  365. print '</tr>';
  366. // Amount
  367. print '<tr><td class="titlefield">'.$langs->trans("Amount").'</td><td>';
  368. print ((is_null($object->amount) || $object->amount === '') ? '' : '<span class="amount">'.price($object->amount).'</span>');
  369. print '</tr>';
  370. print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
  371. print yn($object->vote);
  372. print '</tr>';
  373. print '<tr><td class="titlefield">'.$langs->trans("Duration").'</td><td colspan="2">'.$object->duration_value.'&nbsp;';
  374. if ($object->duration_value > 1) {
  375. $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"));
  376. } elseif ($object->duration_value > 0) {
  377. $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"));
  378. }
  379. print (!empty($object->duration_unit) && isset($dur[$object->duration_unit]) ? $langs->trans($dur[$object->duration_unit]) : '')."&nbsp;";
  380. print '</td></tr>';
  381. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  382. print nl2br($object->note)."</td></tr>";
  383. print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
  384. print nl2br($object->mail_valid)."</td></tr>";
  385. // Other attributes
  386. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  387. print '</table>';
  388. print '</div>';
  389. print dol_get_fiche_end();
  390. /*
  391. * Buttons
  392. */
  393. print '<div class="tabsAction">';
  394. // Edit
  395. if ($user->rights->adherent->configurer) {
  396. 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>';
  397. }
  398. // Add
  399. if ($user->rights->adherent->configurer && !empty($object->status)) {
  400. 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>';
  401. } else {
  402. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NoAddMember")).'">'.$langs->trans("AddMember").'</a></div>';
  403. }
  404. // Delete
  405. if ($user->rights->adherent->configurer) {
  406. 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>';
  407. }
  408. print "</div>";
  409. // Show list of members (nearly same code than in page list.php)
  410. $membertypestatic = new AdherentType($db);
  411. $now = dol_now();
  412. $sql = "SELECT d.rowid, d.login, d.firstname, d.lastname, d.societe as company,";
  413. $sql .= " d.datefin,";
  414. $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut as status,";
  415. $sql .= " t.libelle as type, t.subscription, t.amount";
  416. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."adherent_type as t";
  417. $sql .= " WHERE d.fk_adherent_type = t.rowid ";
  418. $sql .= " AND d.entity IN (".getEntity('adherent').")";
  419. $sql .= " AND t.rowid = ".((int) $object->id);
  420. if ($sall) {
  421. $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);
  422. }
  423. if ($status != '') {
  424. $sql .= natural_search('d.statut', $status, 2);
  425. }
  426. if ($action == 'search') {
  427. if (GETPOST('search', 'alpha')) {
  428. $sql .= natural_search(array("d.firstname", "d.lastname"), GETPOST('search', 'alpha'));
  429. }
  430. }
  431. if (!empty($search_lastname)) {
  432. $sql .= natural_search(array("d.firstname", "d.lastname"), $search_lastname);
  433. }
  434. if (!empty($search_login)) {
  435. $sql .= natural_search("d.login", $search_login);
  436. }
  437. if (!empty($search_email)) {
  438. $sql .= natural_search("d.email", $search_email);
  439. }
  440. if ($filter == 'uptodate') {
  441. $sql .= " AND (datefin >= '".$db->idate($now)."') OR t.subscription = 0)";
  442. }
  443. if ($filter == 'outofdate') {
  444. $sql .= " AND (datefin < '".$db->idate($now)."' AND t.subscription = 1)";
  445. }
  446. $sql .= " ".$db->order($sortfield, $sortorder);
  447. // Count total nb of records
  448. $nbtotalofrecords = '';
  449. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  450. $resql = $db->query($sql);
  451. if ($resql) {
  452. $nbtotalofrecords = $db->num_rows($result);
  453. } else {
  454. dol_print_error($db);
  455. }
  456. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  457. $page = 0;
  458. $offset = 0;
  459. }
  460. }
  461. $sql .= " ".$db->plimit($conf->liste_limit + 1, $offset);
  462. $resql = $db->query($sql);
  463. if ($resql) {
  464. $num = $db->num_rows($resql);
  465. $i = 0;
  466. $titre = $langs->trans("MembersList");
  467. if ($status != '') {
  468. if ($status == '-1,1') {
  469. $titre = $langs->trans("MembersListQualified");
  470. } elseif ($status == '-1') {
  471. $titre = $langs->trans("MembersListToValid");
  472. } elseif ($status == '1' && !$filter) {
  473. $titre = $langs->trans("MembersListValid");
  474. } elseif ($status == '1' && $filter == 'uptodate') {
  475. $titre = $langs->trans("MembersListUpToDate");
  476. } elseif ($status == '1' && $filter == 'outofdate') {
  477. $titre = $langs->trans("MembersListNotUpToDate");
  478. } elseif ($status == '0') {
  479. $titre = $langs->trans("MembersListResiliated");
  480. } elseif ($status == '-2') {
  481. $titre = $langs->trans("MembersListExcluded");
  482. }
  483. } elseif ($action == 'search') {
  484. $titre = $langs->trans("MembersListQualified");
  485. }
  486. if ($type > 0) {
  487. $membertype = new AdherentType($db);
  488. $result = $membertype->fetch($type);
  489. $titre .= " (".$membertype->label.")";
  490. }
  491. $param = "&rowid=".urlencode($object->id);
  492. if (!empty($status)) {
  493. $param .= "&status=".urlencode($status);
  494. }
  495. if (!empty($search_lastname)) {
  496. $param .= "&search_lastname=".urlencode($search_lastname);
  497. }
  498. if (!empty($search_firstname)) {
  499. $param .= "&search_firstname=".urlencode($search_firstname);
  500. }
  501. if (!empty($search_login)) {
  502. $param .= "&search_login=".urlencode($search_login);
  503. }
  504. if (!empty($search_email)) {
  505. $param .= "&search_email=".urlencode($search_email);
  506. }
  507. if (!empty($filter)) {
  508. $param .= "&filter=".urlencode($filter);
  509. }
  510. if ($sall) {
  511. print $langs->trans("Filter")." (".$langs->trans("Lastname").", ".$langs->trans("Firstname").", ".$langs->trans("EMail").", ".$langs->trans("Address")." ".$langs->trans("or")." ".$langs->trans("Town")."): ".$sall;
  512. }
  513. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  514. print '<input type="hidden" name="token" value="'.newToken().'">';
  515. print '<input class="flat" type="hidden" name="rowid" value="'.$object->id.'" size="12"></td>';
  516. print '<br>';
  517. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords);
  518. $moreforfilter = '';
  519. print '<div class="div-table-responsive">';
  520. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  521. // Fields title search
  522. print '<tr class="liste_titre_filter">';
  523. print '<td class="liste_titre left">';
  524. print '<input class="flat" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'" size="12"></td>';
  525. print '<td class="liste_titre left">';
  526. print '<input class="flat" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'" size="7"></td>';
  527. print '<td class="liste_titre">&nbsp;</td>';
  528. print '<td class="liste_titre left">';
  529. print '<input class="flat" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'" size="12"></td>';
  530. print '<td class="liste_titre">&nbsp;</td>';
  531. print '<td class="liste_titre right" colspan="2">';
  532. 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")).'">';
  533. print '&nbsp; ';
  534. 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")).'">';
  535. print '</td>';
  536. print "</tr>\n";
  537. print '<tr class="liste_titre">';
  538. print_liste_field_titre("NameSlashCompany", $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder);
  539. print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder);
  540. print_liste_field_titre("MemberNature", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder);
  541. print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder);
  542. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder);
  543. print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", 'align="center"', $sortfield, $sortorder);
  544. print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", $param, "", 'width="60" align="center"', $sortfield, $sortorder);
  545. print "</tr>\n";
  546. while ($i < $num && $i < $conf->liste_limit) {
  547. $objp = $db->fetch_object($resql);
  548. $datefin = $db->jdate($objp->datefin);
  549. $adh = new Adherent($db);
  550. $adh->lastname = $objp->lastname;
  551. $adh->firstname = $objp->firstname;
  552. $adh->datefin = $datefin;
  553. $adh->need_subscription = $objp->subscription;
  554. $adh->statut = $objp->status;
  555. // Lastname
  556. print '<tr class="oddeven">';
  557. if ($objp->company != '') {
  558. 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";
  559. } else {
  560. 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";
  561. }
  562. // Login
  563. print "<td>".$objp->login."</td>\n";
  564. // Type
  565. /*print '<td class="nowrap">';
  566. $membertypestatic->id=$objp->type_id;
  567. $membertypestatic->label=$objp->type;
  568. print $membertypestatic->getNomUrl(1,12);
  569. print '</td>';
  570. */
  571. // Moral/Physique
  572. print "<td>".$adh->getmorphylib($objp->morphy)."</td>\n";
  573. // EMail
  574. print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n";
  575. // Status
  576. print '<td class="nowrap">';
  577. print $adh->getLibStatut(2);
  578. print "</td>";
  579. // Date end subscription
  580. if ($datefin) {
  581. print '<td class="nowrap center">';
  582. if ($datefin < dol_now() && $objp->status > 0) {
  583. print dol_print_date($datefin, 'day')." ".img_warning($langs->trans("SubscriptionLate"));
  584. } else {
  585. print dol_print_date($datefin, 'day');
  586. }
  587. print '</td>';
  588. } else {
  589. print '<td class="nowrap left">';
  590. if (!empty($objp->subscription)) {
  591. print $langs->trans("SubscriptionNotReceived");
  592. if ($objp->status > 0) {
  593. print " ".img_warning();
  594. }
  595. } else {
  596. print '&nbsp;';
  597. }
  598. print '</td>';
  599. }
  600. // Actions
  601. print '<td class="center">';
  602. if ($user->rights->adherent->creer) {
  603. 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>';
  604. }
  605. if ($user->rights->adherent->supprimer) {
  606. print '<a class="marginleftonly" href="card.php?rowid='.$objp->rowid.'&action=resign&token='.newToken().'">'.img_picto($langs->trans("Resiliate"), 'disable.png').'</a>';
  607. }
  608. print "</td>";
  609. print "</tr>\n";
  610. $i++;
  611. }
  612. print "</table>\n";
  613. print '</div>';
  614. print '</form>';
  615. if ($num > $conf->liste_limit) {
  616. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
  617. }
  618. } else {
  619. dol_print_error($db);
  620. }
  621. }
  622. /* ************************************************************************** */
  623. /* */
  624. /* Edition mode */
  625. /* */
  626. /* ************************************************************************** */
  627. if ($action == 'edit') {
  628. $object = new AdherentType($db);
  629. $object->fetch($rowid);
  630. $object->fetch_optionals();
  631. $head = member_type_prepare_head($object);
  632. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'">';
  633. print '<input type="hidden" name="token" value="'.newToken().'">';
  634. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  635. print '<input type="hidden" name="action" value="update">';
  636. print dol_get_fiche_head($head, 'card', $langs->trans("MemberType"), 0, 'group');
  637. print '<table class="border centpercent">';
  638. print '<tr><td class="titlefield">'.$langs->trans("Ref").'</td><td>'.$object->id.'</td></tr>';
  639. 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>';
  640. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  641. print $form->selectarray('status', array('0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $object->status);
  642. print '</td></tr>';
  643. // Morphy
  644. $morphys[""] = $langs->trans("MorAndPhy");
  645. $morphys["phy"] = $langs->trans("Physical");
  646. $morphys["mor"] = $langs->trans("Moral");
  647. print '<tr><td><span>'.$langs->trans("MembersNature").'</span></td><td>';
  648. print $form->selectarray("morphy", $morphys, GETPOSTISSET("morphy") ? GETPOST("morphy", 'aZ09') : $object->morphy);
  649. print "</td></tr>";
  650. print '<tr><td>'.$langs->trans("SubscriptionRequired").'</td><td>';
  651. print $form->selectyesno("subscription", $object->subscription, 1);
  652. print '</td></tr>';
  653. print '<tr><td>'.$langs->trans("Amount").'</td><td>';
  654. print '<input name="amount" size="5" value="';
  655. print ((is_null($object->amount) || $object->amount === '') ? '' : price($object->amount));
  656. print '">';
  657. print '</td></tr>';
  658. print '<tr><td>'.$langs->trans("VoteAllowed").'</td><td>';
  659. print $form->selectyesno("vote", $object->vote, 1);
  660. print '</td></tr>';
  661. print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="3">';
  662. print '<input name="duration_value" size="5" value="'.$object->duration_value.'"> ';
  663. print $formproduct->selectMeasuringUnits("duration_unit", "time", ($object->duration_unit === '' ? 'y' : $object->duration_unit), 0, 1);
  664. print '</td></tr>';
  665. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td><td>';
  666. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  667. $doleditor = new DolEditor('comment', $object->note, '', 280, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
  668. $doleditor->Create();
  669. print "</td></tr>";
  670. print '<tr><td class="tdtop">'.$langs->trans("WelcomeEMail").'</td><td>';
  671. $doleditor = new DolEditor('mail_valid', $object->mail_valid, '', 280, 'dolibarr_notes', '', false, true, empty($conf->fckeditor->enabled) ? false : $conf->fckeditor->enabled, 15, '90%');
  672. $doleditor->Create();
  673. print "</td></tr>";
  674. // Other attributes
  675. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php';
  676. print '</table>';
  677. print dol_get_fiche_end();
  678. print $form->buttonsSaveCancel();
  679. print "</form>";
  680. }
  681. }
  682. // End of page
  683. llxFooter();
  684. $db->close();