mails_templates.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 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@capnetworks.com>
  6. * Copyright (C) 2010-2016 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2011-2017 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. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/admin/mails_templates.php
  30. * \ingroup setup
  31. * \brief Page to administer data tables
  32. */
  33. require '../main.inc.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  40. if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  41. $langs->load("errors");
  42. $langs->load("admin");
  43. $langs->load("main");
  44. $langs->load("mails");
  45. $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view';
  46. $confirm=GETPOST('confirm','alpha');
  47. $id=GETPOST('id','int');
  48. $rowid=GETPOST('rowid','alpha');
  49. $allowed=$user->admin;
  50. if (! $allowed) accessforbidden();
  51. $acts[0] = "activate";
  52. $acts[1] = "disable";
  53. $actl[0] = img_picto($langs->trans("Disabled"),'switch_off');
  54. $actl[1] = img_picto($langs->trans("Activated"),'switch_on');
  55. $listoffset=GETPOST('listoffset');
  56. $listlimit=GETPOST('listlimit')>0?GETPOST('listlimit'):1000;
  57. $active = 1;
  58. $sortfield = GETPOST("sortfield",'alpha');
  59. $sortorder = GETPOST("sortorder",'alpha');
  60. $page = GETPOST("page",'int');
  61. if ($page == -1) { $page = 0 ; }
  62. $offset = $listlimit * $page ;
  63. $pageprev = $page - 1;
  64. $pagenext = $page + 1;
  65. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  66. $hookmanager->initHooks(array('emailtemplates'));
  67. // Name of SQL tables of dictionaries
  68. $tabname=array();
  69. $tabname[25]= MAIN_DB_PREFIX."c_email_templates";
  70. // Requests to extract data
  71. $tabsql=array();
  72. $tabsql[25]= "SELECT rowid as rowid, label, type_template, private, position, topic, content_lines, content, active FROM ".MAIN_DB_PREFIX."c_email_templates WHERE entity IN (".getEntity('email_template',1).")";
  73. // Criteria to sort dictionaries
  74. $tabsqlsort=array();
  75. $tabsqlsort[25]="label ASC";
  76. // Nom des champs en resultat de select pour affichage du dictionnaire
  77. $tabfield=array();
  78. $tabfield[25]= "label,type_template,private,position,topic,content";
  79. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfield[25].=',content_lines';
  80. // Nom des champs d'edition pour modification d'un enregistrement
  81. $tabfieldvalue=array();
  82. $tabfieldvalue[25]= "label,type_template,private,position,topic,content";
  83. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldvalue[25].=',content_lines';
  84. // Nom des champs dans la table pour insertion d'un enregistrement
  85. $tabfieldinsert=array();
  86. $tabfieldinsert[25]= "label,type_template,private,position,topic,content";
  87. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) $tabfieldinsert[25].=',content_lines';
  88. $tabfieldinsert[25].=',entity'; // Must be at end because not into other arrays
  89. // Nom du rowid si le champ n'est pas de type autoincrement
  90. // Example: "" if id field is "rowid" and has autoincrement on
  91. // "nameoffield" if id field is not "rowid" or has not autoincrement on
  92. $tabrowid=array();
  93. $tabrowid[25]= "";
  94. // Condition to show dictionary in setup page
  95. $tabcond=array();
  96. $tabcond[25]= true;
  97. // List of help for fields
  98. // Set MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES to allow edit of template for lines
  99. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  100. $formmail=new FormMail($db);
  101. if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  102. {
  103. $tmp=FormMail::getAvailableSubstitKey('formemail');
  104. $tmp['__(AnyTransKey)__']='__(AnyTransKey)__';
  105. $helpsubstit = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
  106. $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
  107. }
  108. else
  109. {
  110. $tmp=FormMail::getAvailableSubstitKey('formemailwithlines');
  111. $tmp['__(AnyTransKey)__']='__(AnyTransKey)__';
  112. $helpsubstit = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
  113. $tmp=FormMail::getAvailableSubstitKey('formemailforlines');
  114. $helpsubstitforlines = $langs->trans("AvailableVariables").':<br>'.implode('<br>', $tmp);
  115. }
  116. $tabhelp=array();
  117. $tabhelp[25] = array('topic'=>$helpsubstit,'content'=>$helpsubstit,'content_lines'=>$helpsubstitforlines,'type_template'=>$langs->trans("TemplateForElement"),'private'=>$langs->trans("TemplateIsVisibleByOwnerOnly"), 'position'=>$langs->trans("PositionIntoComboList"));
  118. // List of check for fields (NOT USED YET)
  119. $tabfieldcheck=array();
  120. $tabfieldcheck[25] = array();
  121. // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact")
  122. $elementList = array();
  123. $sourceList=array();
  124. // We save list of template email Dolibarr can manage. This list can found by a grep into code on "->param['models']"
  125. $elementList = array();
  126. if ($conf->propal->enabled) $elementList['propal_send']=$langs->trans('MailToSendProposal');
  127. if ($conf->commande->enabled) $elementList['order_send']=$langs->trans('MailToSendOrder');
  128. if ($conf->facture->enabled) $elementList['facture_send']=$langs->trans('MailToSendInvoice');
  129. if ($conf->expedition->enabled) $elementList['shipping_send']=$langs->trans('MailToSendShipment');
  130. if ($conf->ficheinter->enabled) $elementList['fichinter_send']=$langs->trans('MailToSendIntervention');
  131. if ($conf->supplier_proposal->enabled) $elementList['supplier_proposal_send']=$langs->trans('MailToSendSupplierRequestForQuotation');
  132. if ($conf->fournisseur->enabled) $elementList['order_supplier_send']=$langs->trans('MailToSendSupplierOrder');
  133. if ($conf->fournisseur->enabled) $elementList['invoice_supplier_send']=$langs->trans('MailToSendSupplierInvoice');
  134. if ($conf->societe->enabled) $elementList['thirdparty']=$langs->trans('MailToThirdparty');
  135. if ($conf->contrat->enabled) $elementList['contract']=$langs->trans('MailToSendContract');
  136. $parameters=array('elementList'=>$elementList);
  137. $reshook=$hookmanager->executeHooks('emailElementlist',$parameters); // Note that $action and $object may have been modified by some hooks
  138. if ($reshook == 0) {
  139. foreach ($hookmanager->resArray as $item => $value) {
  140. $elementList[$item] = $value;
  141. }
  142. }
  143. $id = 25;
  144. /*
  145. * Actions
  146. */
  147. if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x'))
  148. {
  149. //$search_country_id = '';
  150. }
  151. // Actions add or modify an entry into a dictionary
  152. if (GETPOST('actionadd') || GETPOST('actionmodify'))
  153. {
  154. $listfield=explode(',', str_replace(' ', '',$tabfield[$id]));
  155. $listfieldinsert=explode(',',$tabfieldinsert[$id]);
  156. $listfieldmodify=explode(',',$tabfieldinsert[$id]);
  157. $listfieldvalue=explode(',',$tabfieldvalue[$id]);
  158. // Check that all fields are filled
  159. $ok=1;
  160. foreach ($listfield as $f => $value)
  161. {
  162. if ($value == 'content') continue;
  163. if ($value == 'content_lines') continue;
  164. if ($value == 'content') $value='content-'.$rowid;
  165. if ($value == 'content_lines') $value='content_lines-'.$rowid;
  166. if (! isset($_POST[$value]) || $_POST[$value]=='')
  167. {
  168. $ok=0;
  169. $fieldnamekey=$listfield[$f];
  170. // We take translate key of field
  171. if ($fieldnamekey == 'libelle' || ($fieldnamekey == 'label')) $fieldnamekey='Label';
  172. if ($fieldnamekey == 'libelle_facture') $fieldnamekey = 'LabelOnDocuments';
  173. if ($fieldnamekey == 'code') $fieldnamekey = 'Code';
  174. if ($fieldnamekey == 'note') $fieldnamekey = 'Note';
  175. if ($fieldnamekey == 'type') $fieldnamekey = 'Type';
  176. setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors');
  177. }
  178. }
  179. // Si verif ok et action add, on ajoute la ligne
  180. if ($ok && GETPOST('actionadd'))
  181. {
  182. if ($tabrowid[$id])
  183. {
  184. // Recupere id libre pour insertion
  185. $newid=0;
  186. $sql = "SELECT max(".$tabrowid[$id].") newid from ".$tabname[$id];
  187. $result = $db->query($sql);
  188. if ($result)
  189. {
  190. $obj = $db->fetch_object($result);
  191. $newid=($obj->newid + 1);
  192. } else {
  193. dol_print_error($db);
  194. }
  195. }
  196. // Add new entry
  197. $sql = "INSERT INTO ".$tabname[$id]." (";
  198. // List of fields
  199. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  200. $sql.= $tabrowid[$id].",";
  201. $sql.= $tabfieldinsert[$id];
  202. $sql.=",active)";
  203. $sql.= " VALUES(";
  204. // List of values
  205. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldinsert))
  206. $sql.= $newid.",";
  207. $i=0;
  208. foreach ($listfieldinsert as $f => $value)
  209. {
  210. //var_dump($i.' - '.$listfieldvalue[$i].' - '.$_POST[$listfieldvalue[$i]].' - '.$value);
  211. if ($value == 'entity') {
  212. $_POST[$listfieldvalue[$i]] = $conf->entity;
  213. }
  214. if ($i) $sql.=",";
  215. if ($value == 'private' && ! is_numeric($_POST[$listfieldvalue[$i]])) $_POST[$listfieldvalue[$i]]='0';
  216. if ($value == 'position' && ! is_numeric($_POST[$listfieldvalue[$i]])) $_POST[$listfieldvalue[$i]]='1';
  217. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null"; // For vat, we want/accept code = ''
  218. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  219. $i++;
  220. }
  221. $sql.=",1)";
  222. dol_syslog("actionadd", LOG_DEBUG);
  223. $result = $db->query($sql);
  224. if ($result) // Add is ok
  225. {
  226. setEventMessages($langs->transnoentities("RecordSaved"), null, 'mesgs');
  227. $_POST=array('id'=>$id); // Clean $_POST array, we keep only
  228. }
  229. else
  230. {
  231. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  232. setEventMessages($langs->transnoentities("ErrorRecordAlreadyExists"), null, 'errors');
  233. }
  234. else {
  235. dol_print_error($db);
  236. }
  237. }
  238. }
  239. // Si verif ok et action modify, on modifie la ligne
  240. if ($ok && GETPOST('actionmodify'))
  241. {
  242. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  243. else { $rowidcol="rowid"; }
  244. // Modify entry
  245. $sql = "UPDATE ".$tabname[$id]." SET ";
  246. // Modifie valeur des champs
  247. if ($tabrowid[$id] && ! in_array($tabrowid[$id],$listfieldmodify))
  248. {
  249. $sql.= $tabrowid[$id]."=";
  250. $sql.= "'".$db->escape($rowid)."', ";
  251. }
  252. $i = 0;
  253. foreach ($listfieldmodify as $field)
  254. {
  255. if ($field == 'content') $_POST['content']=$_POST['content-'.$rowid];
  256. if ($field == 'content_lines') $_POST['content_lines']=$_POST['content_lines-'.$rowid];
  257. if ($field == 'entity') {
  258. $_POST[$listfieldvalue[$i]] = $conf->entity;
  259. }
  260. if ($i) $sql.=",";
  261. $sql.= $field."=";
  262. if ($_POST[$listfieldvalue[$i]] == '') $sql.="null"; // For vat, we want/accept code = ''
  263. else $sql.="'".$db->escape($_POST[$listfieldvalue[$i]])."'";
  264. $i++;
  265. }
  266. $sql.= " WHERE ".$rowidcol." = '".$rowid."'";
  267. dol_syslog("actionmodify", LOG_DEBUG);
  268. //print $sql;
  269. $resql = $db->query($sql);
  270. if (! $resql)
  271. {
  272. setEventMessages($db->error(), null, 'errors');
  273. }
  274. }
  275. }
  276. if ($action == 'confirm_delete' && $confirm == 'yes') // delete
  277. {
  278. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  279. else { $rowidcol="rowid"; }
  280. $sql = "DELETE from ".$tabname[$id]." WHERE ".$rowidcol."='".$rowid."'";
  281. dol_syslog("delete", LOG_DEBUG);
  282. $result = $db->query($sql);
  283. if (! $result)
  284. {
  285. if ($db->errno() == 'DB_ERROR_CHILD_EXISTS')
  286. {
  287. setEventMessages($langs->transnoentities("ErrorRecordIsUsedByChild"), null, 'errors');
  288. }
  289. else
  290. {
  291. dol_print_error($db);
  292. }
  293. }
  294. }
  295. // activate
  296. if ($action == $acts[0])
  297. {
  298. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  299. else { $rowidcol="rowid"; }
  300. if ($rowid) {
  301. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'";
  302. }
  303. elseif ($_GET["code"]) {
  304. $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'";
  305. }
  306. $result = $db->query($sql);
  307. if (!$result)
  308. {
  309. dol_print_error($db);
  310. }
  311. }
  312. // disable
  313. if ($action == $acts[1])
  314. {
  315. if ($tabrowid[$id]) { $rowidcol=$tabrowid[$id]; }
  316. else { $rowidcol="rowid"; }
  317. if ($rowid) {
  318. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'";
  319. }
  320. elseif ($_GET["code"]) {
  321. $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'";
  322. }
  323. $result = $db->query($sql);
  324. if (!$result)
  325. {
  326. dol_print_error($db);
  327. }
  328. }
  329. /*
  330. * View
  331. */
  332. $form = new Form($db);
  333. $formadmin=new FormAdmin($db);
  334. llxHeader();
  335. $titre=$langs->trans("EMailsSetup");
  336. $linkback='';
  337. $titlepicto='title_setup';
  338. print load_fiche_titre($titre,$linkback,$titlepicto);
  339. $h = 0;
  340. $head[$h][0] = DOL_URL_ROOT."/admin/mails.php";
  341. $head[$h][1] = $langs->trans("OutGoingEmailSetup");
  342. $head[$h][2] = 'common';
  343. $h++;
  344. $head[$h][0] = DOL_URL_ROOT."/admin/mails_templates.php";
  345. $head[$h][1] = $langs->trans("DictionaryEMailTemplates");
  346. $head[$h][2] = 'templates';
  347. $h++;
  348. dol_fiche_head($head, 'templates', '', -1);
  349. // Confirmation de la suppression de la ligne
  350. if ($action == 'delete')
  351. {
  352. print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$_GET["code"].'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1);
  353. }
  354. //var_dump($elementList);
  355. // Complete requete recherche valeurs avec critere de tri
  356. $sql=$tabsql[$id];
  357. if ($search_country_id > 0)
  358. {
  359. if (preg_match('/ WHERE /',$sql)) $sql.= " AND ";
  360. else $sql.=" WHERE ";
  361. $sql.= " c.rowid = ".$search_country_id;
  362. }
  363. if ($sortfield)
  364. {
  365. // If sort order is "country", we use country_code instead
  366. if ($sortfield == 'country') $sortfield='country_code';
  367. $sql.= " ORDER BY ".$sortfield;
  368. if ($sortorder)
  369. {
  370. $sql.=" ".strtoupper($sortorder);
  371. }
  372. $sql.=", ";
  373. // Clear the required sort criteria for the tabsqlsort to be able to force it with selected value
  374. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.' '.$sortorder.',/i','',$tabsqlsort[$id]);
  375. $tabsqlsort[$id]=preg_replace('/([a-z]+\.)?'.$sortfield.',/i','',$tabsqlsort[$id]);
  376. }
  377. else {
  378. $sql.=" ORDER BY ";
  379. }
  380. $sql.=$tabsqlsort[$id];
  381. $sql.=$db->plimit($listlimit+1,$offset);
  382. //print $sql;
  383. $fieldlist=explode(',',$tabfield[$id]);
  384. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">';
  385. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  386. print '<input type="hidden" name="from" value="'.dol_escape_htmltag(GETPOST('from','alpha')).'">';
  387. print '<table class="noborder" width="100%">';
  388. // Form to add a new line
  389. $alabelisused=0;
  390. $var=false;
  391. $fieldlist=explode(',',$tabfield[$id]);
  392. if ($action != 'edit')
  393. {
  394. // Line for title
  395. print '<tr class="liste_titre">';
  396. foreach ($fieldlist as $field => $value)
  397. {
  398. // Determine le nom du champ par rapport aux noms possibles
  399. // dans les dictionnaires de donnees
  400. $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut
  401. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  402. $align="left";
  403. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  404. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  405. if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); }
  406. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label"); }
  407. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  408. if ($fieldlist[$field]=='content') { $valuetoshow=''; }
  409. if ($fieldlist[$field]=='content_lines') { $valuetoshow=''; }
  410. if ($valuetoshow != '')
  411. {
  412. print '<td align="'.$align.'">';
  413. 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>';
  414. else if (! empty($tabhelp[$id][$value]))
  415. {
  416. if (in_array($value, array('topic'))) print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2, $value); // Tooltip on click
  417. else print $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
  418. }
  419. else print $valuetoshow;
  420. print '</td>';
  421. }
  422. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') $alabelisused=1;
  423. }
  424. print '<td colspan="3">';
  425. print '<input type="hidden" name="id" value="'.$id.'">';
  426. print '</td>';
  427. print '</tr>';
  428. // Line to enter new values
  429. print "<tr ".$bcnd[$var].">";
  430. $obj = new stdClass();
  431. // If data was already input, we define them in obj to populate input fields.
  432. if (GETPOST('actionadd'))
  433. {
  434. foreach ($fieldlist as $key=>$val)
  435. {
  436. if (GETPOST($val) != '')
  437. $obj->$val=GETPOST($val);
  438. }
  439. }
  440. $tmpaction = 'create';
  441. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  442. $reshook=$hookmanager->executeHooks('createDictionaryFieldlist',$parameters, $obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  443. $error=$hookmanager->error; $errors=$hookmanager->errors;
  444. if (empty($reshook))
  445. {
  446. if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates' && $action == 'edit')
  447. {
  448. fieldList($fieldlist,$obj,$tabname[$id],'hide');
  449. }
  450. else
  451. {
  452. fieldList($fieldlist,$obj,$tabname[$id],'add');
  453. }
  454. }
  455. print '<td align="right" colspan="3">';
  456. print '</td>';
  457. print "</tr>";
  458. $fieldsforcontent = array('content');
  459. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  460. {
  461. $fieldsforcontent = array('content', 'content_lines');
  462. }
  463. foreach ($fieldsforcontent as $tmpfieldlist)
  464. {
  465. print '<tr class="impair nodrag nodrop nohover"><td colspan="5">';
  466. if ($tmpfieldlist == 'content') print '<strong>'.$form->textwithpicto($langs->trans("Content"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong><br>';
  467. if ($tmpfieldlist == 'content_lines') print '<strong>'.$form->textwithpicto($langs->trans("ContentForLines"), $tabhelp[$id][$tmpfieldlist], 1, 'help', '', 0, 2, $tmpfieldlist).'</strong><br>';
  468. if ($context != 'hide')
  469. {
  470. //print '<textarea cols="3" rows="'.ROWS_2.'" class="flat" name="'.$fieldlist[$field].'">'.(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'</textarea>';
  471. $okforextended=true;
  472. if (empty($conf->global->FCKEDITOR_ENABLE_MAIL)) $okforextended=false;
  473. $doleditor = new DolEditor($tmpfieldlist, (! empty($obj->{$tmpfieldlist})?$obj->{$tmpfieldlist}:''), '', 120, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_4, '90%');
  474. print $doleditor->Create(1);
  475. }
  476. else print '&nbsp;';
  477. print '</td>';
  478. if ($tmpfieldlist == 'content')
  479. {
  480. print '<td align="center" colspan="3" rowspan="'.(count($fieldsforcontent)).'">';
  481. if ($action != 'edit')
  482. {
  483. print '<input type="submit" class="button" name="actionadd" value="'.$langs->trans("Add").'">';
  484. }
  485. print '</td>';
  486. }
  487. //else print '<td></td>';
  488. print '</tr>';
  489. }
  490. $colspan=count($fieldlist)+1;
  491. print '<tr><td colspan="'.$colspan.'">&nbsp;</td></tr>'; // Keep &nbsp; to have a line with enough height
  492. }
  493. // List of available record in database
  494. dol_syslog("htdocs/admin/dict", LOG_DEBUG);
  495. $resql=$db->query($sql);
  496. if ($resql)
  497. {
  498. $num = $db->num_rows($resql);
  499. $i = 0;
  500. $var=true;
  501. $param = '&id='.$id;
  502. $paramwithsearch = $param;
  503. if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder;
  504. if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield;
  505. if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha');
  506. // There is several pages
  507. if ($num > $listlimit)
  508. {
  509. print '<tr class="none"><td align="right" colspan="'.(3+count($fieldlist)).'">';
  510. print_fleche_navigation($page, $_SERVER["PHP_SELF"], $paramwithsearch, ($num > $listlimit), '<li class="pagination"><span>'.$langs->trans("Page").' '.($page+1).'</span></li>');
  511. print '</td></tr>';
  512. }
  513. // Title of lines
  514. print '<tr class="liste_titre'.($action != 'edit' ? ' liste_titre_add' : '').'">';
  515. foreach ($fieldlist as $field => $value)
  516. {
  517. // Determine le nom du champ par rapport aux noms possibles
  518. // dans les dictionnaires de donnees
  519. $showfield=1; // By defaut
  520. $align="left";
  521. $sortable=1;
  522. $valuetoshow='';
  523. /*
  524. $tmparray=getLabelOfField($fieldlist[$field]);
  525. $showfield=$tmp['showfield'];
  526. $valuetoshow=$tmp['valuetoshow'];
  527. $align=$tmp['align'];
  528. $sortable=$tmp['sortable'];
  529. */
  530. $valuetoshow=ucfirst($fieldlist[$field]); // By defaut
  531. $valuetoshow=$langs->trans($valuetoshow); // try to translate
  532. if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); }
  533. if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); }
  534. if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') { $valuetoshow=$langs->trans("Label"); }
  535. if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); }
  536. if ($fieldlist[$field]=='content') { $valuetoshow=$langs->trans("Content"); $showfield=0;}
  537. if ($fieldlist[$field]=='content_lines') { $valuetoshow=$langs->trans("ContentLines"); $showfield=0; }
  538. // Affiche nom du champ
  539. if ($showfield)
  540. {
  541. if (! empty($tabhelp[$id][$value]))
  542. {
  543. if (in_array($value, array('topic'))) $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
  544. else $valuetoshow = $form->textwithpicto($valuetoshow, $tabhelp[$id][$value], 1, 'help', '', 0, 2); // Tooltip on hover
  545. }
  546. print getTitleFieldOfList($valuetoshow, 0, $_SERVER["PHP_SELF"], ($sortable?$fieldlist[$field]:''), ($page?'page='.$page.'&':''), $param, "align=".$align, $sortfield, $sortorder);
  547. }
  548. }
  549. print getTitleFieldOfList($langs->trans("Status"), 0, $_SERVER["PHP_SELF"], "active", ($page?'page='.$page.'&':''), $param, 'align="center"', $sortfield, $sortorder);
  550. print getTitleFieldOfList('');
  551. print getTitleFieldOfList('');
  552. print '</tr>';
  553. // Title line with search boxes
  554. print '<tr class="liste_titre">';
  555. $filterfound=0;
  556. foreach ($fieldlist as $field => $value)
  557. {
  558. if (! in_array($field, array('content', 'content_lines'))) print '<td class="liste_titre"></td>';
  559. }
  560. if (empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES)) print '<td class="liste_titre"></td>';
  561. print '<td class="liste_titre"></td>';
  562. print '<td class="liste_titre"></td>';
  563. print '</tr>';
  564. if ($num)
  565. {
  566. // Lines with values
  567. while ($i < $num)
  568. {
  569. $obj = $db->fetch_object($resql);
  570. //print_r($obj);
  571. print '<tr class="oddeven" id="rowid-'.$obj->rowid.'">';
  572. if ($action == 'edit' && ($rowid == (! empty($obj->rowid)?$obj->rowid:$obj->code)))
  573. {
  574. $tmpaction='edit';
  575. $parameters=array('fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  576. $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  577. $error=$hookmanager->error; $errors=$hookmanager->errors;
  578. // Show fields
  579. if (empty($reshook)) fieldList($fieldlist,$obj,$tabname[$id],'edit');
  580. print '<td colspan="3" align="center">';
  581. print '<input type="hidden" name="page" value="'.$page.'">';
  582. print '<input type="hidden" name="rowid" value="'.$rowid.'">';
  583. print '<input type="submit" class="button" name="actionmodify" value="'.$langs->trans("Modify").'">';
  584. print '<div name="'.(! empty($obj->rowid)?$obj->rowid:$obj->code).'"></div>';
  585. print '<input type="submit" class="button" name="actioncancel" value="'.$langs->trans("Cancel").'">';
  586. print '</td>';
  587. $fieldsforcontent = array('content');
  588. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  589. {
  590. $fieldsforcontent = array('content', 'content_lines');
  591. }
  592. foreach ($fieldsforcontent as $tmpfieldlist)
  593. {
  594. $showfield = 1;
  595. $align = "left";
  596. $valuetoshow = $obj->{$tmpfieldlist};
  597. $class = 'tddict';
  598. // Show value for field
  599. if ($showfield) {
  600. print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$rowid.' "><td colspan="5">'; // To create an artificial CR for the current tr we are on
  601. $okforextended = true;
  602. if (empty($conf->global->FCKEDITOR_ENABLE_MAIL))
  603. $okforextended = false;
  604. $doleditor = new DolEditor($tmpfieldlist.'-'.$rowid, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_6, '90%');
  605. print $doleditor->Create(1);
  606. print '</td>';
  607. print '<td></td><td></td><td></td>';
  608. }
  609. }
  610. }
  611. else
  612. {
  613. $tmpaction = 'view';
  614. $parameters=array('var'=>$var, 'fieldlist'=>$fieldlist, 'tabname'=>$tabname[$id]);
  615. $reshook=$hookmanager->executeHooks('viewDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks
  616. $error=$hookmanager->error; $errors=$hookmanager->errors;
  617. if (empty($reshook))
  618. {
  619. foreach ($fieldlist as $field => $value)
  620. {
  621. if (in_array($fieldlist[$field], array('content','content_lines'))) continue;
  622. $showfield=1;
  623. $align="left";
  624. $valuetoshow=$obj->{$fieldlist[$field]};
  625. if ($value == 'type_template')
  626. {
  627. $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow;
  628. }
  629. $class='tddict';
  630. // Show value for field
  631. if ($showfield)
  632. {
  633. print '<!-- '.$fieldlist[$field].' --><td align="'.$align.'" class="'.$class.'">'.$valuetoshow.'</td>';
  634. }
  635. }
  636. }
  637. // Can an entry be erased or disabled ?
  638. $iserasable=1;$canbedisabled=1;$canbemodified=1; // true by default
  639. $canbemodified=$iserasable;
  640. $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):'');
  641. if ($param) $url .= '&'.$param;
  642. $url.='&';
  643. // Active
  644. print '<td align="center" class="nowrap">';
  645. if ($canbedisabled) print '<a href="'.$url.'action='.$acts[$obj->active].'">'.$actl[$obj->active].'</a>';
  646. else
  647. {
  648. if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO'))) print $langs->trans("AlwaysActive");
  649. else if (isset($obj->type) && in_array($obj->type, array('systemauto')) && empty($obj->active)) print $langs->trans("Deprecated");
  650. else if (isset($obj->type) && in_array($obj->type, array('system')) && ! empty($obj->active) && $obj->code != 'AC_OTH') print $langs->trans("UsedOnlyWithTypeOption");
  651. else print $langs->trans("AlwaysActive");
  652. }
  653. print "</td>";
  654. // Modify link
  655. if ($canbemodified) print '<td align="center"><a class="reposition" href="'.$url.'action=edit">'.img_edit().'</a></td>';
  656. else print '<td>&nbsp;</td>';
  657. // Delete link
  658. if ($iserasable)
  659. {
  660. print '<td align="center">';
  661. if ($user->admin) print '<a href="'.$url.'action=delete">'.img_delete().'</a>';
  662. //else print '<a href="#">'.img_delete().'</a>'; // Some dictionary can be edited by other profile than admin
  663. print '</td>';
  664. }
  665. else print '<td>&nbsp;</td>';
  666. /*
  667. $fieldsforcontent = array('content');
  668. if (! empty($conf->global->MAIN_EMAIL_TEMPLATES_FOR_OBJECT_LINES))
  669. {
  670. $fieldsforcontent = array('content', 'content_lines');
  671. }
  672. foreach ($fieldsforcontent as $tmpfieldlist)
  673. {
  674. $showfield = 1;
  675. $align = "left";
  676. $valuetoshow = $obj->{$tmpfieldlist};
  677. $class = 'tddict';
  678. // Show value for field
  679. if ($showfield) {
  680. print '</tr><tr class="oddeven" nohover tr-'.$tmpfieldlist.'-'.$i.' "><td colspan="5">'; // To create an artificial CR for the current tr we are on
  681. $okforextended = true;
  682. if (empty($conf->global->FCKEDITOR_ENABLE_MAIL))
  683. $okforextended = false;
  684. $doleditor = new DolEditor($tmpfieldlist.'-'.$i, (! empty($obj->{$tmpfieldlist}) ? $obj->{$tmpfieldlist} : ''), '', 140, 'dolibarr_mailings', 'In', 0, false, $okforextended, ROWS_6, '90%', 1);
  685. print $doleditor->Create(1);
  686. print '</td>';
  687. print '<td></td><td></td><td></td>';
  688. }
  689. }*/
  690. }
  691. print "</tr>\n";
  692. $i++;
  693. }
  694. }
  695. }
  696. else {
  697. dol_print_error($db);
  698. }
  699. print '</table>';
  700. print '</form>';
  701. dol_fiche_end();
  702. llxFooter();
  703. $db->close();
  704. /**
  705. * Show fields in insert/edit mode
  706. *
  707. * @param array $fieldlist Array of fields
  708. * @param Object $obj If we show a particular record, obj is filled with record fields
  709. * @param string $tabname Name of SQL table
  710. * @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
  711. * @return void
  712. */
  713. function fieldList($fieldlist, $obj='', $tabname='', $context='')
  714. {
  715. global $conf,$langs,$db;
  716. global $form;
  717. global $region_id;
  718. global $elementList,$sourceList,$localtax_typeList;
  719. global $bc;
  720. $formadmin = new FormAdmin($db);
  721. $formcompany = new FormCompany($db);
  722. if (! empty($conf->accounting->enabled)) $formaccounting = new FormAccounting($db);
  723. foreach ($fieldlist as $field => $value)
  724. {
  725. if ($fieldlist[$field] == 'lang')
  726. {
  727. print '<td>';
  728. print $formadmin->select_language($conf->global->MAIN_LANG_DEFAULT,'lang');
  729. print '</td>';
  730. }
  731. // Le type de template
  732. elseif ($fieldlist[$field] == 'type_template')
  733. {
  734. print '<td>';
  735. print $form->selectarray('type_template', $elementList,(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''));
  736. print '</td>';
  737. }
  738. elseif (in_array($fieldlist[$field], array('content','content_lines'))) continue;
  739. else
  740. {
  741. print '<td>';
  742. $size=''; $class='';
  743. if ($fieldlist[$field]=='code') $class='maxwidth100';
  744. if ($fieldlist[$field]=='private') $class='maxwidth50';
  745. if ($fieldlist[$field]=='position') $class='maxwidth50';
  746. if ($fieldlist[$field]=='libelle') $class='quatrevingtpercent';
  747. if ($fieldlist[$field]=='topic') $class='quatrevingtpercent';
  748. if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" ';
  749. print '<input type="text" '.$size.'class="flat'.($class?' '.$class:'').'" value="'.(isset($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:'').'" name="'.$fieldlist[$field].'">';
  750. print '</td>';
  751. }
  752. }
  753. }