subscription.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2012-2017 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2015-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  7. * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/adherents/subscription.php
  25. * \ingroup member
  26. * \brief tab for Adding, editing, deleting a member's memberships
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.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.'/adherents/class/subscription.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  38. $langs->loadLangs(array("companies", "bills", "members", "users", "mails", 'other'));
  39. $action = GETPOST('action', 'alpha');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $rowid = GETPOST('rowid', 'int') ?GETPOST('rowid', 'int') : GETPOST('id', 'int');
  42. $typeid = GETPOST('typeid', 'int');
  43. // Load variable for pagination
  44. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  45. $sortfield = GETPOST('sortfield', 'alpha');
  46. $sortorder = GETPOST('sortorder', 'alpha');
  47. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  48. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. // Default sort order (if not yet defined by previous GETPOST)
  53. if (!$sortfield) $sortfield = "c.rowid";
  54. if (!$sortorder) $sortorder = "DESC";
  55. // Security check
  56. $result = restrictedArea($user, 'adherent', $rowid, '', 'cotisation');
  57. $object = new Adherent($db);
  58. $extrafields = new ExtraFields($db);
  59. $adht = new AdherentType($db);
  60. // fetch optionals attributes and labels
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. $errmsg = '';
  63. $defaultdelay = 1;
  64. $defaultdelayunit = 'y';
  65. if ($rowid)
  66. {
  67. // Load member
  68. $result = $object->fetch($rowid);
  69. // Define variables to know what current user can do on users
  70. $canadduser = ($user->admin || $user->rights->user->user->creer);
  71. // Define variables to know what current user can do on properties of user linked to edited member
  72. if ($object->user_id)
  73. {
  74. // $user is the user editing, $object->user_id is the user's id linked to the edited member
  75. $caneditfielduser = ((($user->id == $object->user_id) && $user->rights->user->self->creer)
  76. || (($user->id != $object->user_id) && $user->rights->user->user->creer));
  77. $caneditpassworduser = ((($user->id == $object->user_id) && $user->rights->user->self->password)
  78. || (($user->id != $object->user_id) && $user->rights->user->user->password));
  79. }
  80. }
  81. // Define variables to know what current user can do on members
  82. $canaddmember = $user->rights->adherent->creer;
  83. // Define variables to know what current user can do on properties of a member
  84. if ($rowid)
  85. {
  86. $caneditfieldmember = $user->rights->adherent->creer;
  87. }
  88. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  89. $hookmanager->initHooks(array('subscription'));
  90. // PDF
  91. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  92. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  93. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  94. /*
  95. * Actions
  96. */
  97. // Create third party from a member
  98. if ($action == 'confirm_create_thirdparty' && $confirm == 'yes' && $user->rights->societe->creer)
  99. {
  100. if ($result > 0)
  101. {
  102. // Creation of thirdparty
  103. $company = new Societe($db);
  104. $result = $company->create_from_member($object, GETPOST('companyname', 'alpha'), GETPOST('companyalias', 'alpha'), GETPOST('customercode', 'alpha'));
  105. if ($result < 0)
  106. {
  107. $langs->load("errors");
  108. setEventMessages($company->error, $company->errors, 'errors');
  109. }
  110. else
  111. {
  112. $action = 'addsubscription';
  113. }
  114. }
  115. else
  116. {
  117. setEventMessages($object->error, $object->errors, 'errors');
  118. }
  119. }
  120. if ($action == 'setuserid' && ($user->rights->user->self->creer || $user->rights->user->user->creer))
  121. {
  122. $error = 0;
  123. if (empty($user->rights->user->user->creer)) // If can edit only itself user, we can link to itself only
  124. {
  125. if ($_POST["userid"] != $user->id && $_POST["userid"] != $object->user_id)
  126. {
  127. $error++;
  128. setEventMessages($langs->trans("ErrorUserPermissionAllowsToLinksToItselfOnly"), null, 'errors');
  129. }
  130. }
  131. if (!$error)
  132. {
  133. if ($_POST["userid"] != $object->user_id) // If link differs from currently in database
  134. {
  135. $result = $object->setUserId($_POST["userid"]);
  136. if ($result < 0) dol_print_error('', $object->error);
  137. $_POST['action'] = '';
  138. $action = '';
  139. }
  140. }
  141. }
  142. if ($action == 'setsocid')
  143. {
  144. $error = 0;
  145. if (!$error)
  146. {
  147. if (GETPOST('socid', 'int') != $object->fk_soc) // If link differs from currently in database
  148. {
  149. $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."adherent";
  150. $sql .= " WHERE fk_soc = '".GETPOST('socid', 'int')."'";
  151. $resql = $db->query($sql);
  152. if ($resql)
  153. {
  154. $obj = $db->fetch_object($resql);
  155. if ($obj && $obj->rowid > 0)
  156. {
  157. $othermember = new Adherent($db);
  158. $othermember->fetch($obj->rowid);
  159. $thirdparty = new Societe($db);
  160. $thirdparty->fetch(GETPOST('socid', 'int'));
  161. $error++;
  162. setEventMessages($langs->trans("ErrorMemberIsAlreadyLinkedToThisThirdParty", $othermember->getFullName($langs), $othermember->login, $thirdparty->name), null, 'errors');
  163. }
  164. }
  165. if (!$error)
  166. {
  167. $result = $object->setThirdPartyId(GETPOST('socid', 'int'));
  168. if ($result < 0) dol_print_error('', $object->error);
  169. $_POST['action'] = '';
  170. $action = '';
  171. }
  172. }
  173. }
  174. }
  175. if ($user->rights->adherent->cotisation->creer && $action == 'subscription' && !$_POST["cancel"])
  176. {
  177. $error = 0;
  178. $langs->load("banks");
  179. $result = $object->fetch($rowid);
  180. $result = $adht->fetch($object->typeid);
  181. // Subscription informations
  182. $datesubscription = 0;
  183. $datesubend = 0;
  184. $paymentdate = 0;
  185. if ($_POST["reyear"] && $_POST["remonth"] && $_POST["reday"])
  186. {
  187. $datesubscription = dol_mktime(0, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
  188. }
  189. if ($_POST["endyear"] && $_POST["endmonth"] && $_POST["endday"])
  190. {
  191. $datesubend = dol_mktime(0, 0, 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
  192. }
  193. if ($_POST["paymentyear"] && $_POST["paymentmonth"] && $_POST["paymentday"])
  194. {
  195. $paymentdate = dol_mktime(0, 0, 0, $_POST["paymentmonth"], $_POST["paymentday"], $_POST["paymentyear"]);
  196. }
  197. $amount = price2num(GETPOST("subscription", 'alpha')); // Amount of subscription
  198. $label = $_POST["label"];
  199. // Payment informations
  200. $accountid = $_POST["accountid"];
  201. $operation = $_POST["operation"]; // Payment mode
  202. $num_chq = GETPOST("num_chq", "alphanohtml");
  203. $emetteur_nom = $_POST["chqemetteur"];
  204. $emetteur_banque = $_POST["chqbank"];
  205. $option = $_POST["paymentsave"];
  206. if (empty($option)) $option = 'none';
  207. $sendalsoemail = GETPOST("sendmail", 'alpha');
  208. // Check parameters
  209. if (!$datesubscription)
  210. {
  211. $error++;
  212. $langs->load("errors");
  213. $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateSubscription"));
  214. setEventMessages($errmsg, null, 'errors');
  215. $action = 'addsubscription';
  216. }
  217. if (GETPOST('end') && !$datesubend)
  218. {
  219. $error++;
  220. $langs->load("errors");
  221. $errmsg = $langs->trans("ErrorBadDateFormat", $langs->transnoentitiesnoconv("DateEndSubscription"));
  222. setEventMessages($errmsg, null, 'errors');
  223. $action = 'addsubscription';
  224. }
  225. if (!$datesubend)
  226. {
  227. $datesubend = dol_time_plus_duree(dol_time_plus_duree($datesubscription, $defaultdelay, $defaultdelayunit), -1, 'd');
  228. }
  229. if (($option == 'bankviainvoice' || $option == 'bankdirect') && !$paymentdate)
  230. {
  231. $error++;
  232. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment"));
  233. setEventMessages($errmsg, null, 'errors');
  234. $action = 'addsubscription';
  235. }
  236. // Check if a payment is mandatory or not
  237. if (!$error && $adht->subscription) // Member type need subscriptions
  238. {
  239. if (!is_numeric($amount))
  240. {
  241. // If field is '' or not a numeric value
  242. $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount"));
  243. setEventMessages($errmsg, null, 'errors');
  244. $error++;
  245. $action = 'addsubscription';
  246. }
  247. else
  248. {
  249. if (!empty($conf->banque->enabled) && $_POST["paymentsave"] != 'none')
  250. {
  251. if ($_POST["subscription"])
  252. {
  253. if (!$_POST["label"]) $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label"));
  254. if ($_POST["paymentsave"] != 'invoiceonly' && !$_POST["operation"]) $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("PaymentMode"));
  255. if ($_POST["paymentsave"] != 'invoiceonly' && !($_POST["accountid"] > 0)) $errmsg = $langs->trans("ErrorFieldRequired", $langs->transnoentities("FinancialAccount"));
  256. }
  257. else
  258. {
  259. if ($_POST["accountid"]) $errmsg = $langs->trans("ErrorDoNotProvideAccountsIfNullAmount");
  260. }
  261. if ($errmsg)
  262. {
  263. $error++;
  264. setEventMessages($errmsg, null, 'errors');
  265. $error++;
  266. $action = 'addsubscription';
  267. }
  268. }
  269. }
  270. }
  271. // Record the subscription then complementary actions
  272. if (!$error && $action == 'subscription')
  273. {
  274. $db->begin();
  275. // Create subscription
  276. $crowid = $object->subscription($datesubscription, $amount, $accountid, $operation, $label, $num_chq, $emetteur_nom, $emetteur_banque, $datesubend);
  277. if ($crowid <= 0)
  278. {
  279. $error++;
  280. $errmsg = $object->error;
  281. setEventMessages($object->error, $object->errors, 'errors');
  282. }
  283. if (!$error)
  284. {
  285. $result = $object->subscriptionComplementaryActions($crowid, $option, $accountid, $datesubscription, $paymentdate, $operation, $label, $amount, $num_chq, $emetteur_nom, $emetteur_banque);
  286. if ($result < 0)
  287. {
  288. $error++;
  289. setEventMessages($object->error, $object->errors, 'errors');
  290. }
  291. else
  292. {
  293. // If an invoice was created, it is into $object->invoice
  294. }
  295. }
  296. if (!$error)
  297. {
  298. $db->commit();
  299. }
  300. else
  301. {
  302. $db->rollback();
  303. $action = 'addsubscription';
  304. }
  305. if (!$error)
  306. {
  307. setEventMessages("SubscriptionRecorded", null, 'mesgs');
  308. }
  309. // Send email
  310. if (!$error)
  311. {
  312. // Send confirmation Email
  313. if ($object->email && $sendalsoemail) // $object is 'Adherent'
  314. {
  315. $subject = '';
  316. $msg = '';
  317. // Send subscription email
  318. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  319. $formmail = new FormMail($db);
  320. // Set output language
  321. $outputlangs = new Translate('', $conf);
  322. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  323. // Load traductions files required by page
  324. $outputlangs->loadLangs(array("main", "members"));
  325. // Get email content from template
  326. $arraydefaultmessage = null;
  327. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  328. if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  329. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
  330. {
  331. $subject = $arraydefaultmessage->topic;
  332. $msg = $arraydefaultmessage->content;
  333. }
  334. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  335. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  336. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  337. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  338. // Attach a file ?
  339. $file = '';
  340. $listofpaths = array();
  341. $listofnames = array();
  342. $listofmimes = array();
  343. if (is_object($object->invoice))
  344. {
  345. $invoicediroutput = $conf->facture->dir_output;
  346. $fileparams = dol_most_recent_file($invoicediroutput.'/'.$object->invoice->ref, preg_quote($object->invoice->ref, '/').'[^\-]+');
  347. $file = $fileparams['fullname'];
  348. $listofpaths = array($file);
  349. $listofnames = array(basename($file));
  350. $listofmimes = array(dol_mimetype($file));
  351. }
  352. $moreinheader = 'X-Dolibarr-Info: send_an_email by adherents/subscription.php'."\r\n";
  353. $result = $object->send_an_email($texttosend, $subjecttosend, $listofpaths, $listofmimes, $listofnames, "", "", 0, -1, '', $moreinheader);
  354. if ($result < 0)
  355. {
  356. $errmsg = $object->error;
  357. setEventMessages($object->error, $object->errors, 'errors');
  358. }
  359. else
  360. {
  361. setEventMessages($langs->trans("EmailSentToMember", $object->email), null, 'mesgs');
  362. }
  363. }
  364. else
  365. {
  366. setEventMessages($langs->trans("NoEmailSentToMember"), null, 'mesgs');
  367. }
  368. }
  369. // Clean some POST vars
  370. if (!$error)
  371. {
  372. $_POST["subscription"] = '';
  373. $_POST["accountid"] = '';
  374. $_POST["operation"] = '';
  375. $_POST["label"] = '';
  376. $_POST["num_chq"] = '';
  377. }
  378. }
  379. }
  380. /*
  381. * View
  382. */
  383. $form = new Form($db);
  384. $now = dol_now();
  385. $title = $langs->trans("Member")." - ".$langs->trans("Subscriptions");
  386. $helpurl = "EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros";
  387. llxHeader("", $title, $helpurl);
  388. $param = '';
  389. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
  390. if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
  391. $param .= '&id='.$rowid;
  392. if ($optioncss != '') $param .= '&optioncss='.urlencode($optioncss);
  393. // Add $param from extra fields
  394. //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  395. if ($rowid > 0)
  396. {
  397. $res = $object->fetch($rowid);
  398. if ($res < 0) { dol_print_error($db, $object->error); exit; }
  399. $adht->fetch($object->typeid);
  400. $head = member_prepare_head($object);
  401. $rowspan = 10;
  402. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED)) $rowspan++;
  403. if (!empty($conf->societe->enabled)) $rowspan++;
  404. print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
  405. print '<input type="hidden" name="token" value="'.newToken().'">';
  406. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  407. dol_fiche_head($head, 'subscription', $langs->trans("Member"), -1, 'user');
  408. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  409. dol_banner_tab($object, 'rowid', $linkback);
  410. print '<div class="fichecenter">';
  411. print '<div class="fichehalfleft">';
  412. print '<div class="underbanner clearboth"></div>';
  413. print '<table class="border centpercent tableforfield">';
  414. // Login
  415. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  416. {
  417. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  418. }
  419. // Type
  420. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  421. // Morphy
  422. print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  423. print '</tr>';
  424. // Company
  425. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->company.'</td></tr>';
  426. // Civility
  427. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$object->getCivilityLabel().'&nbsp;</td>';
  428. print '</tr>';
  429. // Password
  430. if (empty($conf->global->ADHERENT_LOGIN_NOT_REQUIRED))
  431. {
  432. print '<tr><td>'.$langs->trans("Password").'</td><td>'.preg_replace('/./i', '*', $object->pass);
  433. if ((!empty($object->pass) || !empty($object->pass_crypted)) && empty($object->user_id))
  434. {
  435. $langs->load("errors");
  436. $htmltext = $langs->trans("WarningPasswordSetWithNoAccount");
  437. print ' '.$form->textwithpicto('', $htmltext, 1, 'warning');
  438. }
  439. print '</td></tr>';
  440. }
  441. print '</table>';
  442. print '</div>';
  443. print '<div class="fichehalfright"><div class="ficheaddleft">';
  444. print '<div class="underbanner clearboth"></div>';
  445. print '<table class="border tableforfield" width="100%">';
  446. // Birthday
  447. print '<tr><td class="titlefield">'.$langs->trans("Birthday").'</td><td class="valeur">'.dol_print_date($object->birth, 'day').'</td></tr>';
  448. // Public
  449. print '<tr><td>'.$langs->trans("Public").'</td><td class="valeur">'.yn($object->public).'</td></tr>';
  450. // Categories
  451. if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
  452. {
  453. print '<tr><td>'.$langs->trans("Categories").'</td>';
  454. print '<td colspan="2">';
  455. print $form->showCategories($object->id, Categorie::TYPE_MEMBER, 1);
  456. print '</td></tr>';
  457. }
  458. // Other attributes
  459. $cols = 2;
  460. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  461. // Date end subscription
  462. print '<tr><td>'.$langs->trans("SubscriptionEndDate").'</td><td class="valeur">';
  463. if ($object->datefin)
  464. {
  465. print dol_print_date($object->datefin, 'day');
  466. if ($object->hasDelay()) {
  467. print " ".img_warning($langs->trans("Late"));
  468. }
  469. }
  470. else
  471. {
  472. if (!$adht->subscription)
  473. {
  474. print $langs->trans("SubscriptionNotRecorded");
  475. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  476. }
  477. else
  478. {
  479. print $langs->trans("SubscriptionNotReceived");
  480. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Display a delay picto only if it is not a draft and is not canceled
  481. }
  482. }
  483. print '</td></tr>';
  484. // Third party Dolibarr
  485. if (!empty($conf->societe->enabled))
  486. {
  487. print '<tr><td>';
  488. print '<table class="nobordernopadding" width="100%"><tr><td>';
  489. print $langs->trans("LinkedToDolibarrThirdParty");
  490. print '</td>';
  491. if ($action != 'editthirdparty' && $user->rights->adherent->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editthirdparty&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToThirdParty'), 1).'</a></td>';
  492. print '</tr></table>';
  493. print '</td><td colspan="2" class="valeur">';
  494. if ($action == 'editthirdparty')
  495. {
  496. $htmlname = 'socid';
  497. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'" name="form'.$htmlname.'">';
  498. print '<input type="hidden" name="rowid" value="'.$object->id.'">';
  499. print '<input type="hidden" name="action" value="set'.$htmlname.'">';
  500. print '<input type="hidden" name="token" value="'.newToken().'">';
  501. print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
  502. print '<tr><td>';
  503. print $form->select_company($object->fk_soc, 'socid', '', 1);
  504. print '</td>';
  505. print '<td class="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  506. print '</tr></table></form>';
  507. }
  508. else
  509. {
  510. if ($object->fk_soc)
  511. {
  512. $company = new Societe($db);
  513. $result = $company->fetch($object->fk_soc);
  514. print $company->getNomUrl(1);
  515. }
  516. else
  517. {
  518. print $langs->trans("NoThirdPartyAssociatedToMember");
  519. }
  520. }
  521. print '</td></tr>';
  522. }
  523. // Login Dolibarr
  524. print '<tr><td>';
  525. print '<table class="nobordernopadding" width="100%"><tr><td>';
  526. print $langs->trans("LinkedToDolibarrUser");
  527. print '</td>';
  528. if ($action != 'editlogin' && $user->rights->adherent->creer)
  529. {
  530. print '<td class="right">';
  531. if ($user->rights->user->user->creer)
  532. {
  533. print '<a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editlogin&amp;rowid='.$object->id.'">'.img_edit($langs->trans('SetLinkToUser'), 1).'</a>';
  534. }
  535. print '</td>';
  536. }
  537. print '</tr></table>';
  538. print '</td><td colspan="2" class="valeur">';
  539. if ($action == 'editlogin')
  540. {
  541. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'userid', '');
  542. }
  543. else
  544. {
  545. if ($object->user_id)
  546. {
  547. $form->form_users($_SERVER['PHP_SELF'].'?rowid='.$object->id, $object->user_id, 'none');
  548. }
  549. else print $langs->trans("NoDolibarrAccess");
  550. }
  551. print '</td></tr>';
  552. print "</table>\n";
  553. print "</div></div></div>\n";
  554. print '<div style="clear:both"></div>';
  555. dol_fiche_end();
  556. print '</form>';
  557. /*
  558. * Action buttons
  559. */
  560. // Button to create a new subscription if member no draft neither resiliated
  561. if ($user->rights->adherent->cotisation->creer)
  562. {
  563. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  564. {
  565. print '<div class="tabsAction">';
  566. if ($object->statut > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?rowid='.$rowid.'&action=addsubscription">'.$langs->trans("AddSubscription")."</a></div>";
  567. else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("ValidateBefore")).'">'.$langs->trans("AddSubscription").'</a></div>';
  568. print '</div>';
  569. }
  570. }
  571. /*
  572. * List of subscriptions
  573. */
  574. if ($action != 'addsubscription' && $action != 'create_thirdparty')
  575. {
  576. $sql = "SELECT d.rowid, d.firstname, d.lastname, d.societe, d.fk_adherent_type as type,";
  577. $sql .= " c.rowid as crowid, c.subscription,";
  578. $sql .= " c.datec, c.fk_type as cfk_type,";
  579. $sql .= " c.dateadh as dateh,";
  580. $sql .= " c.datef,";
  581. $sql .= " c.fk_bank,";
  582. $sql .= " b.rowid as bid,";
  583. $sql .= " ba.rowid as baid, ba.label, ba.bank, ba.ref, ba.account_number, ba.fk_accountancy_journal, ba.number, ba.currency_code";
  584. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d, ".MAIN_DB_PREFIX."subscription as c";
  585. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON c.fk_bank = b.rowid";
  586. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
  587. $sql .= " WHERE d.rowid = c.fk_adherent AND d.rowid=".$rowid;
  588. $sql .= $db->order($sortfield, $sortorder);
  589. $result = $db->query($sql);
  590. if ($result)
  591. {
  592. $subscriptionstatic = new Subscription($db);
  593. $num = $db->num_rows($result);
  594. print '<table class="noborder centpercent">'."\n";
  595. print '<tr class="liste_titre">';
  596. print_liste_field_titre('Ref', $_SERVER["PHP_SELF"], 'c.rowid', '', $param, '', $sortfield, $sortorder);
  597. print_liste_field_titre('DateCreation', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  598. print_liste_field_titre('Type', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  599. print_liste_field_titre('DateStart', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  600. print_liste_field_titre('DateEnd', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'center ');
  601. print_liste_field_titre('Amount', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  602. if (!empty($conf->banque->enabled))
  603. {
  604. print_liste_field_titre('Account', $_SERVER["PHP_SELF"], '', '', $param, '', $sortfield, $sortorder, 'right ');
  605. }
  606. print "</tr>\n";
  607. $accountstatic = new Account($db);
  608. $adh = new Adherent($db);
  609. $adht = new AdherentType($db);
  610. $i = 0;
  611. while ($i < $num)
  612. {
  613. $objp = $db->fetch_object($result);
  614. $adh->id = $objp->rowid;
  615. $adh->typeid = $objp->type;
  616. $subscriptionstatic->ref = $objp->crowid;
  617. $subscriptionstatic->id = $objp->crowid;
  618. $typeid = ($objp->cfk_type > 0 ? $objp->cfk_type : $adh->typeid);
  619. if ($typeid > 0)
  620. {
  621. $adht->fetch($typeid);
  622. }
  623. print '<tr class="oddeven">';
  624. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  625. print '<td class="center">'.dol_print_date($db->jdate($objp->datec), 'dayhour')."</td>\n";
  626. print '<td class="center">';
  627. if ($typeid > 0) {
  628. print $adht->getNomUrl(1);
  629. }
  630. print '</td>';
  631. print '<td class="center">'.dol_print_date($db->jdate($objp->dateh), 'day')."</td>\n";
  632. print '<td class="center">'.dol_print_date($db->jdate($objp->datef), 'day')."</td>\n";
  633. print '<td class="right">'.price($objp->subscription).'</td>';
  634. if (!empty($conf->banque->enabled))
  635. {
  636. print '<td class="right">';
  637. if ($objp->bid)
  638. {
  639. $accountstatic->label = $objp->label;
  640. $accountstatic->id = $objp->baid;
  641. $accountstatic->number = $objp->number;
  642. $accountstatic->account_number = $objp->account_number;
  643. $accountstatic->currency_code = $objp->currency_code;
  644. if (!empty($conf->accounting->enabled) && $objp->fk_accountancy_journal > 0)
  645. {
  646. $accountingjournal = new AccountingJournal($db);
  647. $accountingjournal->fetch($objp->fk_accountancy_journal);
  648. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
  649. }
  650. $accountstatic->ref = $objp->ref;
  651. print $accountstatic->getNomUrl(1);
  652. }
  653. else
  654. {
  655. print '&nbsp;';
  656. }
  657. print '</td>';
  658. }
  659. print "</tr>";
  660. $i++;
  661. }
  662. if (empty($num)) {
  663. $colspan = 6;
  664. if (!empty($conf->banque->enabled)) $colspan++;
  665. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  666. }
  667. print "</table>";
  668. }
  669. else
  670. {
  671. dol_print_error($db);
  672. }
  673. }
  674. if (($action != 'addsubscription' && $action != 'create_thirdparty'))
  675. {
  676. // Shon online payment link
  677. $useonlinepayment = (!empty($conf->paypal->enabled) || !empty($conf->stripe->enabled) || !empty($conf->paybox->enabled));
  678. if ($useonlinepayment)
  679. {
  680. print '<br>';
  681. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  682. print showOnlinePaymentUrl('membersubscription', $object->ref);
  683. print '<br>';
  684. }
  685. }
  686. /*
  687. * Add new subscription form
  688. */
  689. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer)
  690. {
  691. print '<br>';
  692. print load_fiche_titre($langs->trans("NewCotisation"));
  693. // Define default choice for complementary actions
  694. $bankdirect = 0; // 1 means option by default is write to bank direct with no invoice
  695. $invoiceonly = 0; // 1 means option by default is invoice only
  696. $bankviainvoice = 0; // 1 means option by default is write to bank via invoice
  697. if (GETPOST('paymentsave'))
  698. {
  699. if (GETPOST('paymentsave') == 'bankdirect') $bankdirect = 1;
  700. if (GETPOST('paymentsave') == 'invoiceonly') $invoiceonly = 1;
  701. if (GETPOST('paymentsave') == 'bankviainvoice') $bankviainvoice = 1;
  702. }
  703. else
  704. {
  705. if (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankviainvoice' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) $bankviainvoice = 1;
  706. elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && !empty($conf->banque->enabled)) $bankdirect = 1;
  707. elseif (!empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'invoiceonly' && !empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled)) $invoiceonly = 1;
  708. }
  709. print "\n\n<!-- Form add subscription -->\n";
  710. if ($conf->use_javascript_ajax)
  711. {
  712. //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
  713. print "\n".'<script type="text/javascript" language="javascript">';
  714. print '$(document).ready(function () {
  715. $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect || $bankviainvoice) ? 'show()' : 'hide()').';
  716. $("#none, #invoiceonly").click(function() {
  717. $(".bankswitchclass").hide();
  718. $(".bankswitchclass2").hide();
  719. });
  720. $("#bankdirect, #bankviainvoice").click(function() {
  721. $(".bankswitchclass").show();
  722. $(".bankswitchclass2").show();
  723. });
  724. $("#selectoperation").change(function() {
  725. var code = $(this).val();
  726. if (code == "CHQ")
  727. {
  728. $(".fieldrequireddyn").addClass("fieldrequired");
  729. if ($("#fieldchqemetteur").val() == "")
  730. {
  731. $("#fieldchqemetteur").val($("#memberlabel").val());
  732. }
  733. }
  734. else
  735. {
  736. $(".fieldrequireddyn").removeClass("fieldrequired");
  737. }
  738. });
  739. ';
  740. if (GETPOST('paymentsave')) print '$("#'.GETPOST('paymentsave').'").prop("checked",true);';
  741. print '});';
  742. print '</script>'."\n";
  743. }
  744. // Confirm create third party
  745. if ($action == 'create_thirdparty')
  746. {
  747. $companyalias = '';
  748. $fullname = $object->getFullName($langs);
  749. if ($object->morphy == 'mor')
  750. {
  751. $companyname = $object->company;
  752. if (!empty($fullname)) $companyalias = $fullname;
  753. }
  754. else
  755. {
  756. $companyname = $fullname;
  757. if (!empty($object->company)) $companyalias = $object->company;
  758. }
  759. // Create a form array
  760. $formquestion = array(
  761. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
  762. array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
  763. );
  764. // If customer code was forced to "required", we ask it at creation to avoid error later
  765. if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
  766. {
  767. $tmpcompany = new Societe($db);
  768. $tmpcompany->name = $companyname;
  769. $tmpcompany->get_codeclient($tmpcompany, 0);
  770. $customercode = $tmpcompany->code_client;
  771. $formquestion[] = array(
  772. 'label' => $langs->trans("CustomerCode"),
  773. 'type' => 'text',
  774. 'name' => 'customercode',
  775. 'value' => $customercode,
  776. 'morecss' => 'minwidth300',
  777. 'moreattr' => 'maxlength="128"',
  778. );
  779. }
  780. // @todo Add other extrafields mandatory for thirdparty creation
  781. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id, $langs->trans("CreateDolibarrThirdParty"), $langs->trans("ConfirmCreateThirdParty"), "confirm_create_thirdparty", $formquestion, 1);
  782. }
  783. print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  784. print '<input type="hidden" name="token" value="'.newToken().'">';
  785. print '<input type="hidden" name="action" value="subscription">';
  786. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  787. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
  788. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->company).'">';
  789. dol_fiche_head('');
  790. print "<table class=\"border\" width=\"100%\">\n";
  791. print '<tbody>';
  792. $today = dol_now();
  793. $datefrom = 0;
  794. $dateto = 0;
  795. $paymentdate = -1;
  796. // Date payment
  797. if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday'))
  798. {
  799. $paymentdate = dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
  800. }
  801. print '<tr>';
  802. // Date start subscription
  803. print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  804. if (GETPOST('reday'))
  805. {
  806. $datefrom = dol_mktime(0, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  807. }
  808. if (!$datefrom)
  809. {
  810. $datefrom = $object->datevalid;
  811. if ($object->datefin > 0)
  812. {
  813. $datefrom = dol_time_plus_duree($object->datefin, 1, 'd');
  814. }
  815. }
  816. print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
  817. print "</td></tr>";
  818. // Date end subscription
  819. if (GETPOST('endday'))
  820. {
  821. $dateto = dol_mktime(0, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
  822. }
  823. if (!$dateto)
  824. {
  825. $dateto = -1; // By default, no date is suggested
  826. }
  827. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  828. print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
  829. print "</td></tr>";
  830. if ($adht->subscription)
  831. {
  832. // Amount
  833. print '<tr><td class="fieldrequired">'.$langs->trans("Amount").'</td><td><input type="text" name="subscription" size="6" value="'.GETPOST('subscription').'"> '.$langs->trans("Currency".$conf->currency).'</td></tr>';
  834. // Label
  835. print '<tr><td>'.$langs->trans("Label").'</td>';
  836. print '<td><input name="label" type="text" size="32" value="';
  837. if (empty($conf->global->MEMBER_NO_DEFAULT_LABEL)) print $langs->trans("Subscription").' '.dol_print_date(($datefrom ? $datefrom : time()), "%Y");
  838. print '"></td></tr>';
  839. // Complementary action
  840. if (!empty($conf->banque->enabled) || !empty($conf->facture->enabled))
  841. {
  842. $company = new Societe($db);
  843. if ($object->fk_soc)
  844. {
  845. $result = $company->fetch($object->fk_soc);
  846. }
  847. // Title payments
  848. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  849. // No more action
  850. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
  851. print '</td>';
  852. print '<td>';
  853. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice) ? ' checked' : '').'> '.$langs->trans("None").'<br>';
  854. // Add entry into bank accoun
  855. if (!empty($conf->banque->enabled))
  856. {
  857. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(!empty($bankdirect) ? ' checked' : '');
  858. print '> '.$langs->trans("MoreActionBankDirect").'<br>';
  859. }
  860. // Add invoice with no payments
  861. if (!empty($conf->societe->enabled) && !empty($conf->facture->enabled))
  862. {
  863. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(!empty($invoiceonly) ? ' checked' : '');
  864. //if (empty($object->fk_soc)) print ' disabled';
  865. print '> '.$langs->trans("MoreActionInvoiceOnly");
  866. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  867. else
  868. {
  869. print ' (';
  870. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  871. print $langs->trans("NoThirdPartyAssociatedToMember");
  872. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  873. print $langs->trans("CreateDolibarrThirdParty");
  874. print '</a>)';
  875. }
  876. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
  877. if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled)))
  878. {
  879. $prodtmp = new Product($db);
  880. $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  881. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  882. }
  883. print '<br>';
  884. }
  885. // Add invoice with payments
  886. if (!empty($conf->banque->enabled) && !empty($conf->societe->enabled) && !empty($conf->facture->enabled))
  887. {
  888. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(!empty($bankviainvoice) ? ' checked' : '');
  889. //if (empty($object->fk_soc)) print ' disabled';
  890. print '> '.$langs->trans("MoreActionBankViaInvoice");
  891. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  892. else
  893. {
  894. print ' (';
  895. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  896. print $langs->trans("NoThirdPartyAssociatedToMember");
  897. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  898. print $langs->trans("CreateDolibarrThirdParty");
  899. print '</a>)';
  900. }
  901. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. <span class="opacitymedium">'.$langs->trans("NoVatOnSubscription", 0).'</span>';
  902. if (!empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (!empty($conf->product->enabled) || !empty($conf->service->enabled)))
  903. {
  904. $prodtmp = new Product($db);
  905. $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  906. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  907. }
  908. print '<br>';
  909. }
  910. print '</td></tr>';
  911. // Bank account
  912. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  913. $form->select_comptes(GETPOST('accountid'), 'accountid', 0, '', 1);
  914. print "</td></tr>\n";
  915. // Payment mode
  916. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  917. $form->select_types_paiements(GETPOST('operation'), 'operation', '', 2);
  918. print "</td></tr>\n";
  919. // Date of payment
  920. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  921. print $form->selectDate(isset($paymentdate) ? $paymentdate : -1, 'payment', 0, 0, 1, 'subscription', 1, 1);
  922. print "</td></tr>\n";
  923. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  924. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  925. print '</td>';
  926. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(!GETPOST('num_chq') ? '' : GETPOST('num_chq')).'"></td></tr>';
  927. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  928. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  929. print '</td>';
  930. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(!GETPOST('chqemetteur') ? '' : GETPOST('chqemetteur')).'"></td></tr>';
  931. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  932. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  933. print '</td>';
  934. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(!GETPOST('chqbank') ? '' : GETPOST('chqbank')).'"></td></tr>';
  935. }
  936. }
  937. print '<tr><td></td><td></td></tr>';
  938. print '<tr><td>'.$langs->trans("SendAcknowledgementByMail").'</td>';
  939. print '<td>';
  940. if (!$object->email)
  941. {
  942. print $langs->trans("NoEMail");
  943. }
  944. else
  945. {
  946. $adht = new AdherentType($db);
  947. $adht->fetch($object->typeid);
  948. // Send subscription email
  949. $subject = '';
  950. $msg = '';
  951. // Send subscription email
  952. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  953. $formmail = new FormMail($db);
  954. // Set output language
  955. $outputlangs = new Translate('', $conf);
  956. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  957. // Load traductions files required by page
  958. $outputlangs->loadLangs(array("main", "members"));
  959. // Get email content from template
  960. $arraydefaultmessage = null;
  961. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  962. if (!empty($labeltouse)) $arraydefaultmessage = $formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  963. if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
  964. {
  965. $subject = $arraydefaultmessage->topic;
  966. $msg = $arraydefaultmessage->content;
  967. }
  968. $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $object);
  969. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  970. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  971. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  972. $tmp = '<input name="sendmail" type="checkbox"'.(GETPOST('sendmail', 'alpha') ? ' checked' : (!empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL) ? ' checked' : '')).'>';
  973. $helpcontent = '';
  974. $helpcontent .= '<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  975. $helpcontent .= '<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  976. $helpcontent .= '<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
  977. if ($subjecttosend) {
  978. $helpcontent .= $subjecttosend."\n";
  979. } else {
  980. $langs->load("errors");
  981. $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
  982. }
  983. $helpcontent .= "<br>";
  984. $helpcontent .= '<b>'.$langs->trans("MailText").'</b>:<br>';
  985. if ($texttosend) {
  986. $helpcontent .= dol_htmlentitiesbr($texttosend)."\n";
  987. } else {
  988. $langs->load("errors");
  989. $helpcontent .= '<span class="error">'.$langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Module310Name")).'</span>'."\n";
  990. }
  991. print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
  992. }
  993. print '</td></tr>';
  994. print '</tbody>';
  995. print '</table>';
  996. dol_fiche_end();
  997. print '<div class="center">';
  998. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  999. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  1000. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  1001. print '</div>';
  1002. print '</form>';
  1003. print "\n<!-- End form subscription -->\n\n";
  1004. }
  1005. //print '</td></tr>';
  1006. //print '</table>';
  1007. }
  1008. else
  1009. {
  1010. $langs->load("errors");
  1011. print $langs->trans("ErrorRecordNotFound");
  1012. }
  1013. // End of page
  1014. llxFooter();
  1015. $db->close();