subscription.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  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. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/adherents/subscription.php
  24. * \ingroup member
  25. * \brief Onglet d'ajout, edition, suppression des adhesions d'un adherent
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/adherents/class/subscription.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
  37. $langs->loadLangs(array("companies","bills","members","users","mails",'other'));
  38. $action=GETPOST('action','alpha');
  39. $confirm=GETPOST('confirm','alpha');
  40. $rowid=GETPOST('rowid','int')?GETPOST('rowid','int'):GETPOST('id','int');
  41. $typeid=GETPOST('typeid','int');
  42. // Load variable for pagination
  43. $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
  44. $sortfield = GETPOST('sortfield','alpha');
  45. $sortorder = GETPOST('sortorder','alpha');
  46. $page = GETPOST('page','int');
  47. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  48. $offset = $limit * $page;
  49. $pageprev = $page - 1;
  50. $pagenext = $page + 1;
  51. // Default sort order (if not yet defined by previous GETPOST)
  52. if (! $sortfield) $sortfield="c.rowid";
  53. if (! $sortorder) $sortorder="DESC";
  54. // Security check
  55. $result=restrictedArea($user,'adherent',$rowid,'','cotisation');
  56. $object = new Adherent($db);
  57. $extrafields = new ExtraFields($db);
  58. $adht = new AdherentType($db);
  59. // fetch optionals attributes and labels
  60. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  61. $errmsg='';
  62. $errmsgs=array();
  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 est le user qui edite, $object->user_id est l'id de l'utilisateur lies au membre edite
  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=$_POST["num_chq"];
  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 requiredby 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, $listofnames, $listofmimes, "", "", 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="'.$_SESSION['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" width="100%">';
  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("Nature").'</td><td class="valeur" >'.$object->getmorphylib().'</td>';
  423. print '</tr>';
  424. // Company
  425. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$object->societe.'</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, '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")); // Affiche picto retard uniquement si non brouillon et non resilie
  476. }
  477. else
  478. {
  479. print $langs->trans("SubscriptionNotReceived");
  480. if ($object->statut > 0) print " ".img_warning($langs->trans("Late")); // Affiche picto retard uniquement si non brouillon et non resilie
  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 align="right"><a 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="'.$_SESSION['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 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,";
  577. $sql.= " c.rowid as crowid, c.subscription,";
  578. $sql.= " c.datec,";
  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";
  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. $i = 0;
  595. print '<table class="noborder" width="100%">'."\n";
  596. print '<tr class="liste_titre">';
  597. print_liste_field_titre('Ref',$_SERVER["PHP_SELF"],'c.rowid','',$param,'',$sortfield,$sortorder);
  598. print '<td align="center">'.$langs->trans("DateCreation").'</td>';
  599. print '<td align="center">'.$langs->trans("DateStart").'</td>';
  600. print '<td align="center">'.$langs->trans("DateEnd").'</td>';
  601. print '<td class="right">'.$langs->trans("Amount").'</td>';
  602. if (! empty($conf->banque->enabled))
  603. {
  604. print '<td class="right">'.$langs->trans("Account").'</td>';
  605. }
  606. print "</tr>\n";
  607. $accountstatic=new Account($db);
  608. while ($i < $num)
  609. {
  610. $objp = $db->fetch_object($result);
  611. $subscriptionstatic->ref=$objp->crowid;
  612. $subscriptionstatic->id=$objp->crowid;
  613. print '<tr class="oddeven">';
  614. print '<td>'.$subscriptionstatic->getNomUrl(1).'</td>';
  615. print '<td align="center">'.dol_print_date($db->jdate($objp->datec),'dayhour')."</td>\n";
  616. print '<td align="center">'.dol_print_date($db->jdate($objp->dateh),'day')."</td>\n";
  617. print '<td align="center">'.dol_print_date($db->jdate($objp->datef),'day')."</td>\n";
  618. print '<td class="right">'.price($objp->subscription).'</td>';
  619. if (! empty($conf->banque->enabled))
  620. {
  621. print '<td class="right">';
  622. if ($objp->bid)
  623. {
  624. $accountstatic->label=$objp->label;
  625. $accountstatic->id=$objp->baid;
  626. $accountstatic->number=$objp->number;
  627. $accountstatic->account_number=$objp->account_number;
  628. if (! empty($conf->accounting->enabled))
  629. {
  630. $accountingjournal = new AccountingJournal($db);
  631. $accountingjournal->fetch($objp->fk_accountancy_journal);
  632. $accountstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1);
  633. }
  634. $accountstatic->ref=$objp->ref;
  635. print $accountstatic->getNomUrl(1);
  636. }
  637. else
  638. {
  639. print '&nbsp;';
  640. }
  641. print '</td>';
  642. }
  643. print "</tr>";
  644. $i++;
  645. }
  646. print "</table>";
  647. }
  648. else
  649. {
  650. dol_print_error($db);
  651. }
  652. }
  653. if (($action != 'addsubscription' && $action != 'create_thirdparty'))
  654. {
  655. // Shon online payment link
  656. $useonlinepayment = (! empty($conf->paypal->enabled) || ! empty($conf->stripe->enabled) || ! empty($conf->paybox->enabled));
  657. if ($useonlinepayment)
  658. {
  659. print '<br>';
  660. require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php';
  661. print showOnlinePaymentUrl('membersubscription', $object->ref);
  662. print '<br>';
  663. }
  664. }
  665. /*
  666. * Add new subscription form
  667. */
  668. if (($action == 'addsubscription' || $action == 'create_thirdparty') && $user->rights->adherent->cotisation->creer)
  669. {
  670. print '<br>';
  671. print load_fiche_titre($langs->trans("NewCotisation"));
  672. // Define default choice for complementary actions
  673. $bankdirect=0; // 1 means option by default is write to bank direct with no invoice
  674. $invoiceonly=0; // 1 means option by default is invoice only
  675. $bankviainvoice=0; // 1 means option by default is write to bank via invoice
  676. if (GETPOST('paymentsave'))
  677. {
  678. if (GETPOST('paymentsave') == 'bankdirect') $bankdirect=1;
  679. if (GETPOST('paymentsave') == 'invoiceonly') $invoiceonly=1;
  680. if (GETPOST('paymentsave') == 'bankviainvoice') $bankviainvoice=1;
  681. }
  682. else
  683. {
  684. 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;
  685. elseif (! empty($conf->global->ADHERENT_BANK_USE) && $conf->global->ADHERENT_BANK_USE == 'bankdirect' && ! empty($conf->banque->enabled)) $bankdirect=1;
  686. 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;
  687. }
  688. print "\n\n<!-- Form add subscription -->\n";
  689. if ($conf->use_javascript_ajax)
  690. {
  691. //var_dump($bankdirect.'-'.$bankviainvoice.'-'.$invoiceonly.'-'.empty($conf->global->ADHERENT_BANK_USE));
  692. print "\n".'<script type="text/javascript" language="javascript">';
  693. print '$(document).ready(function () {
  694. $(".bankswitchclass, .bankswitchclass2").'.(($bankdirect||$bankviainvoice)?'show()':'hide()').';
  695. $("#none, #invoiceonly").click(function() {
  696. $(".bankswitchclass").hide();
  697. $(".bankswitchclass2").hide();
  698. });
  699. $("#bankdirect, #bankviainvoice").click(function() {
  700. $(".bankswitchclass").show();
  701. $(".bankswitchclass2").show();
  702. });
  703. $("#selectoperation").change(function() {
  704. var code = $(this).val();
  705. if (code == "CHQ")
  706. {
  707. $(".fieldrequireddyn").addClass("fieldrequired");
  708. if ($("#fieldchqemetteur").val() == "")
  709. {
  710. $("#fieldchqemetteur").val($("#memberlabel").val());
  711. }
  712. }
  713. else
  714. {
  715. $(".fieldrequireddyn").removeClass("fieldrequired");
  716. }
  717. });
  718. ';
  719. if (GETPOST('paymentsave')) print '$("#'.GETPOST('paymentsave').'").prop("checked",true);';
  720. print '});';
  721. print '</script>'."\n";
  722. }
  723. // Confirm create third party
  724. if ($action == 'create_thirdparty')
  725. {
  726. $companyalias='';
  727. $fullname = $object->getFullName($langs);
  728. if ($object->morphy == 'mor')
  729. {
  730. $companyname=$object->societe;
  731. if (! empty($fullname)) $companyalias=$fullname;
  732. }
  733. else
  734. {
  735. $companyname=$fullname;
  736. if (! empty($object->societe)) $companyalias=$object->societe;
  737. }
  738. // Create a form array
  739. $formquestion=array(
  740. array('label' => $langs->trans("NameToCreate"), 'type' => 'text', 'name' => 'companyname', 'value' => $companyname, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"'),
  741. array('label' => $langs->trans("AliasNames"), 'type' => 'text', 'name' => 'companyalias', 'value' => $companyalias, 'morecss' => 'minwidth300', 'moreattr' => 'maxlength="128"')
  742. );
  743. // If customer code was forced to "required", we ask it at creation to avoid error later
  744. if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))
  745. {
  746. $tmpcompany = new Societe($db);
  747. $tmpcompany->name=$companyname;
  748. $tmpcompany->get_codeclient($tmpcompany, 0);
  749. $customercode = $tmpcompany->code_client;
  750. $formquestion[]=array(
  751. 'label' => $langs->trans("CustomerCode"),
  752. 'type' => 'text',
  753. 'name' => 'customercode',
  754. 'value' => $customercode,
  755. 'morecss' => 'minwidth300',
  756. 'moreattr' => 'maxlength="128"',
  757. );
  758. }
  759. // @TODO Add other extrafields mandatory for thirdparty creation
  760. print $form->formconfirm($_SERVER["PHP_SELF"]."?rowid=".$object->id,$langs->trans("CreateDolibarrThirdParty"),$langs->trans("ConfirmCreateThirdParty"),"confirm_create_thirdparty",$formquestion,1);
  761. }
  762. print '<form name="subscription" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  763. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  764. print '<input type="hidden" name="action" value="subscription">';
  765. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  766. print '<input type="hidden" name="memberlabel" id="memberlabel" value="'.dol_escape_htmltag($object->getFullName($langs)).'">';
  767. print '<input type="hidden" name="thirdpartylabel" id="thirdpartylabel" value="'.dol_escape_htmltag($object->societe).'">';
  768. dol_fiche_head('');
  769. print "<table class=\"border\" width=\"100%\">\n";
  770. print '<tbody>';
  771. $today=dol_now();
  772. $datefrom=0;
  773. $dateto=0;
  774. $paymentdate=-1;
  775. // Date payment
  776. if (GETPOST('paymentyear') && GETPOST('paymentmonth') && GETPOST('paymentday'))
  777. {
  778. $paymentdate=dol_mktime(0, 0, 0, GETPOST('paymentmonth'), GETPOST('paymentday'), GETPOST('paymentyear'));
  779. }
  780. print '<tr>';
  781. // Date start subscription
  782. print '<td class="fieldrequired">'.$langs->trans("DateSubscription").'</td><td>';
  783. if (GETPOST('reday'))
  784. {
  785. $datefrom=dol_mktime(0,0,0,GETPOST('remonth'),GETPOST('reday'),GETPOST('reyear'));
  786. }
  787. if (! $datefrom)
  788. {
  789. $datefrom=$object->datevalid;
  790. if ($object->datefin > 0)
  791. {
  792. $datefrom=dol_time_plus_duree($object->datefin,1,'d');
  793. }
  794. }
  795. print $form->selectDate($datefrom, '', '', '', '', "subscription", 1, 1);
  796. print "</td></tr>";
  797. // Date end subscription
  798. if (GETPOST('endday'))
  799. {
  800. $dateto=dol_mktime(0,0,0,GETPOST('endmonth'),GETPOST('endday'),GETPOST('endyear'));
  801. }
  802. if (! $dateto)
  803. {
  804. $dateto=-1; // By default, no date is suggested
  805. }
  806. print '<tr><td>'.$langs->trans("DateEndSubscription").'</td><td>';
  807. print $form->selectDate($dateto, 'end', '', '', '', "subscription", 1, 0);
  808. print "</td></tr>";
  809. if ($adht->subscription)
  810. {
  811. // Amount
  812. 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>';
  813. // Label
  814. print '<tr><td>'.$langs->trans("Label").'</td>';
  815. print '<td><input name="label" type="text" size="32" value="';
  816. if (empty($conf->global->MEMBER_NO_DEFAULT_LABEL)) print $langs->trans("Subscription").' '.dol_print_date(($datefrom?$datefrom:time()),"%Y");
  817. print '"></td></tr>';
  818. // Complementary action
  819. if (! empty($conf->banque->enabled) || ! empty($conf->facture->enabled))
  820. {
  821. $company=new Societe($db);
  822. if ($object->fk_soc)
  823. {
  824. $result=$company->fetch($object->fk_soc);
  825. }
  826. // Title payments
  827. //print '<tr><td colspan="2"><b>'.$langs->trans("Payment").'</b></td></tr>';
  828. // No more action
  829. print '<tr><td class="tdtop fieldrequired">'.$langs->trans('MoreActions');
  830. print '</td>';
  831. print '<td>';
  832. print '<input type="radio" class="moreaction" id="none" name="paymentsave" value="none"'.(empty($bankdirect) && empty($invoiceonly) && empty($bankviainvoice)?' checked':'').'> '.$langs->trans("None").'<br>';
  833. // Add entry into bank accoun
  834. if (! empty($conf->banque->enabled))
  835. {
  836. print '<input type="radio" class="moreaction" id="bankdirect" name="paymentsave" value="bankdirect"'.(! empty($bankdirect)?' checked':'');
  837. print '> '.$langs->trans("MoreActionBankDirect").'<br>';
  838. }
  839. // Add invoice with no payments
  840. if (! empty($conf->societe->enabled) && ! empty($conf->facture->enabled))
  841. {
  842. print '<input type="radio" class="moreaction" id="invoiceonly" name="paymentsave" value="invoiceonly"'.(! empty($invoiceonly)?' checked':'');
  843. //if (empty($object->fk_soc)) print ' disabled';
  844. print '> '.$langs->trans("MoreActionInvoiceOnly");
  845. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  846. else
  847. {
  848. print ' (';
  849. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  850. print $langs->trans("NoThirdPartyAssociatedToMember");
  851. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  852. print $langs->trans("CreateDolibarrThirdParty");
  853. print '</a>)';
  854. }
  855. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. '.$langs->trans("NoVatOnSubscription",0);
  856. if (! empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (! empty($conf->product->enabled) || ! empty($conf->service->enabled)))
  857. {
  858. $prodtmp=new Product($db);
  859. $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  860. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  861. }
  862. print '<br>';
  863. }
  864. // Add invoice with payments
  865. if (! empty($conf->banque->enabled) && ! empty($conf->societe->enabled) && ! empty($conf->facture->enabled))
  866. {
  867. print '<input type="radio" class="moreaction" id="bankviainvoice" name="paymentsave" value="bankviainvoice"'.(! empty($bankviainvoice)?' checked':'');
  868. //if (empty($object->fk_soc)) print ' disabled';
  869. print '> '.$langs->trans("MoreActionBankViaInvoice");
  870. if ($object->fk_soc) print ' ('.$langs->trans("ThirdParty").': '.$company->getNomUrl(1).')';
  871. else
  872. {
  873. print ' (';
  874. if (empty($object->fk_soc)) print img_warning($langs->trans("NoThirdPartyAssociatedToMember"));
  875. print $langs->trans("NoThirdPartyAssociatedToMember");
  876. print ' - <a href="'.$_SERVER["PHP_SELF"].'?rowid='.$object->id.'&amp;action=create_thirdparty">';
  877. print $langs->trans("CreateDolibarrThirdParty");
  878. print '</a>)';
  879. }
  880. if (empty($conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS) || $conf->global->ADHERENT_VAT_FOR_SUBSCRIPTIONS != 'defaultforfoundationcountry') print '. '.$langs->trans("NoVatOnSubscription",0);
  881. if (! empty($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS) && (! empty($conf->product->enabled) || ! empty($conf->service->enabled)))
  882. {
  883. $prodtmp=new Product($db);
  884. $prodtmp->fetch($conf->global->ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS);
  885. print '. '.$langs->transnoentitiesnoconv("ADHERENT_PRODUCT_ID_FOR_SUBSCRIPTIONS", $prodtmp->getNomUrl(1)); // must use noentitiesnoconv to avoid to encode html into getNomUrl of product
  886. }
  887. print '<br>';
  888. }
  889. print '</td></tr>';
  890. // Bank account
  891. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("FinancialAccount").'</td><td>';
  892. $form->select_comptes(GETPOST('accountid'),'accountid',0,'',1);
  893. print "</td></tr>\n";
  894. // Payment mode
  895. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td>';
  896. $form->select_types_paiements(GETPOST('operation'),'operation','',2);
  897. print "</td></tr>\n";
  898. // Date of payment
  899. print '<tr class="bankswitchclass"><td class="fieldrequired">'.$langs->trans("DatePayment").'</td><td>';
  900. print $form->selectDate(isset($paymentdate)?$paymentdate:-1, 'payment', 0, 0, 1, 'subscription', 1, 1);
  901. print "</td></tr>\n";
  902. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Numero');
  903. print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
  904. print '</td>';
  905. print '<td><input id="fieldnum_chq" name="num_chq" type="text" size="8" value="'.(! GETPOST('num_chq')?'':GETPOST('num_chq')).'"></td></tr>';
  906. print '<tr class="bankswitchclass2 fieldrequireddyn"><td>'.$langs->trans('CheckTransmitter');
  907. print ' <em>('.$langs->trans("ChequeMaker").')</em>';
  908. print '</td>';
  909. print '<td><input id="fieldchqemetteur" name="chqemetteur" size="32" type="text" value="'.(! GETPOST('chqemetteur')?'':GETPOST('chqemetteur')).'"></td></tr>';
  910. print '<tr class="bankswitchclass2"><td>'.$langs->trans('Bank');
  911. print ' <em>('.$langs->trans("ChequeBank").')</em>';
  912. print '</td>';
  913. print '<td><input id="chqbank" name="chqbank" size="32" type="text" value="'.(! GETPOST('chqbank')?'':GETPOST('chqbank')).'"></td></tr>';
  914. }
  915. }
  916. print '<tr><td colspan="2">&nbsp;</td>';
  917. print '<tr><td width="30%">'.$langs->trans("SendAcknowledgementByMail").'</td>';
  918. print '<td>';
  919. if (! $object->email)
  920. {
  921. print $langs->trans("NoEMail");
  922. }
  923. else
  924. {
  925. $adht = new AdherentType($db);
  926. $adht->fetch($object->typeid);
  927. // Send subscription email
  928. $subject = '';
  929. $msg= '';
  930. // Send subscription email
  931. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  932. $formmail=new FormMail($db);
  933. // Set output language
  934. $outputlangs = new Translate('', $conf);
  935. $outputlangs->setDefaultLang(empty($object->thirdparty->default_lang) ? $mysoc->default_lang : $object->thirdparty->default_lang);
  936. // Load traductions files requiredby by page
  937. $outputlangs->loadLangs(array("main", "members"));
  938. // Get email content from template
  939. $arraydefaultmessage=null;
  940. $labeltouse = $conf->global->ADHERENT_EMAIL_TEMPLATE_SUBSCRIPTION;
  941. if (! empty($labeltouse)) $arraydefaultmessage=$formmail->getEMailTemplate($db, 'member', $user, $outputlangs, 0, 1, $labeltouse);
  942. if (! empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0)
  943. {
  944. $subject = $arraydefaultmessage->topic;
  945. $msg = $arraydefaultmessage->content;
  946. }
  947. $substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
  948. complete_substitutions_array($substitutionarray, $outputlangs, $object);
  949. $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
  950. $texttosend = make_substitutions(dol_concatdesc($msg, $adht->getMailOnSubscription()), $substitutionarray, $outputlangs);
  951. $tmp='<input name="sendmail" type="checkbox"'.(GETPOST('sendmail','alpha')?' checked':(! empty($conf->global->ADHERENT_DEFAULT_SENDINFOBYMAIL)?' checked':'')).'>';
  952. $helpcontent='';
  953. $helpcontent.='<b>'.$langs->trans("MailFrom").'</b>: '.$conf->global->ADHERENT_MAIL_FROM.'<br>'."\n";
  954. $helpcontent.='<b>'.$langs->trans("MailRecipient").'</b>: '.$object->email.'<br>'."\n";
  955. $helpcontent.='<b>'.$langs->trans("MailTopic").'</b>:<br>'."\n";
  956. $helpcontent.=$subjecttosend."\n";
  957. $helpcontent.="<br>";
  958. $helpcontent.='<b>'.$langs->trans("MailText").'</b>:<br>';
  959. $helpcontent.=dol_htmlentitiesbr($texttosend)."\n";
  960. print $form->textwithpicto($tmp, $helpcontent, 1, 'help', '', 0, 2, 'helpemailtosend');
  961. }
  962. print '</td></tr>';
  963. print '</tbody>';
  964. print '</table>';
  965. dol_fiche_end();
  966. print '<div class="center">';
  967. print '<input type="submit" class="button" name="add" value="'.$langs->trans("AddSubscription").'">';
  968. print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  969. print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
  970. print '</div>';
  971. print '</form>';
  972. print "\n<!-- End form subscription -->\n\n";
  973. }
  974. //print '</td></tr>';
  975. //print '</table>';
  976. }
  977. else
  978. {
  979. $langs->load("errors");
  980. print $langs->trans("ErrorRecordNotFound");
  981. }
  982. // End of page
  983. llxFooter();
  984. $db->close();