mails_templates.php 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
  8. * Copyright (C) 2011 Remy Younes <ryounes@gmail.com>
  9. * Copyright (C) 2012-2015 Marcos García <marcosgdf@gmail.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@ltairis.fr>
  11. * Copyright (C) 2011-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
  12. * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  14. * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/admin/mails_templates.php
  31. * \ingroup core
  32. * \brief Page to administer emails templates
  33. */
  34. // Load Dolibarr environment
  35. require '../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  42. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  43. // Load translation files required by the page
  44. $langsArray=array("errors", "admin", "mails", "languages");
  45. if (isModEnabled('adherent')) {
  46. $langsArray[]='members';
  47. }
  48. if (isModEnabled('eventorganization')) {
  49. $langsArray[]='eventorganization';
  50. }
  51. $langs->loadLangs($langsArray);
  52. $toselect = GETPOST('toselect', 'array');
  53. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view';
  54. $massaction = GETPOST('massaction', 'alpha');
  55. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  56. $mode = GETPOST('mode', 'aZ09');
  57. $optioncss = GETPOST('optioncss', 'alpha');
  58. $id = GETPOST('id', 'int');
  59. $rowid = GETPOST('rowid', 'alpha');
  60. $search_label = GETPOST('search_label', 'alphanohtml'); // Must allow value like 'Abc Def' or '(MyTemplateName)'
  61. $search_type_template = GETPOST('search_type_template', 'alpha');
  62. $search_lang = GETPOST('search_lang', 'alpha');
  63. $search_fk_user = GETPOST('search_fk_user', 'intcomma');
  64. $search_topic = GETPOST('search_topic', 'alpha');
  65. $search_module = GETPOST('search_module', 'alpha');
  66. $acts = array();
  67. $actl = array();
  68. $acts[0] = "activate";
  69. $acts[1] = "disable";
  70. $actl[0] = img_picto($langs->trans("Disabled"), 'switch_off', 'class="size15x"');
  71. $actl[1] = img_picto($langs->trans("Activated"), 'switch_on', 'class="size15x"');
  72. $listoffset = GETPOST('listoffset', 'alpha');
  73. $listlimit = GETPOST('listlimit', 'alpha') > 0 ? GETPOST('listlimit', 'alpha') : 1000;
  74. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  75. $sortfield = GETPOST('sortfield', 'aZ09comma');
  76. $sortorder = GETPOST('sortorder', 'aZ09comma');
  77. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  78. if (empty($page) || $page == -1) {
  79. $page = 0;
  80. } // If $page is not defined, or '' or -1
  81. $offset = $listlimit * $page;
  82. $pageprev = $page - 1;
  83. $pagenext = $page + 1;
  84. if (empty($sortfield)) {
  85. $sortfield = 'type_template,lang,position,label';
  86. }
  87. if (empty($sortorder)) {
  88. $sortorder = 'ASC';
  89. }
  90. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  91. $hookmanager->initHooks(array('emailtemplates'));
  92. // Name of SQL tables of dictionaries
  93. $tabname = array();
  94. $tabname[25] = MAIN_DB_PREFIX."c_email_templates";
  95. // Nom des champs en resultat de select pour affichage du dictionnaire
  96. $tabfield = array();
  97. $tabfield[25] = "label,lang,type_template,fk_user,private,position,module,topic,joinfiles,defaultfortype,content";
  98. if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
  99. $tabfield[25] .= ',content_lines';
  100. }
  101. // Nom des champs d'edition pour modification d'un enregistrement
  102. $tabfieldvalue = array();
  103. $tabfieldvalue[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
  104. if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
  105. $tabfieldvalue[25] .= ',content_lines';
  106. }
  107. // Nom des champs dans la table pour insertion d'un enregistrement
  108. $tabfieldinsert = array();
  109. $tabfieldinsert[25] = "label,lang,type_template,fk_user,private,position,topic,email_from,joinfiles,defaultfortype,content";
  110. if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
  111. $tabfieldinsert[25] .= ',content_lines';
  112. }
  113. $tabfieldinsert[25] .= ',entity'; // Must be at end because not into other arrays
  114. // Condition to show dictionary in setup page
  115. $tabcond = array();
  116. $tabcond[25] = true;
  117. // List of help for fields
  118. // Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
  119. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  120. $formmail = new FormMail($db);
  121. if (!getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
  122. $tmp = FormMail::getAvailableSubstitKey('formemail');
  123. $tmp['__(AnyTranslationKey)__'] = 'Translation';
  124. $helpsubstit = $langs->trans("AvailableVariables").':<br>';
  125. $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
  126. foreach ($tmp as $key => $val) {
  127. $helpsubstit .= $key.' -> '.$val.'<br>';
  128. $helpsubstitforlines .= $key.' -> '.$val.'<br>';
  129. }
  130. } else {
  131. $tmp = FormMail::getAvailableSubstitKey('formemailwithlines');
  132. $tmp['__(AnyTranslationKey)__'] = 'Translation';
  133. $helpsubstit = $langs->trans("AvailableVariables").':<br>';
  134. $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
  135. foreach ($tmp as $key => $val) {
  136. $helpsubstit .= $key.' -> '.$val.'<br>';
  137. }
  138. $tmp = FormMail::getAvailableSubstitKey('formemailforlines');
  139. foreach ($tmp as $key => $val) {
  140. $helpsubstitforlines .= $key.' -> '.$val.'<br>';
  141. }
  142. }
  143. $tabhelp = array();
  144. $tabhelp[25] = array(
  145. 'label'=>$langs->trans('EnterAnyCode'),
  146. 'type_template'=>$langs->trans("TemplateForElement"),
  147. 'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"),
  148. 'position'=>$langs->trans("PositionIntoComboList"),
  149. 'topic'=>'<span class="small">'.$helpsubstit.'</span>',
  150. 'email_from'=>$langs->trans('ForceEmailFrom'),
  151. 'joinfiles'=>$langs->trans('AttachMainDocByDefault'),
  152. 'defaultfortype'=>$langs->trans("DefaultForTypeDesc"),
  153. 'content'=>'<span class="small">'.$helpsubstit.'</span>',
  154. 'content_lines'=>'<span class="small">'.$helpsubstitforlines.'</span>'
  155. );
  156. // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
  157. $elementList = array();
  158. // Add all and none after the sort
  159. $elementList['all'] = '-- '.dol_escape_htmltag($langs->trans("All")).' --';
  160. $elementList['none'] = '-- '.dol_escape_htmltag($langs->trans("None")).' --';
  161. $elementList['user'] = img_picto('', 'user', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToUser'));
  162. if (isModEnabled('adherent') && $user->hasRight('adherent', 'lire')) {
  163. $elementList['member'] = img_picto('', 'object_member', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToMember'));
  164. }
  165. if (isModEnabled('recruitment') && $user->hasRight('recruitment', 'recruitmentjobposition', 'read')) {
  166. $elementList['recruitmentcandidature_send'] = img_picto('', 'recruitmentcandidature', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('RecruitmentCandidatures'));
  167. }
  168. if (isModEnabled("societe") && $user->hasRight('societe', 'lire')) {
  169. $elementList['thirdparty'] = img_picto('', 'company', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToThirdparty'));
  170. }
  171. if (isModEnabled('project')) {
  172. $elementList['project'] = img_picto('', 'project', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToProject'));
  173. }
  174. if (isModEnabled("propal") && $user->hasRight('propal', 'lire')) {
  175. $elementList['propal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendProposal'));
  176. }
  177. if (isModEnabled('commande') && $user->hasRight('commande', 'lire')) {
  178. $elementList['order_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendOrder'));
  179. }
  180. if (isModEnabled('facture') && $user->hasRight('facture', 'lire')) {
  181. $elementList['facture_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendInvoice'));
  182. }
  183. if (isModEnabled("expedition")) {
  184. $elementList['shipping_send'] = img_picto('', 'dolly', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendShipment'));
  185. }
  186. if (isModEnabled("reception")) {
  187. $elementList['reception_send'] = img_picto('', 'dollyrevert', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendReception'));
  188. }
  189. if (isModEnabled('ficheinter')) {
  190. $elementList['fichinter_send'] = img_picto('', 'intervention', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendIntervention'));
  191. }
  192. if (isModEnabled('supplier_proposal')) {
  193. $elementList['supplier_proposal_send'] = img_picto('', 'propal', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierRequestForQuotation'));
  194. }
  195. if (isModEnabled("supplier_order") && ($user->hasRight('fournisseur', 'commande', 'lire') || $user->hasRight('supplier_order', 'read'))) {
  196. $elementList['order_supplier_send'] = img_picto('', 'order', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierOrder'));
  197. }
  198. if (isModEnabled("supplier_invoice") && ($user->hasRight('fournisseur', 'facture', 'lire') || $user->hasRight('supplier_invoice', 'read'))) {
  199. $elementList['invoice_supplier_send'] = img_picto('', 'bill', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendSupplierInvoice'));
  200. }
  201. if (isModEnabled('contrat') && $user->hasRight('contrat', 'lire')) {
  202. $elementList['contract'] = img_picto('', 'contract', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendContract'));
  203. }
  204. if (isModEnabled('ticket') && $user->hasRight('ticket', 'read')) {
  205. $elementList['ticket_send'] = img_picto('', 'ticket', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToTicket'));
  206. }
  207. if (isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire')) {
  208. $elementList['expensereport_send'] = img_picto('', 'trip', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToExpenseReport'));
  209. }
  210. if (isModEnabled('agenda')) {
  211. $elementList['actioncomm_send'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventPush'));
  212. }
  213. if (isModEnabled('eventorganization') && $user->hasRight('eventorganization', 'read')) {
  214. $elementList['conferenceorbooth'] = img_picto('', 'action', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToSendEventOrganization'));
  215. }
  216. if (isModEnabled('partnership') && $user->hasRight('partnership', 'read')) {
  217. $elementList['partnership_send'] = img_picto('', 'partnership', 'class="pictofixedwidth"').dol_escape_htmltag($langs->trans('MailToPartnership'));
  218. }
  219. $parameters = array('elementList'=>$elementList);
  220. $reshook = $hookmanager->executeHooks('emailElementlist', $parameters); // Note that $action and $object may have been modified by some hooks
  221. if ($reshook == 0) {
  222. foreach ($hookmanager->resArray as $item => $value) {
  223. $elementList[$item] = $value;
  224. }
  225. }
  226. $id = 25;
  227. $acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
  228. // Security
  229. if (!empty($user->socid)) {
  230. accessforbidden();
  231. }
  232. $permissiontoadd = 1;
  233. $permissiontodelete = 1;
  234. /*
  235. * Actions
  236. */
  237. if (GETPOST('cancel', 'alpha')) {
  238. $action = 'list';
  239. $massaction = '';
  240. }
  241. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  242. $massaction = '';
  243. }
  244. $parameters = array();
  245. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  246. if ($reshook < 0) {
  247. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  248. }
  249. if (empty($reshook)) {
  250. // Selection of new fields
  251. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  252. // Purge search criteria
  253. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  254. // All tests are required to be compatible with all browsers
  255. $search_label = '';
  256. $search_type_template = '';
  257. $search_lang = '';
  258. $search_fk_user = '';
  259. $search_topic = '';
  260. $search_module = '';
  261. $toselect = array();
  262. $search_array_options = array();
  263. }
  264. // Actions add or modify an email template
  265. if ((GETPOST('actionadd', 'alpha') || GETPOST('actionmodify', 'alpha')) && $permissiontoadd) {
  266. $listfield = explode(',', str_replace(' ', '', $tabfield[$id]));
  267. $listfieldinsert = explode(',', $tabfieldinsert[$id]);
  268. $listfieldmodify = explode(',', $tabfieldinsert[$id]);
  269. $listfieldvalue = explode(',', $tabfieldvalue[$id]);
  270. // Check that all fields are filled
  271. $ok = 1;
  272. foreach ($listfield as $f => $value) {
  273. // Not mandatory fields
  274. if (in_array($value, ['joinfiles', 'defaultfortype', 'content', 'content_lines', 'module'])) {
  275. continue;
  276. }
  277. // Rename some POST variables into a generic name
  278. if (GETPOST('actionmodify', 'alpha') && $value == 'topic') {
  279. $_POST['topic'] = GETPOST('topic-'.$rowid);
  280. }
  281. if ((!GETPOSTISSET($value) || GETPOST($value) == '' || GETPOST($value) == '-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position') {
  282. $ok = 0;
  283. $fieldnamekey = $listfield[$f];
  284. // We take translate key of field
  285. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) {
  286. $fieldnamekey = 'Code';
  287. }
  288. if ($fieldnamekey == 'code') {
  289. $fieldnamekey = 'Code';
  290. }
  291. if ($fieldnamekey == 'note') {
  292. $fieldnamekey = 'Note';
  293. }
  294. if ($fieldnamekey == 'type_template') {
  295. $fieldnamekey = 'TypeOfTemplate';
  296. }
  297. if ($fieldnamekey == 'fk_user') {
  298. $fieldnamekey = 'Owner';
  299. }
  300. if ($fieldnamekey == 'private') {
  301. $fieldnamekey = 'Private';
  302. }
  303. if ($fieldnamekey == 'position') {
  304. $fieldnamekey = 'Position';
  305. }
  306. if ($fieldnamekey == 'topic') {
  307. $fieldnamekey = 'Topic';
  308. }
  309. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  310. $action = 'create';
  311. }
  312. }
  313. // If previous test is ok action is add, we add the line
  314. if ($ok && GETPOST('actionadd')) {
  315. // Add new entry
  316. $sql = "INSERT INTO ".$tabname[$id]." (";
  317. // List of fields
  318. $sql .= $tabfieldinsert[$id];
  319. $sql .= ", active, enabled)";
  320. $sql .= " VALUES(";
  321. // List of values
  322. $i = 0;
  323. foreach ($listfieldinsert as $f => $value) {
  324. $keycode = isset($listfieldvalue[$i]) ? $listfieldvalue[$i] : "";
  325. if ($value == 'lang') {
  326. $keycode = 'langcode';
  327. }
  328. if (empty($keycode)) {
  329. $keycode = $value;
  330. }
  331. // Clean input variables
  332. if ($value == 'entity') {
  333. $_POST[$keycode] = $conf->entity;
  334. }
  335. if ($value == 'fk_user' && !($_POST[$keycode] > 0)) {
  336. $_POST[$keycode] = '';
  337. }
  338. if ($value == 'private' && !is_numeric($_POST[$keycode])) {
  339. $_POST[$keycode] = '0';
  340. }
  341. if ($value == 'position' && !is_numeric($_POST[$keycode])) {
  342. $_POST[$keycode] = '1';
  343. }
  344. if ($value == 'defaultfortype' && !is_numeric($_POST[$keycode])) {
  345. $_POST[$keycode] = '0';
  346. }
  347. //var_dump($keycode.' '.$value);
  348. if ($i) {
  349. $sql .= ", ";
  350. }
  351. if (GETPOST($keycode) == '' && $keycode != 'langcode') {
  352. $sql .= "null"; // langcode must be '' if not defined so the unique key that include lang will work
  353. } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
  354. $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
  355. } elseif ($keycode == 'fk_user') {
  356. if (!$user->admin) { // A non admin user can only edit its own template
  357. $sql .= " ".((int) $user->id);
  358. } else {
  359. $sql .= " ".((int) GETPOST($keycode, 'int'));
  360. }
  361. } elseif ($keycode == 'content') {
  362. $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
  363. } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private', 'position', 'entity'))) {
  364. $sql .= (int) GETPOST($keycode, 'int');
  365. } else {
  366. $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
  367. }
  368. $i++;
  369. }
  370. $sql .= ", 1, 1)";
  371. dol_syslog("actionadd", LOG_DEBUG);
  372. $result = $db->query($sql);
  373. if ($result) { // Add is ok
  374. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  375. $_POST = array('id'=>$id); // Clean $_POST array, we keep only id
  376. } else {
  377. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  378. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  379. } else {
  380. dol_print_error($db);
  381. }
  382. $action = 'create';
  383. }
  384. }
  385. // We modify the line
  386. if ($ok && GETPOST('actionmodify')) {
  387. $rowidcol = "rowid";
  388. // Modify entry
  389. $sql = "UPDATE ".$tabname[$id]." SET ";
  390. // Modify value of fields
  391. $i = 0;
  392. foreach ($listfieldmodify as $field) {
  393. if ($field == 'entity') {
  394. // entity not present on listfieldmodify array
  395. $keycode = $field;
  396. $_POST[$keycode] = $conf->entity;
  397. } else {
  398. $keycode = $listfieldvalue[$i];
  399. }
  400. if ($field == 'lang') {
  401. $keycode = 'langcode';
  402. }
  403. if (empty($keycode)) {
  404. $keycode = $field;
  405. }
  406. // Rename some POST variables into a generic name
  407. if ($field == 'fk_user' && !(GETPOST('fk_user', 'int') > 0)) {
  408. $_POST['fk_user'] = '';
  409. }
  410. if ($field == 'topic') {
  411. $_POST['topic'] = GETPOST('topic-'.$rowid);
  412. }
  413. if ($field == 'joinfiles') {
  414. $_POST['joinfiles'] = GETPOST('joinfiles-'.$rowid);
  415. }
  416. if ($field == 'content') {
  417. $_POST['content'] = GETPOST('content-'.$rowid, 'restricthtml');
  418. }
  419. if ($field == 'content_lines') {
  420. $_POST['content_lines'] = GETPOST('content_lines-'.$rowid, 'restricthtml');
  421. }
  422. if ($i) {
  423. $sql .= ", ";
  424. }
  425. $sql .= $field."=";
  426. if (GETPOST($keycode) == '' || (!in_array($keycode, array('langcode', 'position', 'private', 'defaultfortype')) && !GETPOST($keycode))) {
  427. $sql .= "null"; // langcode,... must be '' if not defined so the unique key that include lang will work
  428. } elseif (GETPOST($keycode) == '0' && $keycode == 'langcode') {
  429. $sql .= "''"; // langcode must be '' if not defined so the unique key that include lang will work
  430. } elseif ($keycode == 'fk_user') {
  431. if (!$user->admin) { // A non admin user can only edit its own template
  432. $sql .= " ".((int) $user->id);
  433. } else {
  434. $sql .= " ".((int) GETPOST($keycode, 'int'));
  435. }
  436. } elseif ($keycode == 'content') {
  437. $sql .= "'".$db->escape(GETPOST($keycode, 'restricthtml'))."'";
  438. } elseif (in_array($keycode, array('joinfiles', 'defaultfortype', 'private', 'position'))) {
  439. $sql .= (int) GETPOST($keycode, 'int');
  440. } else {
  441. $sql .= "'".$db->escape(GETPOST($keycode, 'alphanohtml'))."'";
  442. }
  443. $i++;
  444. }
  445. $sql .= " WHERE ".$db->escape($rowidcol)." = ".((int) $rowid);
  446. if (!$user->admin) { // A non admin user can only edit its own template
  447. $sql .= " AND fk_user = ".((int) $user->id);
  448. }
  449. //print $sql;exit;
  450. dol_syslog("actionmodify", LOG_DEBUG);
  451. //print $sql;
  452. $resql = $db->query($sql);
  453. if ($resql) {
  454. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  455. } else {
  456. setEventMessages($db->error(), null, 'errors');
  457. $action = 'edit';
  458. }
  459. }
  460. }
  461. if ($action == 'confirm_delete' && $confirm == 'yes' && $permissiontodelete) { // delete
  462. $rowidcol = "rowid";
  463. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol." = ".((int) $rowid);
  464. if (!$user->admin) { // A non admin user can only edit its own template
  465. $sql .= " AND fk_user = ".((int) $user->id);
  466. }
  467. dol_syslog("delete", LOG_DEBUG);
  468. $result = $db->query($sql);
  469. if (!$result) {
  470. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS') {
  471. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  472. } else {
  473. dol_print_error($db);
  474. }
  475. }
  476. }
  477. // activate
  478. if ($action == $acts[0] && $permissiontoadd) {
  479. $rowidcol = "rowid";
  480. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE rowid = ".((int) $rowid);
  481. $result = $db->query($sql);
  482. if (!$result) {
  483. dol_print_error($db);
  484. }
  485. }
  486. // disable
  487. if ($action == $acts[1] && $permissiontoadd) {
  488. $rowidcol = "rowid";
  489. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE rowid = ".((int) $rowid);
  490. $result = $db->query($sql);
  491. if (!$result) {
  492. dol_print_error($db);
  493. }
  494. }
  495. }
  496. /*
  497. * View
  498. */
  499. $form = new Form($db);
  500. $now = dol_now();
  501. $formadmin = new FormAdmin($db);
  502. //$help_url = "EN:Module_MyObject|FR:Module_MyObject_FR|ES:Módulo_MyObject";
  503. $help_url = '';
  504. if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
  505. $title = $langs->trans("EMailsSetup");
  506. } else {
  507. $title = $langs->trans("EMailTemplates");
  508. }
  509. $morejs = array();
  510. $morecss = array();
  511. $sql = "SELECT rowid as rowid, module, label, type_template, lang, fk_user, private, position, topic, email_from,joinfiles, defaultfortype, content_lines, content, enabled, active";
  512. $sql .= " FROM ".MAIN_DB_PREFIX."c_email_templates";
  513. $sql .= " WHERE entity IN (".getEntity('email_template').")";
  514. if (!$user->admin) {
  515. $sql .= " AND (private = 0 OR (private = 1 AND fk_user = ".((int) $user->id)."))"; // Show only public and private to me
  516. $sql .= " AND (active = 1 OR fk_user = ".((int) $user->id).")"; // Show only active or owned by me
  517. }
  518. if (!getDolGlobalInt('MAIN_MULTILANGS')) {
  519. $sql .= " AND (lang = '".$db->escape($langs->defaultlang)."' OR lang IS NULL OR lang = '')";
  520. }
  521. if ($search_label) {
  522. $sql .= natural_search('label', $search_label);
  523. }
  524. if ($search_type_template != '' && $search_type_template != '-1') {
  525. $sql .= natural_search('type_template', $search_type_template);
  526. }
  527. if ($search_lang) {
  528. $sql .= natural_search('lang', $search_lang);
  529. }
  530. if ($search_fk_user != '' && $search_fk_user != '-1') {
  531. $sql .= natural_search('fk_user', $search_fk_user, 2);
  532. }
  533. if ($search_module) {
  534. $sql .= natural_search('module', $search_module);
  535. }
  536. if ($search_topic) {
  537. $sql .= natural_search('topic', $search_topic);
  538. }
  539. // If sort order is "country", we use country_code instead
  540. if ($sortfield == 'country') {
  541. $sortfield = 'country_code';
  542. }
  543. $sql .= $db->order($sortfield, $sortorder);
  544. $sql .= $db->plimit($listlimit + 1, $offset);
  545. //print $sql;
  546. // Output page
  547. // --------------------------------------------------------------------
  548. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  549. $arrayofselected = is_array($toselect) ? $toselect : array();
  550. $param = '';
  551. if (!empty($mode)) {
  552. $param .= '&mode='.urlencode($mode);
  553. }
  554. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  555. $param .= '&contextpage='.urlencode($contextpage);
  556. }
  557. if ($limit > 0 && $limit != $conf->liste_limit) {
  558. $param .= '&limit='.((int) $limit);
  559. }
  560. if (!empty($search) && is_array($search)) {
  561. foreach ($search as $key => $val) {
  562. if (is_array($search[$key]) && count($search[$key])) {
  563. foreach ($search[$key] as $skey) {
  564. if ($skey != '') {
  565. $param .= '&search_'.$key.'[]='.urlencode($skey);
  566. }
  567. }
  568. } elseif ($search[$key] != '') {
  569. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  570. }
  571. }
  572. }
  573. if ($optioncss != '') {
  574. $param .= '&optioncss='.urlencode($optioncss);
  575. }
  576. // Add $param from extra fields
  577. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  578. // Add $param from hooks
  579. $parameters = array();
  580. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  581. $param .= $hookmanager->resPrint;
  582. $linkback = '';
  583. $titlepicto = 'title_setup';
  584. $url = DOL_URL_ROOT.'/admin/mails_templates.php?action=create';
  585. $newcardbutton = '';
  586. $newcardbutton .= dolGetButtonTitle($langs->trans('NewEMailTemplate'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
  587. if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
  588. print load_fiche_titre($title, '', $titlepicto);
  589. } else {
  590. print load_fiche_titre($title, $newcardbutton, $titlepicto);
  591. }
  592. if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
  593. $head = email_admin_prepare_head();
  594. print dol_get_fiche_head($head, 'templates', '', -1);
  595. if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
  596. print load_fiche_titre('', $newcardbutton, '');
  597. }
  598. }
  599. // Confirm deletion of record
  600. if ($action == 'delete') {
  601. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.((int) $rowid).'&code='.urlencode($code).'&id='.((int) $id), $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete', '', 0, 1);
  602. }
  603. $fieldlist = explode(',', $tabfield[$id]);
  604. if ($action == 'create') {
  605. // If data was already input, we define them in obj to populate input fields.
  606. $obj = new stdClass();
  607. $obj->label = GETPOST('label');
  608. $obj->lang = GETPOST('lang');
  609. $obj->type_template = GETPOST('type_template');
  610. $obj->fk_user = GETPOST('fk_user', 'int');
  611. $obj->private = GETPOST('private', 'int');
  612. $obj->position = GETPOST('position');
  613. $obj->topic = GETPOST('topic');
  614. $obj->joinfiles = GETPOST('joinfiles');
  615. $obj->defaultfortype = GETPOST('defaultfortype') ? 1 : 0;
  616. $obj->content = GETPOST('content', 'restricthtml');
  617. // Form to add a new line
  618. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  619. print '<input type="hidden" name="token" value="'.newToken().'">';
  620. print '<input type="hidden" name="action" value="add">';
  621. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  622. print '<div class="div-table-responsive-no-min">';
  623. print '<table class="noborder centpercent">';
  624. // Line to enter new values (title)
  625. print '<tr class="liste_titre">';
  626. foreach ($fieldlist as $field => $value) {
  627. // Determine le nom du champ par rapport aux noms possibles
  628. // dans les dictionnaires de donnees
  629. $valuetoshow = ucfirst($fieldlist[$field]); // Par defaut
  630. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  631. $css = "left";
  632. if ($fieldlist[$field] == 'module') {
  633. $valuetoshow = '&nbsp;';
  634. }
  635. if ($fieldlist[$field] == 'fk_user') {
  636. $valuetoshow = $langs->trans("Owner");
  637. }
  638. if ($fieldlist[$field] == 'lang') {
  639. $valuetoshow = (!getDolGlobalInt('MAIN_MULTILANGS') ? '&nbsp;' : $langs->trans("Language"));
  640. }
  641. if ($fieldlist[$field] == 'type') {
  642. $valuetoshow = $langs->trans("Type");
  643. }
  644. if ($fieldlist[$field] == 'position') {
  645. $css = 'center';
  646. }
  647. if ($fieldlist[$field] == 'code') {
  648. $valuetoshow = $langs->trans("Code");
  649. }
  650. if ($fieldlist[$field] == 'label') {
  651. $valuetoshow = $langs->trans("Code");
  652. }
  653. if ($fieldlist[$field] == 'type_template') {
  654. $valuetoshow = $langs->trans("TypeOfTemplate");
  655. $css = "center";
  656. }
  657. if (in_array($fieldlist[$field], array('private', 'private', 'defaultfortype'))) {
  658. $css = 'center';
  659. }
  660. if ($fieldlist[$field] == 'topic') {
  661. $valuetoshow = '';
  662. }
  663. if ($fieldlist[$field] == 'joinfiles') {
  664. $valuetoshow = '';
  665. }
  666. if ($fieldlist[$field] == 'content') {
  667. $valuetoshow = '';
  668. }
  669. if ($fieldlist[$field] == 'content_lines') {
  670. $valuetoshow = '';
  671. }
  672. if ($valuetoshow != '') {
  673. print '<th class="'.$css.'">';
  674. if (!empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i', $tabhelp[$id][$value])) {
  675. print '<a href="'.$tabhelp[$id][$value].'" target="_blank" rel="noopener noreferrer">'.$valuetoshow.' '.img_help(1, $valuetoshow).'</a>';
  676. } elseif (!empty($tabhelp[$id][$value])) {
  677. if (in_array($value, array('topic'))) {
  678. print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
  679. } else {
  680. print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
  681. }
  682. } else {
  683. print $valuetoshow;
  684. }
  685. print '</th>';
  686. }
  687. }
  688. print '<th>';
  689. print '<input type="hidden" name="id" value="'.$id.'">';
  690. print '</th>';
  691. print '</tr>';
  692. $tmpaction = 'create';
  693. $parameters = array(
  694. 'fieldlist' => $fieldlist,
  695. 'tabname' => $tabname[$id]
  696. );
  697. $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  698. $error = $hookmanager->error;
  699. $errors = $hookmanager->errors;
  700. // Line to enter new values (input fields)
  701. print '<tr class="oddeven">';
  702. if (empty($reshook)) {
  703. if ($action == 'edit') {
  704. fieldList($fieldlist, $obj, $tabname[$id], 'hide');
  705. } else {
  706. fieldList($fieldlist, $obj, $tabname[$id], 'add');
  707. }
  708. }
  709. // Action column
  710. print '<td class="right">';
  711. print '</td>';
  712. print "</tr>";
  713. print '<tr class="impair nodrag nodrop nohover"><td colspan="9" class="nobottom">';
  714. // Show fields for topic, join files and body
  715. $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content');
  716. if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
  717. $fieldsforcontent = array('topic', 'email_from', 'joinfiles', 'content', 'content_lines');
  718. }
  719. foreach ($fieldsforcontent as $tmpfieldlist) {
  720. // Topic of email
  721. if ($tmpfieldlist == 'topic') {
  722. print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
  723. }
  724. if ($tmpfieldlist == 'email_from') {
  725. print $form->textwithpicto($langs->trans("MailFrom"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist);
  726. }
  727. if ($tmpfieldlist == 'joinfiles') {
  728. print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
  729. }
  730. if ($tmpfieldlist == 'content') {
  731. print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
  732. }
  733. if ($tmpfieldlist == 'content_lines') {
  734. print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
  735. }
  736. // Input field
  737. if ($tmpfieldlist == 'topic') {
  738. print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
  739. } elseif ($tmpfieldlist == 'email_from') {
  740. print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="'.(!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '').'">';
  741. } elseif ($tmpfieldlist == 'joinfiles') {
  742. print $form->selectyesno($tmpfieldlist, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
  743. } else {
  744. $okforextended = true;
  745. if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
  746. $okforextended = false;
  747. }
  748. $doleditor = new DolEditor($tmpfieldlist, (!empty($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : ''), '', 400, 'dolibarr_mailings', 'In', false, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
  749. print $doleditor->Create(1);
  750. }
  751. print '<br>';
  752. }
  753. print '</tr>';
  754. print '</table>';
  755. if ($action != 'edit') {
  756. print '<center>';
  757. print '<input type="submit" class="button button-add" name="actionadd" value="'.$langs->trans("Add").'"> ';
  758. print '<input type="submit" class="button button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  759. print '</center>';
  760. }
  761. print '</div>';
  762. print '</form>';
  763. print '<br><br>';
  764. }
  765. // List of available record in database
  766. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  767. $resql = $db->query($sql);
  768. if (!$resql) {
  769. dol_print_error($db);
  770. exit;
  771. }
  772. $num = $db->num_rows($resql);
  773. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  774. print '<input type="hidden" name="token" value="'.newToken().'">';
  775. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from', 'alpha')).'">';
  776. print '<div class="div-table-responsive-no-min">';
  777. print '<table class="noborder centpercent">';
  778. $i = 0;
  779. $param = '&id='.((int) $id);
  780. if ($search_label) {
  781. $param .= '&search_label='.urlencode($search_label);
  782. }
  783. if ($search_lang > 0) {
  784. $param .= '&search_lang='.urlencode($search_lang);
  785. }
  786. if ($search_type_template != '-1') {
  787. $param .= '&search_type_template='.urlencode($search_type_template);
  788. }
  789. if ($search_fk_user > 0) {
  790. $param .= '&search_fk_user='.urlencode($search_fk_user);
  791. }
  792. if ($search_module) {
  793. $param .= '&search_module='.urlencode($search_module);
  794. }
  795. if ($search_topic) {
  796. $param .= '&search_topic='.urlencode($search_topic);
  797. }
  798. $paramwithsearch = $param;
  799. if ($sortorder) {
  800. $paramwithsearch .= '&sortorder='.urlencode($sortorder);
  801. }
  802. if ($sortfield) {
  803. $paramwithsearch .= '&sortfield='.urlencode($sortfield);
  804. }
  805. if (GETPOST('from', 'alpha')) {
  806. $paramwithsearch .= '&from='.urlencode(GETPOST('from', 'alpha'));
  807. }
  808. // There is several pages
  809. if ($num > $listlimit) {
  810. print '<tr class="none"><td class="right" colspan="'.(3 + count($fieldlist)).'">';
  811. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page + 1).'</span></li>');
  812. print '</td></tr>';
  813. }
  814. // Title line with search boxes
  815. print '<tr class="liste_titre">';
  816. // Action column
  817. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  818. print '<td class="liste_titre center" width="64">';
  819. $searchpicto = $form->showFilterButtons();
  820. print $searchpicto;
  821. print '</td>';
  822. }
  823. foreach ($fieldlist as $field => $value) {
  824. if ($value == 'module') {
  825. print '<td class="liste_titre"><input type="text" name="search_module" class="maxwidth75" value="'.dol_escape_htmltag($search_module).'"></td>';
  826. } elseif ($value == 'label') {
  827. print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth75" value="'.dol_escape_htmltag($search_label).'"></td>';
  828. } elseif ($value == 'lang') {
  829. print '<td class="liste_titre">';
  830. print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100');
  831. print '</td>';
  832. } elseif ($value == 'fk_user') {
  833. print '<td class="liste_titre">';
  834. print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'maxwidth100', 1);
  835. print '</td>';
  836. } elseif ($value == 'topic') {
  837. print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
  838. } elseif ($value == 'type_template') {
  839. print '<td class="liste_titre center">';
  840. print $form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'minwidth100 maxwidth125', 1, '', 0, 1);
  841. print '</td>';
  842. } elseif (!in_array($value, array('content', 'content_lines'))) {
  843. print '<td class="liste_titre"></td>';
  844. }
  845. }
  846. /*if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) {
  847. print '<td class="liste_titre"></td>';
  848. }*/
  849. // Status
  850. print '<td></td>';
  851. // Action column
  852. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  853. print '<td class="liste_titre center" width="64">';
  854. $searchpicto = $form->showFilterButtons();
  855. print $searchpicto;
  856. print '</td>';
  857. }
  858. print '</tr>';
  859. // Title of lines
  860. print '<tr class="liste_titre">';
  861. // Action column
  862. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  863. print getTitleFieldOfList('');
  864. }
  865. foreach ($fieldlist as $field => $value) {
  866. $showfield = 1; // By defaut
  867. $css = "left";
  868. $sortable = 1;
  869. $valuetoshow = '';
  870. $forcenowrap = 1;
  871. /*
  872. $tmparray=getLabelOfField($fieldlist[$field]);
  873. $showfield=$tmp['showfield'];
  874. $valuetoshow=$tmp['valuetoshow'];
  875. $css=$tmp['align'];
  876. $sortable=$tmp['sortable'];
  877. */
  878. $valuetoshow = ucfirst($fieldlist[$field]); // By defaut
  879. $valuetoshow = $langs->trans($valuetoshow); // try to translate
  880. if ($fieldlist[$field] == 'module') {
  881. $css = 'tdoverflowmax100';
  882. }
  883. if ($fieldlist[$field] == 'fk_user') {
  884. $valuetoshow = $langs->trans("Owner");
  885. }
  886. if ($fieldlist[$field] == 'lang') {
  887. $valuetoshow = $langs->trans("Language");
  888. }
  889. if ($fieldlist[$field] == 'type') {
  890. $valuetoshow = $langs->trans("Type");
  891. }
  892. if ($fieldlist[$field] == 'libelle' || $fieldlist[$field] == 'label') {
  893. $valuetoshow = $langs->trans("Code");
  894. }
  895. if ($fieldlist[$field] == 'type_template') {
  896. $css = 'center';
  897. $valuetoshow = $langs->trans("TypeOfTemplate");
  898. }
  899. if ($fieldlist[$field] == 'private') {
  900. $css = 'center';
  901. }
  902. if ($fieldlist[$field] == 'position') {
  903. $css = 'center';
  904. }
  905. if ($fieldlist[$field] == 'joinfiles') {
  906. $valuetoshow = $langs->trans("FilesAttachedToEmail");
  907. $css = 'center';
  908. $forcenowrap = 0;
  909. }
  910. if ($fieldlist[$field] == 'content') {
  911. $valuetoshow = $langs->trans("Content");
  912. $showfield = 0;
  913. }
  914. if ($fieldlist[$field] == 'content_lines') {
  915. $valuetoshow = $langs->trans("ContentForLines");
  916. $showfield = 0;
  917. }
  918. // Show fields
  919. if ($showfield) {
  920. if (!empty($tabhelp[$id][$value])) {
  921. if (in_array($value, array('topic'))) {
  922. $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
  923. } else {
  924. $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
  925. }
  926. }
  927. $sortfieldtouse = ($sortable ? $fieldlist[$field] : '');
  928. if ($sortfieldtouse == 'type_template') {
  929. $sortfieldtouse.= 'type_template,lang,position,label';
  930. }
  931. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], $sortfieldtouse, ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, $css.' ');
  932. }
  933. }
  934. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page ? 'page='.$page.'&' : ''), $param, '', $sortfield, $sortorder, 'center ');
  935. // Action column
  936. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  937. print getTitleFieldOfList('');
  938. }
  939. print '</tr>';
  940. if ($num) {
  941. $nbqualified = 0;
  942. // Lines with values
  943. while ($i < $num) {
  944. $obj = $db->fetch_object($resql);
  945. if ($obj) {
  946. if ($action == 'edit' && ($rowid == (!empty($obj->rowid) ? $obj->rowid : $obj->code))) {
  947. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  948. $tmpaction = 'edit';
  949. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  950. $reshook = $hookmanager->executeHooks('editEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  951. $error = $hookmanager->error;
  952. $errors = $hookmanager->errors;
  953. // Action column
  954. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  955. print '<td class="center">';
  956. print '<input type="hidden" name="page" value="'.$page.'">';
  957. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  958. print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Modify").'">';
  959. print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
  960. print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  961. print '</td>';
  962. }
  963. // Show main fields
  964. if (empty($reshook)) {
  965. fieldList($fieldlist, $obj, $tabname[$id], 'edit');
  966. }
  967. // Action column
  968. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  969. print '<td class="center">';
  970. print '<input type="hidden" name="page" value="'.$page.'">';
  971. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  972. print '<input type="submit" class="button buttongen button-save" name="actionmodify" value="'.$langs->trans("Modify").'">';
  973. print '<div name="'.(!empty($obj->rowid) ? $obj->rowid : $obj->code).'"></div>';
  974. print '<input type="submit" class="button buttongen button-cancel" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  975. print '</td>';
  976. }
  977. print "</tr>\n";
  978. print '<tr class="oddeven nohover'.(in_array($tmpfieldlist, array('topic', 'joinfiles')) ? ' nobottom' : '').'" id="tr-'.$tmpfieldlist.'-'.$rowid.'">';
  979. print '<td colspan="10">';
  980. $fieldsforcontent = array('topic', 'email_from','joinfiles', 'content');
  981. if (getDolGlobalString('MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES')) {
  982. $fieldsforcontent[] = 'content_lines';
  983. }
  984. foreach ($fieldsforcontent as $tmpfieldlist) {
  985. $showfield = 1;
  986. $css = "left";
  987. $valuetoshow = $obj->$tmpfieldlist;
  988. $class = 'tddict';
  989. // Show value for field
  990. if ($showfield) {
  991. // Show line for topic, joinfiles and content
  992. if ($tmpfieldlist == 'topic') {
  993. print '<strong>'.$form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
  994. print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
  995. print '<br>'."\n";
  996. }
  997. if ($tmpfieldlist == 'email_from') {
  998. print '<strong>'.$form->textwithpicto($langs->trans("MailFrom"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
  999. print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="'.(!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '').'">';
  1000. print '<br>'."\n";
  1001. }
  1002. if ($tmpfieldlist == 'joinfiles') {
  1003. print '<strong>'.$form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong> ';
  1004. print $form->selectyesno($tmpfieldlist.'-'.$rowid, (isset($obj->$tmpfieldlist) ? $obj->$tmpfieldlist : '0'), 1, false, 0, 1);
  1005. print '<br>'."\n";
  1006. }
  1007. if ($tmpfieldlist == 'content') {
  1008. print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
  1009. $okforextended = true;
  1010. if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
  1011. $okforextended = false;
  1012. }
  1013. $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 500, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
  1014. print $doleditor->Create(1);
  1015. }
  1016. if ($tmpfieldlist == 'content_lines') {
  1017. print '<br>'."\n";
  1018. print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'<br>';
  1019. $okforextended = true;
  1020. if (!getDolGlobalString('FCKEDITOR_ENABLE_MAIL')) {
  1021. $okforextended = false;
  1022. }
  1023. $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (!empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, $acceptlocallinktomedia, $okforextended, ROWS_6, '90%');
  1024. print $doleditor->Create(1);
  1025. }
  1026. }
  1027. }
  1028. print '</td>';
  1029. print '<td></td>';
  1030. print '<td></td>';
  1031. print "</tr>\n";
  1032. $nbqualified++;
  1033. } else {
  1034. // If template is for a module, check module is enabled.
  1035. if ($obj->module) {
  1036. $tempmodulekey = $obj->module;
  1037. if (empty($conf->$tempmodulekey) || !isModEnabled($tempmodulekey)) {
  1038. $i++;
  1039. continue;
  1040. }
  1041. }
  1042. $keyforobj = 'type_template';
  1043. if (!in_array($obj->$keyforobj, array_keys($elementList))) {
  1044. $i++;
  1045. continue; // It means this is a type of template not into elementList (may be because enabled condition of this type is false because module is not enabled)
  1046. }
  1047. // Test on 'enabled'
  1048. if (!dol_eval($obj->enabled, 1, 1, '1')) {
  1049. $i++;
  1050. continue; // Email template not qualified
  1051. }
  1052. $nbqualified++;
  1053. // Can an entry be erased or disabled ?
  1054. $iserasable = 1;
  1055. $canbedisabled = 1;
  1056. $canbemodified = 1; // true by default
  1057. if (!$user->admin && $obj->fk_user != $user->id) {
  1058. $iserasable = 0;
  1059. $canbedisabled = 0;
  1060. $canbemodified = 0;
  1061. }
  1062. $url = $_SERVER["PHP_SELF"].'?'.($page ? 'page='.$page.'&' : '').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(!empty($obj->rowid) ? $obj->rowid : (!empty($obj->code) ? $obj->code : '')).'&code='.(!empty($obj->code) ? urlencode($obj->code) : '');
  1063. if ($param) {
  1064. $url .= '&'.$param;
  1065. }
  1066. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  1067. // Action column - Modify link / Delete link
  1068. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1069. print '<td class="center nowraponall" width="64">';
  1070. if ($canbemodified) {
  1071. print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
  1072. }
  1073. if ($iserasable) {
  1074. print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
  1075. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  1076. }
  1077. print '</td>';
  1078. }
  1079. $tmpaction = 'view';
  1080. $parameters = array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  1081. $reshook = $hookmanager->executeHooks('viewEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  1082. $error = $hookmanager->error;
  1083. $errors = $hookmanager->errors;
  1084. if (empty($reshook)) {
  1085. foreach ($fieldlist as $field => $value) {
  1086. if (in_array($fieldlist[$field], array('content', 'content_lines'))) {
  1087. continue;
  1088. }
  1089. $showfield = 1;
  1090. $css = "";
  1091. $class = "tddict";
  1092. $title = '';
  1093. $tmpvar = $fieldlist[$field];
  1094. $valuetoshow = $obj->$tmpvar;
  1095. if ($value == 'label' || $value == 'topic') {
  1096. if ($langs->trans($valuetoshow) != $valuetoshow) {
  1097. $valuetoshow = $langs->trans($valuetoshow);
  1098. }
  1099. $valuetoshow = dol_escape_htmltag($valuetoshow);
  1100. }
  1101. if ($value == 'label') {
  1102. $class .= ' tdoverflowmax200';
  1103. }
  1104. if ($value == 'topic') {
  1105. $class .= ' tdoverflowmax200 small';
  1106. }
  1107. if ($value == 'type_template') {
  1108. $valuetoshow = isset($elementList[$valuetoshow]) ? $elementList[$valuetoshow] : $valuetoshow;
  1109. $css = "center tdoverflowmax150";
  1110. }
  1111. if ($value == 'lang' && $valuetoshow) {
  1112. $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
  1113. $class .= ' tdoverflowmax100';
  1114. }
  1115. if ($value == 'fk_user') {
  1116. if ($valuetoshow > 0) {
  1117. $fuser = new User($db);
  1118. $fuser->fetch($valuetoshow);
  1119. $valuetoshow = $fuser->getNomUrl(1);
  1120. $class .= ' tdoverflowmax100';
  1121. }
  1122. }
  1123. if ($value == 'private') {
  1124. $css = "center";
  1125. if ($valuetoshow) {
  1126. $valuetoshow = yn($valuetoshow);
  1127. } else {
  1128. $valuetoshow = '';
  1129. }
  1130. }
  1131. if ($value == 'position') {
  1132. $css = "center";
  1133. }
  1134. if (in_array($value, array('joinfiles', 'defaultfortype'))) {
  1135. $css = "center";
  1136. if ($valuetoshow) {
  1137. //$valuetoshow = yn(1);
  1138. $valuetoshow = '<input type="checkbox" checked="checked" disabled>';
  1139. } else {
  1140. $valuetoshow = '';
  1141. }
  1142. }
  1143. if ($css) {
  1144. $class .= ' '.$css;
  1145. }
  1146. // Show value for field
  1147. if ($showfield) {
  1148. print '<!-- '.$fieldlist[$field].' -->';
  1149. print '<td class="'.$class.'"';
  1150. if (in_array($value, array('code', 'label', 'topic'))) {
  1151. print ' title="'.dol_escape_htmltag($valuetoshow).'"';
  1152. }
  1153. print '>';
  1154. print $valuetoshow;
  1155. print '</td>';
  1156. }
  1157. }
  1158. }
  1159. // Status / Active
  1160. print '<td class="center nowrap">';
  1161. if ($canbedisabled) {
  1162. print '<a class="reposition" href="'.$url.'&action='.$acts[$obj->active].'&token='.newToken().'">'.$actl[$obj->active].'</a>';
  1163. } else {
  1164. print '<span class="opacitymedium">'.$actl[$obj->active].'</span>';
  1165. }
  1166. print "</td>";
  1167. // Action column - Modify link / Delete link
  1168. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1169. print '<td class="center nowraponall" width="64">';
  1170. if ($canbemodified) {
  1171. print '<a class="reposition editfielda" href="'.$url.'&action=edit&token='.newToken().'">'.img_edit().'</a>';
  1172. }
  1173. if ($iserasable) {
  1174. print '<a class="reposition marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a>';
  1175. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  1176. }
  1177. print '</td>';
  1178. }
  1179. print "</tr>\n";
  1180. }
  1181. }
  1182. $i++;
  1183. }
  1184. }
  1185. // If no record found
  1186. if ($nbqualified == 0) {
  1187. $colspan = 12;
  1188. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1189. }
  1190. print '</table>';
  1191. print '</div>';
  1192. print '</form>';
  1193. if (!empty($user->admin) && (empty($_SESSION['leftmenu']) || $_SESSION['leftmenu'] != 'email_templates')) {
  1194. print dol_get_fiche_end();
  1195. }
  1196. // End of page
  1197. llxFooter();
  1198. $db->close();
  1199. /**
  1200. * Show fields in insert/edit mode
  1201. *
  1202. * @param array $fieldlist Array of fields
  1203. * @param Object $obj If we show a particular record, obj is filled with record fields
  1204. * @param string $tabname Name of SQL table
  1205. * @param string $context 'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered
  1206. * @return void
  1207. */
  1208. function fieldList($fieldlist, $obj = null, $tabname = '', $context = '')
  1209. {
  1210. global $langs, $user, $db;
  1211. global $form;
  1212. global $elementList;
  1213. $formadmin = new FormAdmin($db);
  1214. foreach ($fieldlist as $field => $value) {
  1215. //print $value;
  1216. if ($value == 'module') {
  1217. print '<td></td>';
  1218. } elseif ($value == 'fk_user') {
  1219. print '<td>';
  1220. if ($user->admin) {
  1221. print $form->select_dolusers(empty($obj->$value) ? '' : $obj->$value, 'fk_user', 1, null, 0, ($user->admin ? '' : 'hierarchyme'), null, 0, 0, 0, '', 0, '', 'minwidth75 maxwidth100');
  1222. } else {
  1223. if ($context == 'add') { // I am not admin and we show the add form
  1224. print $user->getNomUrl(1); // Me
  1225. $forcedvalue = $user->id;
  1226. } else {
  1227. if ($obj && !empty($obj->$value) && $obj->$value > 0) {
  1228. $fuser = new User($db);
  1229. $fuser->fetch($obj->$value);
  1230. print $fuser->getNomUrl(1);
  1231. $forcedvalue = $fuser->id;
  1232. } else {
  1233. $forcedvalue = $obj->$value;
  1234. }
  1235. }
  1236. $keyname = $value;
  1237. print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
  1238. }
  1239. print '</td>';
  1240. } elseif ($value == 'lang') {
  1241. print '<td>';
  1242. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1243. $selectedlang = GETPOSTISSET('langcode') ? GETPOST('langcode', 'aZ09') : $langs->defaultlang;
  1244. if ($context == 'edit') {
  1245. $selectedlang = $obj->lang;
  1246. }
  1247. print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth100');
  1248. } else {
  1249. if (!empty($obj->lang)) {
  1250. print $obj->lang.' - '.$langs->trans('Language_'.$obj->lang);
  1251. }
  1252. $keyname = $value;
  1253. if ($keyname == 'lang') {
  1254. $keyname = 'langcode'; // Avoid conflict with lang param
  1255. }
  1256. print '<input type="hidden" value="'.(empty($obj->lang) ? '' : $obj->lang).'" name="'.$keyname.'">';
  1257. }
  1258. print '</td>';
  1259. } elseif ($value == 'type_template') {
  1260. // Le type de template
  1261. print '<td class="center">';
  1262. if ($context == 'edit' && !empty($obj->type_template) && !in_array($obj->type_template, array_keys($elementList))) {
  1263. // Current template type is an unknown type, so we must keep it as it is.
  1264. print '<input type="hidden" name="type_template" value="'.$obj->type_template.'">';
  1265. print $obj->type_template;
  1266. } else {
  1267. print $form->selectarray('type_template', $elementList, (!empty($obj->type_template) ? $obj->type_template : ''), 1, 0, 0, '', 0, 0, 0, '', 'minwidth75 maxwidth125', 1, '', 0, 1);
  1268. }
  1269. print '</td>';
  1270. } elseif ($context == 'add' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
  1271. //print '<td></td>';
  1272. } elseif ($context == 'edit' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
  1273. print '<td></td>';
  1274. } elseif ($context == 'hide' && in_array($value, array('topic', 'joinfiles', 'content', 'content_lines'))) {
  1275. //print '<td></td>';
  1276. } else {
  1277. $size = '';
  1278. $class = '';
  1279. $classtd = '';
  1280. if ($value == 'code') {
  1281. $class = 'maxwidth100';
  1282. }
  1283. if ($value == 'label') {
  1284. $class = 'maxwidth200';
  1285. }
  1286. if ($value == 'private') {
  1287. $class = 'maxwidth50';
  1288. $classtd = 'center';
  1289. }
  1290. if ($value == 'position') {
  1291. $class = 'maxwidth50 center';
  1292. $classtd = 'center';
  1293. }
  1294. if ($value == 'topic') {
  1295. $class = 'quatrevingtpercent';
  1296. }
  1297. if ($value == 'defaultfortype') {
  1298. $class = 'width25 center';
  1299. $classtd = 'center';
  1300. }
  1301. print '<td'.($classtd ? ' class="'.$classtd.'"' : '').'>';
  1302. if ($value == 'private') {
  1303. if (empty($user->admin)) {
  1304. print $form->selectyesno($value, '1', 1);
  1305. } else {
  1306. print $form->selectyesno($value, (isset($obj->$value) ? $obj->$value : ''), 1);
  1307. }
  1308. } else {
  1309. print '<input type="text" '.$size.'class="flat'.($class ? ' '.$class : '').'" value="'.(isset($obj->$value) ? $obj->$value : '').'" name="'. $value .'">';
  1310. }
  1311. print '</td>';
  1312. }
  1313. }
  1314. }