mails_templates.php 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  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.dolibarr@gmail.com>
  12. * Copyright (C) 2015 Ferran Marcet <fmarcet@2byte.es>
  13. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  14. * Copyright (C) 2018 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 <http://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. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  40. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  41. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  42. // Load translation files required by the page
  43. $langs->loadLangs(array("errors","admin","mails","languages"));
  44. $action = GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
  45. $confirm = GETPOST('confirm','alpha'); // Result of a confirmation
  46. $id = GETPOST('id','int');
  47. $rowid = GETPOST('rowid','alpha');
  48. $search_label=GETPOST('search_label','alpha');
  49. $search_type_template=GETPOST('search_type_template','alpha');
  50. $search_lang=GETPOST('search_lang','alpha');
  51. $search_fk_user=GETPOST('search_fk_user','intcomma');
  52. $search_topic=GETPOST('search_topic','alpha');
  53. if (! empty($user->socid)) accessforbidden();
  54. $acts[0] = "activate";
  55. $acts[1] = "disable";
  56. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  57. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  58. $listoffset=GETPOST('listoffset','alpha');
  59. $listlimit =GETPOST('listlimit','alpha')>0?GETPOST('listlimit','alpha'):1000;
  60. $active = 1;
  61. $sortfield = GETPOST("sortfield",'alpha');
  62. $sortorder = GETPOST("sortorder",'alpha');
  63. $page = GETPOST("page",'int');
  64. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  65. $offset = $listlimit * $page ;
  66. $pageprev = $page - 1;
  67. $pagenext = $page + 1;
  68. if (empty($sortfield)) $sortfield='type_template, lang, position, label';
  69. if (empty($sortorder)) $sortorder='ASC';
  70. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  71. $hookmanager->initHooks(array('emailtemplates'));
  72. // Name of SQL tables of dictionaries
  73. $tabname=array();
  74. $tabname[25]= MAIN_DB_PREFIX."c_email_templates";
  75. // Nom des champs en resultat de select pour affichage du dictionnaire
  76. $tabfield=array();
  77. $tabfield[25]= "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
  78. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfield[25].=',content_lines';
  79. // Nom des champs d'edition pour modification d'un enregistrement
  80. $tabfieldvalue=array();
  81. $tabfieldvalue[25]= "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
  82. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldvalue[25].=',content_lines';
  83. // Nom des champs dans la table pour insertion d'un enregistrement
  84. $tabfieldinsert=array();
  85. $tabfieldinsert[25]= "label,lang,type_template,fk_user,private,position,topic,joinfiles,content";
  86. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldinsert[25].=',content_lines';
  87. $tabfieldinsert[25].=',entity'; // Must be at end because not into other arrays
  88. // Condition to show dictionary in setup page
  89. $tabcond=array();
  90. $tabcond[25]= true;
  91. // List of help for fields
  92. // Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
  93. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  94. $formmail=new FormMail($db);
  95. if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  96. {
  97. $tmp=FormMail::getAvailableSubstitKey('formemail');
  98. $tmp['__(AnyTranslationKey)__']='Translation';
  99. $helpsubstit = $langs->trans("AvailableVariables").':<br>';
  100. $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
  101. foreach($tmp as $key => $val)
  102. {
  103. $helpsubstit.=$key.' -> '.$val.'<br>';
  104. $helpsubstitforlines.=$key.' -> '.$val.'<br>';
  105. }
  106. }
  107. else
  108. {
  109. $tmp=FormMail::getAvailableSubstitKey('formemailwithlines');
  110. $tmp['__(AnyTranslationKey)__']='Translation';
  111. $helpsubstit = $langs->trans("AvailableVariables").':<br>';
  112. $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>';
  113. foreach($tmp as $key => $val)
  114. {
  115. $helpsubstit.=$key.' -> '.$val.'<br>';
  116. }
  117. $tmp=FormMail::getAvailableSubstitKey('formemailforlines');
  118. foreach($tmp as $key => $val)
  119. {
  120. $helpsubstitforlines.=$key.' -> '.$val.'<br>';
  121. }
  122. }
  123. $tabhelp=array();
  124. $tabhelp[25] = array('topic'=>$helpsubstit,'joinfiles'=>$langs->trans('AttachMainDocByDefault'), 'content'=>$helpsubstit,'content_lines'=>$helpsubstitforlines,'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList"));
  125. // List of check for fields (NOT USED YET)
  126. $tabfieldcheck=array();
  127. $tabfieldcheck[25] = array();
  128. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  129. $elementList = array();
  130. $sourceList=array();
  131. // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
  132. $elementList = array();
  133. if ($conf->propal->enabled) $elementList['propal_send']=$langs->trans('MailToSendProposal');
  134. if ($conf->commande->enabled) $elementList['order_send']=$langs->trans('MailToSendOrder');
  135. if ($conf->facture->enabled) $elementList['facture_send']=$langs->trans('MailToSendInvoice');
  136. if ($conf->expedition->enabled) $elementList['shipping_send']=$langs->trans('MailToSendShipment');
  137. if ($conf->ficheinter->enabled) $elementList['fichinter_send']=$langs->trans('MailToSendIntervention');
  138. if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send']=$langs->trans('MailToSendSupplierRequestForQuotation');
  139. if ($conf->fournisseur->enabled) $elementList['order_supplier_send']=$langs->trans('MailToSendSupplierOrder');
  140. if ($conf->fournisseur->enabled) $elementList['invoice_supplier_send']=$langs->trans('MailToSendSupplierInvoice');
  141. if ($conf->societe->enabled) $elementList['thirdparty']=$langs->trans('MailToThirdparty');
  142. if ($conf->adherent->enabled) $elementList['member']=$langs->trans('MailToMember');
  143. if ($conf->contrat->enabled) $elementList['contract']=$langs->trans('MailToSendContract');
  144. if ($conf->projet->enabled) $elementList['project']=$langs->trans('MailToProject');
  145. $elementList['user']=$langs->trans('MailToUser');
  146. $parameters=array('elementList'=>$elementList);
  147. $reshook=$hookmanager->executeHooks('emailElementlist',$parameters); // Note that $action and $object may have been modified by some hooks
  148. if ($reshook == 0) {
  149. foreach ($hookmanager->resArray as $item => $value) {
  150. $elementList[$item] = $value;
  151. }
  152. }
  153. // Add all and none after the sort
  154. $elementList['all'] ='-- '.$langs->trans("All").' -- ('.$langs->trans('VisibleEverywhere').')';
  155. $elementList['none']='-- '.$langs->trans("None").' -- ('.$langs->trans('VisibleNowhere').')';
  156. asort($elementList);
  157. $id = 25;
  158. /*
  159. * Actions
  160. */
  161. if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
  162. if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
  163. $parameters=array();
  164. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  165. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  166. if (empty($reshook))
  167. {
  168. // Purge search criteria
  169. if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') ||GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
  170. {
  171. $search_label='';
  172. $search_type_template='';
  173. $search_lang='';
  174. $search_fk_user='';
  175. $search_topic='';
  176. $toselect='';
  177. $search_array_options=array();
  178. }
  179. // Actions add or modify an entry into a dictionary
  180. if (GETPOST('actionadd','alpha') || GETPOST('actionmodify','alpha'))
  181. {
  182. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  183. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  184. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  185. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  186. // Check that all fields are filled
  187. $ok=1;
  188. foreach ($listfield as $f => $value)
  189. {
  190. // Not mandatory fields
  191. if ($value == 'joinfiles') continue;
  192. if ($value == 'content') continue;
  193. if ($value == 'content_lines') continue;
  194. if (GETPOST('actionmodify','alpha') && $value == 'topic') $_POST['topic']=$_POST['topic-'.$rowid];
  195. if ((! isset($_POST[$value]) || $_POST[$value]=='' || $_POST[$value]=='-1') && $value != 'lang' && $value != 'fk_user' && $value != 'position')
  196. {
  197. $ok=0;
  198. $fieldnamekey=$listfield[$f];
  199. // We take translate key of field
  200. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Code';
  201. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  202. if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
  203. if ($fieldnamekey == 'type_template') $fieldnamekey = 'TypeOfTemplate';
  204. if ($fieldnamekey == 'fk_user') $fieldnamekey = 'Owner';
  205. if ($fieldnamekey == 'private') $fieldnamekey = 'Private';
  206. if ($fieldnamekey == 'position') $fieldnamekey = 'Position';
  207. if ($fieldnamekey == 'topic') $fieldnamekey = 'Topic';
  208. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  209. }
  210. }
  211. // Si verif ok et action add, on ajoute la ligne
  212. if ($ok && GETPOST('actionadd'))
  213. {
  214. // Add new entry
  215. $sql = "INSERT INTO ".$tabname[$id]." (";
  216. // List of fields
  217. $sql.= $tabfieldinsert[$id];
  218. $sql.=",active)";
  219. $sql.= " VALUES(";
  220. // List of values
  221. $i=0;
  222. foreach ($listfieldinsert as $f => $value)
  223. {
  224. //var_dump($i.' - '.$listfieldvalue[$i].' - '.$_POST[$listfieldvalue[$i]].' - '.$value);
  225. $keycode=$listfieldvalue[$i];
  226. if ($value == 'lang') $keycode='langcode';
  227. if ($value == 'entity') $_POST[$keycode] = $conf->entity;
  228. if ($i) $sql.=",";
  229. if ($value == 'fk_user' && ! ($_POST[$keycode] > 0)) $_POST[$keycode]='';
  230. if ($value == 'private' && ! is_numeric($_POST[$keycode])) $_POST[$keycode]='0';
  231. if ($value == 'position' && ! is_numeric($_POST[$keycode])) $_POST[$keycode]='1';
  232. if ($_POST[$keycode] == '' && $keycode != 'langcode') $sql.="null"; // lang must be '' if not defined so the unique key that include lang will work
  233. elseif ($_POST[$keycode] == '0' && $keycode == 'langcode') $sql.="''"; // lang must be '' if not defined so the unique key that include lang will work
  234. else $sql.="'".$db->escape($_POST[$keycode])."'";
  235. $i++;
  236. }
  237. $sql.=",1)";
  238. dol_syslog("actionadd", LOG_DEBUG);
  239. $result = $db->query($sql);
  240. if ($result) // Add is ok
  241. {
  242. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  243. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  244. }
  245. else
  246. {
  247. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  248. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  249. }
  250. else {
  251. dol_print_error($db);
  252. }
  253. }
  254. }
  255. // Si verif ok et action modify, on modifie la ligne
  256. if ($ok && GETPOST('actionmodify'))
  257. {
  258. $rowidcol="rowid";
  259. // Modify entry
  260. $sql = "UPDATE ".$tabname[$id]." SET ";
  261. // Modifie valeur des champs
  262. $i = 0;
  263. foreach ($listfieldmodify as $field)
  264. {
  265. $keycode=$listfieldvalue[$i];
  266. if ($field == 'lang') $keycode='langcode';
  267. if ($field == 'fk_user' && ! ($_POST['fk_user'] > 0)) $_POST['fk_user']='';
  268. if ($field == 'topic') $_POST['topic']=$_POST['topic-'.$rowid];
  269. if ($field == 'joinfiles') $_POST['joinfiles']=$_POST['joinfiles-'.$rowid];
  270. if ($field == 'content') $_POST['content']=$_POST['content-'.$rowid];
  271. if ($field == 'content_lines') $_POST['content_lines']=$_POST['content_lines-'.$rowid];
  272. if ($field == 'entity') $_POST[$keycode] = $conf->entity;
  273. if ($i) $sql.=",";
  274. $sql.= $field."=";
  275. //print $keycode.' - '.$_POST[$keycode].'<br>';
  276. if ($_POST[$keycode] == '' || ($keycode != 'langcode' && $keycode != 'position' && $keycode != 'private' && empty($_POST[$keycode]))) $sql.="null"; // lang must be '' if not defined so the unique key that include lang will work
  277. elseif ($_POST[$keycode] == '0' && $keycode == 'langcode') $sql.="''"; // lang must be '' if not defined so the unique key that include lang will work
  278. elseif ($keycode == 'private') $sql.=((int) $_POST[$keycode]); // private must be 0 or 1
  279. elseif ($keycode == 'position') $sql.=((int) $_POST[$keycode]);
  280. else $sql.="'".$db->escape($_POST[$keycode])."'";
  281. $i++;
  282. }
  283. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  284. //print $sql;exit;
  285. dol_syslog("actionmodify", LOG_DEBUG);
  286. //print $sql;
  287. $resql = $db->query($sql);
  288. if ($resql)
  289. {
  290. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  291. }
  292. else
  293. {
  294. setEventMessages($db->error(), null, 'errors');
  295. }
  296. }
  297. }
  298. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  299. {
  300. $rowidcol="rowid";
  301. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  302. dol_syslog("delete", LOG_DEBUG);
  303. $result = $db->query($sql);
  304. if (! $result)
  305. {
  306. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  307. {
  308. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  309. }
  310. else
  311. {
  312. dol_print_error($db);
  313. }
  314. }
  315. }
  316. // activate
  317. if ($action == $acts[0])
  318. {
  319. $rowidcol="rowid";
  320. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  321. $result = $db->query($sql);
  322. if (!$result)
  323. {
  324. dol_print_error($db);
  325. }
  326. }
  327. // disable
  328. if ($action == $acts[1])
  329. {
  330. $rowidcol="rowid";
  331. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  332. $result = $db->query($sql);
  333. if (!$result)
  334. {
  335. dol_print_error($db);
  336. }
  337. }
  338. }
  339. /*
  340. * View
  341. */
  342. $form = new Form($db);
  343. $formadmin=new FormAdmin($db);
  344. llxHeader();
  345. $titre=$langs->trans("EMailsSetup");
  346. $linkback='';
  347. $titlepicto='title_setup';
  348. print load_fiche_titre($titre,$linkback,$titlepicto);
  349. $head = email_admin_prepare_head();
  350. dol_fiche_head($head, 'templates', '', -1);
  351. // Confirmation de la suppression de la ligne
  352. if ($action == 'delete')
  353. {
  354. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
  355. }
  356. //var_dump($elementList);
  357. $sql="SELECT rowid as rowid, label, type_template, lang, fk_user, private, position, topic, joinfiles, content_lines, content, enabled, active";
  358. $sql.=" FROM ".MAIN_DB_PREFIX."c_email_templates";
  359. $sql.=" WHERE entity IN (".getEntity('email_template').")";
  360. if (! $user->admin)
  361. {
  362. $sql.=" AND (private = 0 OR (private = 1 AND fk_user = ".$user->id."))"; // Show only public and private to me
  363. $sql.=" AND (active = 1 OR fk_user = ".$user->id.")"; // Show only active or owned by me
  364. }
  365. if (empty($conf->global->MAIN_MULTILANGS))
  366. {
  367. $sql.= " AND (lang = '".$langs->defaultlang."' OR lang IS NULL OR lang = '')";
  368. }
  369. if ($search_label) $sql.=natural_search('label', $search_label);
  370. if ($search_type_template != '' && $search_type_template != '-1') $sql.=natural_search('type_template', $search_type_template);
  371. if ($search_lang) $sql.=natural_search('lang', $search_lang);
  372. if ($search_fk_user != '' && $search_fk_user != '-1') $sql.=natural_search('fk_user', $search_fk_user, 2);
  373. if ($search_topic) $sql.=natural_search('topic', $search_topic);
  374. // If sort order is "country", we use country_code instead
  375. if ($sortfield == 'country') $sortfield='country_code';
  376. $sql.=$db->order($sortfield,$sortorder);
  377. $sql.=$db->plimit($listlimit+1,$offset);
  378. //print $sql;
  379. $fieldlist=explode(',',$tabfield[$id]);
  380. // Form to add a new line
  381. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  382. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  383. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  384. print '<div class="div-table-responsive-no-min">';
  385. print '<table class="noborder" width="100%">';
  386. // Line to enter new values (title)
  387. print '<tr class="liste_titre">';
  388. foreach ($fieldlist as $field => $value)
  389. {
  390. // Determine le nom du champ par rapport aux noms possibles
  391. // dans les dictionnaires de donnees
  392. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  393. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  394. $align="left";
  395. if ($fieldlist[$field]=='fk_user') { $valuetoshow=$langs->trans("Owner");}
  396. if ($fieldlist[$field]=='lang') { $valuetoshow=(empty($conf->global->MAIN_MULTILANGS) ? '&nbsp;' : $langs->trans("Language")); }
  397. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  398. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  399. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Code"); }
  400. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  401. if ($fieldlist[$field]=='private') { $align='center'; }
  402. if ($fieldlist[$field]=='position') { $align='center'; }
  403. if ($fieldlist[$field]=='topic') { $valuetoshow=''; }
  404. if ($fieldlist[$field]=='joinfiles') { $valuetoshow=''; }
  405. if ($fieldlist[$field]=='content') { $valuetoshow=''; }
  406. if ($fieldlist[$field]=='content_lines') { $valuetoshow=''; }
  407. if ($valuetoshow != '')
  408. {
  409. print '<td align="'.$align.'">';
  410. if (! empty($tabhelp[$id][$value]) && preg_match('/^http(s*):/i',$tabhelp[$id][$value])) print '<a href="'.$tabhelp[$id][$value].'" target="_blank">'.$valuetoshow.' '.img_help(1,$valuetoshow).'</a>';
  411. else if (! empty($tabhelp[$id][$value]))
  412. {
  413. if (in_array($value, array('topic'))) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
  414. else print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
  415. }
  416. else print $valuetoshow;
  417. print '</td>';
  418. }
  419. }
  420. print '<td>';
  421. print '<input type="hidden" name="id" value="' . $id . '">';
  422. print '</td>';
  423. print '</tr>';
  424. $obj = new stdClass();
  425. // If data was already input, we define them in obj to populate input fields.
  426. if (GETPOST('actionadd'))
  427. {
  428. foreach ($fieldlist as $key => $val) {
  429. if (GETPOST($val) != '')
  430. $obj->$val = GETPOST($val);
  431. }
  432. }
  433. $tmpaction = 'create';
  434. $parameters = array(
  435. 'fieldlist' => $fieldlist,
  436. 'tabname' => $tabname[$id]
  437. );
  438. $reshook = $hookmanager->executeHooks('createEmailTemplateFieldlist', $parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  439. $error = $hookmanager->error;
  440. $errors = $hookmanager->errors;
  441. // Line to enter new values (input fields)
  442. print "<tr " . $bcnd[$var] . ">";
  443. if (empty($reshook))
  444. {
  445. if ($action == 'edit') {
  446. fieldList($fieldlist, $obj, $tabname[$id], 'hide');
  447. } else {
  448. fieldList($fieldlist, $obj, $tabname[$id], 'add');
  449. }
  450. }
  451. print '<td align="right">';
  452. print '</td>';
  453. print "</tr>";
  454. // Show fields for topic, join files and body
  455. $fieldsforcontent = array('topic', 'joinfiles', 'content');
  456. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) { $fieldsforcontent = array('content','content_lines'); }
  457. foreach ($fieldsforcontent as $tmpfieldlist)
  458. {
  459. print '<tr class="impair nodrag nodrop nohover"><td colspan="6" class="nobottom">';
  460. // Label
  461. if ($tmpfieldlist == 'topic')
  462. {
  463. print '<strong>' . $form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist) . '</strong> ';
  464. }
  465. if ($tmpfieldlist == 'joinfiles')
  466. {
  467. print '<strong>' . $form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist) . '</strong> ';
  468. }
  469. if ($tmpfieldlist == 'content')
  470. print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist);
  471. if ($tmpfieldlist == 'content_lines')
  472. print $form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist) . '<br>';
  473. // Input field
  474. if ($tmpfieldlist == 'topic') {
  475. print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'" value="' . (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '') . '">';
  476. }
  477. else if ($tmpfieldlist == 'joinfiles') {
  478. print '<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.'" value="' . (isset($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '1') . '">';
  479. }
  480. else
  481. {
  482. if ($context != 'hide') {
  483. // print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
  484. $okforextended = true;
  485. if (empty($conf->global->FCKEDITOR_ENABLE_MAIL))
  486. $okforextended = false;
  487. $doleditor = new DolEditor($tmpfieldlist, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 120, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_4, '90%');
  488. print $doleditor->Create(1);
  489. }
  490. else
  491. print '&nbsp;';
  492. }
  493. print '</td>';
  494. if ($tmpfieldlist == 'topic') {
  495. print '<td align="center" rowspan="' . (count($fieldsforcontent)) . '">';
  496. if ($action != 'edit') {
  497. print '<input type="submit" class="button" name="actionadd" value="' . $langs->trans("Add") . '">';
  498. }
  499. print '</td>';
  500. }
  501. // else print '<td></td>';
  502. print '</tr>';
  503. }
  504. $colspan=count($fieldlist)+1;
  505. //print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  506. print '</table>';
  507. print '</div>';
  508. print '</form>';
  509. print '<br>';
  510. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  511. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  512. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  513. print '<div class="div-table-responsive-no-min">';
  514. print '<table class="noborder" width="100%">';
  515. // List of available record in database
  516. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  517. $resql=$db->query($sql);
  518. if ($resql)
  519. {
  520. $num = $db->num_rows($resql);
  521. $i = 0;
  522. $param = '&id='.$id;
  523. if ($search_label) $param.= '&search_label='.urlencode($search_label);
  524. if ($search_lang > 0) $param.= '&search_lang='.urlencode($search_lang);
  525. if ($search_type_template > 0) $param.= '&search_type_template='.urlencode($search_type_template);
  526. if ($search_fk_user > 0) $param.= '&search_fk_user='.urlencode($search_fk_user);
  527. if ($search_topic) $param.= '&search_topic='.urlencode($search_topic);
  528. $paramwithsearch = $param;
  529. if ($sortorder) $paramwithsearch.= '&sortorder='.urlencode($sortorder);
  530. if ($sortfield) $paramwithsearch.= '&sortfield='.urlencode($sortfield);
  531. if (GETPOST('from','alpha')) $paramwithsearch.= '&from='.urlencode(GETPOST('from','alpha'));
  532. // There is several pages
  533. if ($num > $listlimit)
  534. {
  535. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  536. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  537. print '</td></tr>';
  538. }
  539. // Title line with search boxes
  540. print '<tr class="liste_titre">';
  541. $filterfound=0;
  542. foreach ($fieldlist as $field => $value)
  543. {
  544. if ($value == 'label') print '<td class="liste_titre"><input type="text" name="search_label" class="maxwidth100" value="'.dol_escape_htmltag($search_label).'"></td>';
  545. elseif ($value == 'lang')
  546. {
  547. print '<td class="liste_titre">';
  548. print $formadmin->select_language($search_lang, 'search_lang', 0, null, 1, 0, 0, 'maxwidth100');
  549. print '</td>';
  550. }
  551. elseif ($value == 'fk_user')
  552. {
  553. print '<td class="liste_titre">';
  554. $restrictid=array();
  555. if (! $user->admin) $restrictid=array($user->id);
  556. //var_dump($restrictid);
  557. print $form->select_dolusers($search_fk_user, 'search_fk_user', 1, null, 0, 'hierarchyme', null, 0, 0, 1, '', 0, '', 'maxwidth100');
  558. print '</td>';
  559. }
  560. elseif ($value == 'topic') print '<td class="liste_titre"><input type="text" name="search_topic" value="'.dol_escape_htmltag($search_topic).'"></td>';
  561. elseif ($value == 'type_template')
  562. {
  563. print '<td class="liste_titre">'.$form->selectarray('search_type_template', $elementList, $search_type_template, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100 maxwidth100onsmartphone').'</td>';
  564. }
  565. elseif (! in_array($value, array('content', 'content_lines'))) print '<td class="liste_titre"></td>';
  566. }
  567. if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) print '<td class="liste_titre"></td>';
  568. // Action column
  569. print '<td class="liste_titre" align="right" width="64">';
  570. $searchpicto=$form->showFilterButtons();
  571. print $searchpicto;
  572. print '</td>';
  573. print '</tr>';
  574. // Title of lines
  575. print '<tr class="liste_titre">';
  576. foreach ($fieldlist as $field => $value)
  577. {
  578. // Determine le nom du champ par rapport aux noms possibles
  579. // dans les dictionnaires de donnees
  580. $showfield=1; // By defaut
  581. $align="left";
  582. $sortable=1;
  583. $valuetoshow='';
  584. $forcenowrap=1;
  585. /*
  586. $tmparray=getLabelOfField($fieldlist[$field]);
  587. $showfield=$tmp['showfield'];
  588. $valuetoshow=$tmp['valuetoshow'];
  589. $align=$tmp['align'];
  590. $sortable=$tmp['sortable'];
  591. */
  592. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  593. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  594. if ($fieldlist[$field]=='fk_user') { $valuetoshow=$langs->trans("Owner"); }
  595. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  596. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  597. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Code"); }
  598. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  599. if ($fieldlist[$field]=='private') { $align='center'; }
  600. if ($fieldlist[$field]=='position') { $align='center'; }
  601. if ($fieldlist[$field]=='joinfiles') { $valuetoshow=$langs->trans("FilesAttachedToEmail"); $align='center'; $forcenowrap=0; }
  602. if ($fieldlist[$field]=='content') { $valuetoshow=$langs->trans("Content"); $showfield=0;}
  603. if ($fieldlist[$field]=='content_lines') { $valuetoshow=$langs->trans("ContentLines"); $showfield=0; }
  604. // Affiche nom du champ
  605. if ($showfield)
  606. {
  607. if (! empty($tabhelp[$id][$value]))
  608. {
  609. if (in_array($value, array('topic'))) $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, 'tooltip'.$value, $forcenowrap); // Tooltip on click
  610. else $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, '', $forcenowrap); // Tooltip on hover
  611. }
  612. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  613. }
  614. }
  615. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  616. print getTitleFieldOfList('');
  617. print '</tr>';
  618. if ($num)
  619. {
  620. // Lines with values
  621. while ($i < $num)
  622. {
  623. $obj = $db->fetch_object($resql);
  624. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  625. {
  626. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  627. $tmpaction='edit';
  628. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  629. $reshook=$hookmanager->executeHooks('editEmailTemplateFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  630. $error=$hookmanager->error; $errors=$hookmanager->errors;
  631. // Show fields
  632. if (empty($reshook)) fieldList($fieldlist,$obj,$tabname[$id],'edit');
  633. print '<td></td><td></td><td></td>';
  634. print '<td align="center">';
  635. print '<input type="hidden" name="page" value="'.$page.'">';
  636. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  637. print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  638. print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
  639. print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  640. print '</td>';
  641. $fieldsforcontent = array('topic', 'joinfiles', 'content');
  642. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  643. {
  644. $fieldsforcontent = array('topic', 'joinfiles', 'content', 'content_lines');
  645. }
  646. foreach ($fieldsforcontent as $tmpfieldlist)
  647. {
  648. $showfield = 1;
  649. $align = "left";
  650. $valuetoshow = $obj->{$tmpfieldlist};
  651. $class = 'tddict';
  652. // Show value for field
  653. if ($showfield) {
  654. // Show line for topic, joinfiles and content
  655. print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$rowid.' ">';
  656. print '<td colspan="8">';
  657. if ($tmpfieldlist == 'topic')
  658. {
  659. print '<strong>' . $form->textwithpicto($langs->trans("Topic"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist) . '</strong> ';
  660. print '<input type="text" class="flat minwidth500" name="'.$tmpfieldlist.'-'.$rowid.'" value="' . (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '') . '">';
  661. }
  662. if ($tmpfieldlist == 'joinfiles')
  663. {
  664. print '<strong>' . $form->textwithpicto($langs->trans("FilesAttachedToEmail"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist) . '</strong> ';
  665. print '<input type="text" class="flat maxwidth50" name="'.$tmpfieldlist.'-'.$rowid.'" value="' . (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : '') . '">';
  666. }
  667. if ($tmpfieldlist == 'content')
  668. {
  669. print $form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist) . '<br>';
  670. $okforextended = true;
  671. if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended = false;
  672. $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_6, '90%');
  673. print $doleditor->Create(1);
  674. }
  675. print '</td>';
  676. print '<td></td>';
  677. print '<td></td>';
  678. }
  679. }
  680. print "</tr>\n";
  681. }
  682. else
  683. {
  684. $keyforobj='type_template';
  685. if (! in_array($obj->$keyforobj, array_keys($elementList)))
  686. {
  687. $i++;
  688. 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)
  689. }
  690. // Test on 'enabled'
  691. if (! dol_eval($obj->enabled, 1))
  692. {
  693. $i++;
  694. continue; // Email template not qualified
  695. }
  696. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  697. $tmpaction = 'view';
  698. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  699. $reshook=$hookmanager->executeHooks('viewEmailTemplateFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  700. $error=$hookmanager->error; $errors=$hookmanager->errors;
  701. if (empty($reshook))
  702. {
  703. foreach ($fieldlist as $field => $value)
  704. {
  705. if (in_array($fieldlist[$field], array('content','content_lines'))) continue;
  706. $showfield=1;
  707. $align="left";
  708. $valuetoshow=$obj->{$fieldlist[$field]};
  709. if ($value == 'type_template')
  710. {
  711. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  712. }
  713. if ($value == 'lang' && $valuetoshow)
  714. {
  715. $valuetoshow = $valuetoshow.' - '.$langs->trans("Language_".$valuetoshow);
  716. }
  717. if ($value == 'fk_user')
  718. {
  719. if ($valuetoshow > 0)
  720. {
  721. $fuser=new User($db);
  722. $fuser->fetch($valuetoshow);
  723. $valuetoshow = $fuser->getNomUrl(1);
  724. }
  725. }
  726. if ($value == 'private')
  727. {
  728. $align="center";
  729. if ($valuetoshow) $valuetoshow=yn($valuetoshow);
  730. else $valuetoshow='';
  731. }
  732. if ($value == 'position')
  733. {
  734. $align="center";
  735. }
  736. if ($value == 'joinfiles')
  737. {
  738. $align="center";
  739. if ($valuetoshow) $valuetoshow=1;
  740. else $valuetoshow='';
  741. }
  742. $class='tddict';
  743. // Show value for field
  744. if ($showfield)
  745. {
  746. print '<!-- '.$fieldlist[$field].' -->';
  747. print '<td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  748. }
  749. }
  750. }
  751. // Can an entry be erased or disabled ?
  752. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  753. if (! $user->admin && $obj->fk_user != $user->id)
  754. {
  755. $iserasable=0;
  756. $canbedisabled=0;
  757. $canbemodified=0;
  758. }
  759. $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):'');
  760. if ($param) $url .= '&'.$param;
  761. $url.='&';
  762. // Status / Active
  763. print '<td align="center" class="nowrap">';
  764. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  765. print "</td>";
  766. // Modify link / Delete link
  767. print '<td class="center nowraponall" width="64">';
  768. if ($canbemodified) print '<a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a>';
  769. if ($iserasable)
  770. {
  771. print ' &nbsp; <a href="'.$url.'action=delete">'.img_delete().'</a>';
  772. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  773. }
  774. print '</td>';
  775. /*
  776. $fieldsforcontent = array('content');
  777. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  778. {
  779. $fieldsforcontent = array('content', 'content_lines');
  780. }
  781. foreach ($fieldsforcontent as $tmpfieldlist)
  782. {
  783. $showfield = 1;
  784. $align = "left";
  785. $valuetoshow = $obj->{$tmpfieldlist};
  786. $class = 'tddict';
  787. // Show value for field
  788. if ($showfield) {
  789. print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$i.' "><td colspan="5">'; // To create an artificial CR for the current tr we are on
  790. $okforextended = true;
  791. if (empty($conf->global->FCKEDITOR_ENABLE_MAIL))
  792. $okforextended = false;
  793. $doleditor = new DolEditor($tmpfieldlist.'-'.$i, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_6, '90%', 1);
  794. print $doleditor->Create(1);
  795. print '</td>';
  796. print '<td></td><td></td><td></td>';
  797. }
  798. }*/
  799. print "</tr>\n";
  800. }
  801. $i++;
  802. }
  803. }
  804. }
  805. else {
  806. dol_print_error($db);
  807. }
  808. print '</table>';
  809. print '</div>';
  810. print '</form>';
  811. dol_fiche_end();
  812. // End of page
  813. llxFooter();
  814. $db->close();
  815. /**
  816. * Show fields in insert/edit mode
  817. *
  818. * @param array $fieldlist Array of fields
  819. * @param Object $obj If we show a particular record, obj is filled with record fields
  820. * @param string $tabname Name of SQL table
  821. * @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
  822. * @return void
  823. */
  824. function fieldList($fieldlist, $obj='', $tabname='', $context='')
  825. {
  826. global $conf, $langs, $user, $db;
  827. global $form;
  828. global $region_id;
  829. global $elementList,$sourceList,$localtax_typeList;
  830. global $bc;
  831. $formadmin = new FormAdmin($db);
  832. $formcompany = new FormCompany($db);
  833. foreach ($fieldlist as $field => $value)
  834. {
  835. if ($fieldlist[$field] == 'fk_user')
  836. {
  837. print '<td>';
  838. if ($user->admin)
  839. {
  840. print $form->select_dolusers($obj->{$fieldlist[$field]}, 'fk_user', 1, null, 0, '', null, 0, 0, 1, '', 0, '', 'maxwidth200');
  841. }
  842. else
  843. {
  844. if ($context == 'add') // I am not admin and we show the add form
  845. {
  846. print $user->getNomUrl(1); // Me
  847. $forcedvalue=$user->id;
  848. }
  849. else
  850. {
  851. if ($obj && ! empty($obj->{$fieldlist[$field]}) && $obj->{$fieldlist[$field]} > 0)
  852. {
  853. $fuser=new User($db);
  854. $fuser->fetch($obj->{$fieldlist[$field]});
  855. print $fuser->getNomUrl(1);
  856. $forcedvalue=$fuser->id;
  857. }
  858. else
  859. {
  860. $forcedvalue=$obj->{$fieldlist[$field]};
  861. }
  862. }
  863. $keyname=$fieldlist[$field];
  864. print '<input type="hidden" value="'.$forcedvalue.'" name="'.$keyname.'">';
  865. }
  866. print '</td>';
  867. }
  868. elseif ($fieldlist[$field] == 'lang')
  869. {
  870. print '<td>';
  871. if (! empty($conf->global->MAIN_MULTILANGS))
  872. {
  873. $selectedlang = GETPOSTISSET('langcode')?GETPOST('langcode', 'aZ09'):$langs->defaultlang;
  874. if ($context == 'edit') $selectedlang = $obj->{$fieldlist[$field]};
  875. print $formadmin->select_language($selectedlang, 'langcode', 0, null, 1, 0, 0, 'maxwidth150');
  876. }
  877. else
  878. {
  879. if (! empty($obj->{$fieldlist[$field]}))
  880. {
  881. print $obj->{$fieldlist[$field]}.' - '.$langs->trans('Language_'.$obj->{$fieldlist[$field]});
  882. }
  883. $keyname=$fieldlist[$field];
  884. if ($keyname == 'lang') $keyname='langcode'; // Avoid conflict with lang param
  885. print '<input type="hidden" value="'.$obj->{$fieldlist[$field]}.'" name="'.$keyname.'">';
  886. }
  887. print '</td>';
  888. }
  889. // Le type de template
  890. elseif ($fieldlist[$field] == 'type_template')
  891. {
  892. print '<td>';
  893. if ($context == 'edit' && ! empty($obj->{$fieldlist[$field]}) && ! in_array($obj->{$fieldlist[$field]}, array_keys($elementList)))
  894. {
  895. // Current tempalte type is an unknown type, so we must keep it as it is.
  896. print '<input type="hidden" name="type_template" value="'.$obj->{$fieldlist[$field]}.'">';
  897. print $obj->{$fieldlist[$field]};
  898. }
  899. else
  900. {
  901. print $form->selectarray('type_template', $elementList, (! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 1, 0, 0, '', 0, 0, 0, '', 'maxwidth150 maxwidth100onsmartphone');
  902. }
  903. print '</td>';
  904. }
  905. elseif ($context == 'add' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
  906. elseif ($context == 'edit' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
  907. elseif ($context == 'hide' && in_array($fieldlist[$field], array('topic', 'joinfiles', 'content', 'content_lines'))) continue;
  908. else
  909. {
  910. $size=''; $class=''; $classtd='';
  911. if ($fieldlist[$field]=='code') $class='maxwidth100';
  912. if ($fieldlist[$field]=='label') $class='maxwidth100';
  913. if ($fieldlist[$field]=='private') { $class='maxwidth50'; $classtd='center'; }
  914. if ($fieldlist[$field]=='position') { $class='maxwidth50'; $classtd='center'; }
  915. if ($fieldlist[$field]=='libelle') $class='quatrevingtpercent';
  916. if ($fieldlist[$field]=='topic') $class='quatrevingtpercent';
  917. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  918. print '<td'.($classtd?' class="'.$classtd.'"':'').'>';
  919. if ($fieldlist[$field]=='private')
  920. {
  921. if (empty($user->admin))
  922. {
  923. print $form->selectyesno($fieldlist[$field], '1', 1);
  924. }
  925. else
  926. {
  927. //print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="1" name="'.$fieldlist[$field].'">';
  928. print $form->selectyesno($fieldlist[$field], (isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''), 1);
  929. }
  930. }
  931. else
  932. {
  933. print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  934. }
  935. print '</td>';
  936. }
  937. }
  938. }