type.php 30 KB

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