type.php 33 KB

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