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