mails_senderprofile_list.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/admin/mails_senderprofile_list.php
  20. * \ingroup core
  21. * \brief Page to adminsiter email sender profiles
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/emailsenderprofile.class.php';
  29. // Load translation files required by the page
  30. $langs->loadLangs(array("errors", "admin", "mails", "languages"));
  31. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  32. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  33. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  34. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  35. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  36. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  37. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'emailsenderprofilelist'; // To manage different context of search
  38. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  39. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  40. $id = GETPOST('id', 'int');
  41. $rowid = GETPOST('rowid', 'alpha');
  42. // Load variable for pagination
  43. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  48. $page = 0;
  49. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. // Initialize technical objects
  54. $object = new EmailSenderProfile($db);
  55. $extrafields = new ExtraFields($db);
  56. $diroutputmassaction = $conf->admin->dir_output.'/temp/massgeneration/'.$user->id;
  57. $hookmanager->initHooks(array('emailsenderprofilelist')); // Note that conf->hooks_modules contains array
  58. // Fetch optionals attributes and labels
  59. $extrafields->fetch_name_optionals_label($object->table_element);
  60. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  61. // Default sort order (if not yet defined by previous GETPOST)
  62. if (!$sortfield) {
  63. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  64. }
  65. if (!$sortorder) {
  66. $sortorder = "ASC";
  67. }
  68. // Initialize array of search criterias
  69. $search_all = GETPOST("search_all", 'alpha');
  70. $search = array();
  71. foreach ($object->fields as $key => $val) {
  72. if (GETPOST('search_'.$key, 'alpha')) {
  73. $search[$key] = GETPOST('search_'.$key, 'alpha');
  74. }
  75. }
  76. // List of fields to search into when doing a "search in all"
  77. $fieldstosearchall = array();
  78. foreach ($object->fields as $key => $val) {
  79. if (!empty($val['searchall'])) {
  80. $fieldstosearchall['t.'.$key] = $val['label'];
  81. }
  82. }
  83. // Definition of fields for list
  84. $arrayfields = array();
  85. foreach ($object->fields as $key => $val) {
  86. // If $val['visible']==0, then we never show the field
  87. if (!empty($val['visible'])) {
  88. $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>($val['enabled'] && ($val['visible'] != 3)), 'position'=>$val['position']);
  89. }
  90. }
  91. // Extra fields
  92. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label']) > 0) {
  93. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  94. if (!empty($extrafields->attributes[$object->table_element]['list'][$key])) {
  95. $arrayfields["ef.".$key] = array(
  96. 'label'=>$extrafields->attributes[$object->table_element]['label'][$key],
  97. 'checked'=>(($extrafields->attributes[$object->table_element]['list'][$key] < 0) ? 0 : 1),
  98. 'position'=>$extrafields->attributes[$object->table_element]['pos'][$key],
  99. 'enabled'=>(abs($extrafields->attributes[$object->table_element]['list'][$key]) != 3 && $extrafields->attributes[$object->table_element]['perms'][$key])
  100. );
  101. }
  102. }
  103. }
  104. $object->fields = dol_sort_array($object->fields, 'position');
  105. $arrayfields = dol_sort_array($arrayfields, 'position');
  106. $permissiontoread = $user->admin;
  107. $permissiontoadd = $user->admin;
  108. $permissiontodelete = $user->admin;
  109. if ($id > 0) {
  110. $object->fetch($id);
  111. }
  112. // Security check
  113. $socid = 0;
  114. if ($user->socid > 0) { // Protection if external user
  115. //$socid = $user->socid;
  116. accessforbidden();
  117. }
  118. // A non admin user can see profiles but limited to its own user
  119. if (!$user->admin) {
  120. if ($object->id > 0 && $object->private != $user->id) {
  121. accessforbidden();
  122. }
  123. }
  124. /*
  125. * Actions
  126. */
  127. if (GETPOST('cancel', 'alpha')) {
  128. $action = 'list'; $massaction = '';
  129. }
  130. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  131. $massaction = '';
  132. }
  133. $parameters = array();
  134. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  135. if ($reshook < 0) {
  136. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  137. }
  138. if (empty($reshook)) {
  139. // Actions cancel, add, update, delete or clone
  140. $backurlforlist = $_SERVER["PHP_SELF"].'?action=list';
  141. include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
  142. // Selection of new fields
  143. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  144. // Purge search criteria
  145. 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
  146. foreach ($object->fields as $key => $val) {
  147. $search[$key] = '';
  148. }
  149. $toselect = array();
  150. $search_array_options = array();
  151. }
  152. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  153. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  154. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  155. }
  156. // Mass actions
  157. $objectclass = 'EmailSenderProfile';
  158. $objectlabel = 'EmailSenderProfile';
  159. $uploaddir = $conf->admin->dir_output.'/senderprofiles';
  160. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  161. if ($action == 'delete') {
  162. $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_email_senderprofile WHERE rowid = ".GETPOST('id', 'int');
  163. $resql = $db->query($sql);
  164. if ($resql) {
  165. setEventMessages($langs->trans("RecordDeleted"), null, 'mesgs');
  166. } else {
  167. setEventMessages($langs->trans("Error").' '.$db->lasterror(), null, 'errors');
  168. }
  169. }
  170. }
  171. /*
  172. * View
  173. */
  174. $form = new Form($db);
  175. $now = dol_now();
  176. //$help_url="EN:Module_EmailSenderProfile|FR:Module_EmailSenderProfile_FR|ES:Módulo_EmailSenderProfile";
  177. $help_url = '';
  178. $title = $langs->trans("EMailsSetup");
  179. llxHeader('', $title);
  180. $linkback = '';
  181. $titlepicto = 'title_setup';
  182. print load_fiche_titre($title, $linkback, $titlepicto);
  183. $head = email_admin_prepare_head();
  184. print dol_get_fiche_head($head, 'senderprofiles', '', -1);
  185. print '<span class="opacitymedium">'.$langs->trans("EMailsSenderProfileDesc")."</span><br>\n";
  186. print "<br>\n";
  187. // Build and execute select
  188. // --------------------------------------------------------------------
  189. $sql = 'SELECT ';
  190. foreach ($object->fields as $key => $val) {
  191. $sql .= "t.".$key.", ";
  192. }
  193. // Add fields from extrafields
  194. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  195. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  196. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
  197. }
  198. }
  199. // Add fields from hooks
  200. $parameters = array();
  201. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  202. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  203. $sql = preg_replace('/,\s*$/', '', $sql);
  204. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  205. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  206. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  207. }
  208. if ($object->ismultientitymanaged == 1) {
  209. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  210. } else {
  211. $sql .= " WHERE 1 = 1";
  212. }
  213. foreach ($search as $key => $val) {
  214. if ($key == 'status' && $search[$key] == -1) {
  215. continue;
  216. }
  217. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  218. if (strpos($object->fields[$key]['type'], 'integer:') === 0 || $key == 'active') {
  219. if ($search[$key] == '-1') {
  220. $search[$key] = '';
  221. }
  222. $mode_search = 2;
  223. }
  224. if ($search[$key] != '') {
  225. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  226. }
  227. }
  228. if ($search_all) {
  229. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  230. }
  231. // If non admin, restrict list to itself
  232. if (empty($user->admin)) {
  233. $sql .= " AND private = ".((int) $user->id);
  234. }
  235. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  236. // Add where from extra fields
  237. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  238. // Add where from hooks
  239. $parameters = array();
  240. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  241. $sql .= $hookmanager->resPrint;
  242. /* If a group by is required
  243. $sql.= " GROUP BY "
  244. foreach($object->fields as $key => $val)
  245. {
  246. $sql .= "t.".$key.", ";
  247. }
  248. // Add fields from extrafields
  249. if (! empty($extrafields->attributes[$object->table_element]['label'])) {
  250. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  251. }
  252. // Add where from hooks
  253. $parameters=array();
  254. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  255. $sql.=$hookmanager->resPrint;
  256. $sql=preg_replace('/,\s*$/','', $sql);
  257. */
  258. $sql .= $db->order($sortfield, $sortorder);
  259. // Count total nb of records
  260. $nbtotalofrecords = '';
  261. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  262. $resql = $db->query($sql);
  263. $nbtotalofrecords = $db->num_rows($resql);
  264. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  265. $page = 0;
  266. $offset = 0;
  267. }
  268. }
  269. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  270. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  271. $num = $nbtotalofrecords;
  272. } else {
  273. if ($limit) {
  274. $sql .= $db->plimit($limit + 1, $offset);
  275. }
  276. $resql = $db->query($sql);
  277. if (!$resql) {
  278. dol_print_error($db);
  279. exit;
  280. }
  281. $num = $db->num_rows($resql);
  282. }
  283. // Output page
  284. // --------------------------------------------------------------------
  285. $arrayofselected = is_array($toselect) ? $toselect : array();
  286. $param = '';
  287. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  288. $param .= '&contextpage='.urlencode($contextpage);
  289. }
  290. if ($limit > 0 && $limit != $conf->liste_limit) {
  291. $param .= '&limit='.urlencode($limit);
  292. }
  293. foreach ($search as $key => $val) {
  294. if (is_array($search[$key]) && count($search[$key])) {
  295. foreach ($search[$key] as $skey) {
  296. $param .= '&search_'.$key.'[]='.urlencode($skey);
  297. }
  298. } else {
  299. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  300. }
  301. }
  302. if ($optioncss != '') {
  303. $param .= '&optioncss='.urlencode($optioncss);
  304. }
  305. // Add $param from extra fields
  306. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  307. // List of mass actions available
  308. $arrayofmassactions = array(
  309. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  310. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  311. );
  312. //if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  313. //if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
  314. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  315. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  316. if ($optioncss != '') {
  317. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  318. }
  319. print '<input type="hidden" name="token" value="'.newToken().'">';
  320. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  321. print '<input type="hidden" name="action" value="'.($action == 'create' ? 'add' : ($action == 'edit' ? 'update' : 'list')).'">';
  322. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  323. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  324. print '<input type="hidden" name="page" value="'.$page.'">';
  325. print '<input type="hidden" name="id" value="'.$id.'">';
  326. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  327. $newcardbutton = '';
  328. if ($action != 'create') {
  329. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create', '', $permissiontoadd);
  330. if ($action == 'edit') {
  331. print '<table class="border centpercent tableforfield">';
  332. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" value="'.(GETPOSTISSET('label') ? GETPOST('label', 'alphanohtml') : $object->label).'"></td></tr>';
  333. print '<tr><td>'.$langs->trans("Email").'</td><td><input type="text" name="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alphanohtml') : $object->email).'"></td></tr>';
  334. print '<tr><td>'.$langs->trans("Signature").'</td><td>';
  335. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  336. $doleditor = new DolEditor('signature', (GETPOSTISSET('signature') ? GETPOST('signature', 'restricthtml') : $object->signature), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
  337. print $doleditor->Create(1);
  338. print '</td></tr>';
  339. print '<tr><td>'.$langs->trans("User").'</td><td>';
  340. print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : $object->private), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
  341. print '</td></tr>';
  342. print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.(GETPOSTISSET('position') ? GETPOST('position', 'int') : $object->position).'"></td></tr>';
  343. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  344. print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], (GETPOSTISSET('active') ? GETPOST('active', 'int') : $object->active), 0, 0, 0, '', 1);
  345. print '</td></tr>';
  346. print '</table>';
  347. print $form->buttonsSaveCancel();
  348. }
  349. } else {
  350. /*print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  351. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  352. print '<input type="hidden" name="token" value="'.newToken().'">';
  353. print '<input type="hidden" name="action" value="add">';
  354. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  355. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  356. print '<input type="hidden" name="page" value="'.$page.'">';
  357. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  358. */
  359. print '<table class="border centpercent tableforfield">';
  360. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" value="'.GETPOST('label', 'alphanohtml').'" autofocus></td></tr>';
  361. print '<tr><td class="fieldrequired">'.$langs->trans("Email").'</td><td><input type="text" name="email" value="'.GETPOST('email', 'alphanohtml').'"></td></tr>';
  362. print '<tr><td>'.$langs->trans("Signature").'</td><td>';
  363. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  364. $doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
  365. print $doleditor->Create(1);
  366. print '</td></tr>';
  367. print '<tr><td>'.$langs->trans("User").'</td><td>';
  368. print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : -1), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
  369. print '</td></tr>';
  370. print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.GETPOST('position', 'int').'"></td></tr>';
  371. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  372. print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], GETPOST('active', 'int'), 0);
  373. print '</td></tr>';
  374. print '</table>';
  375. print $form->buttonsSaveCancel();
  376. //print '</form>';
  377. }
  378. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit);
  379. //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
  380. $topicmail = "Information";
  381. //$modelmail="subscription";
  382. $objecttmp = new EmailSenderProfile($db);
  383. //$trackid = (($action == 'testhtml') ? "testhtml" : "test");
  384. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  385. if ($search_all) {
  386. foreach ($fieldstosearchall as $key => $val) {
  387. $fieldstosearchall[$key] = $langs->trans($val);
  388. }
  389. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  390. }
  391. $moreforfilter = '';
  392. /*$moreforfilter.='<div class="divsearchfield">';
  393. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  394. $moreforfilter.= '</div>';*/
  395. $parameters = array();
  396. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  397. if (empty($reshook)) {
  398. $moreforfilter .= $hookmanager->resPrint;
  399. } else {
  400. $moreforfilter = $hookmanager->resPrint;
  401. }
  402. if (!empty($moreforfilter)) {
  403. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  404. print $moreforfilter;
  405. print '</div>';
  406. }
  407. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  408. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  409. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  410. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  411. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  412. // Fields title search
  413. // --------------------------------------------------------------------
  414. print '<tr class="liste_titre">';
  415. foreach ($object->fields as $key => $val) {
  416. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  417. if ($key == 'status') {
  418. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  419. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  420. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  421. } elseif (in_array($val['type'], array('timestamp'))) {
  422. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  423. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  424. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  425. }
  426. if (!empty($arrayfields['t.'.$key]['checked'])) {
  427. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  428. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  429. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], empty($search[$key]) ? '' : $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  430. } elseif (strpos($val['type'], 'integer:') === 0) {
  431. print $object->showInputField($val, $key, empty($search[$key]) ? '' : $search[$key], '', '', 'search_', 'maxwidth150', 1);
  432. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  433. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  434. }
  435. print '</td>';
  436. }
  437. }
  438. // Extra fields
  439. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  440. // Fields from hook
  441. $parameters = array('arrayfields'=>$arrayfields);
  442. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  443. print $hookmanager->resPrint;
  444. // Action column
  445. print '<td class="liste_titre maxwidthsearch">';
  446. $searchpicto = $form->showFilterButtons();
  447. print $searchpicto;
  448. print '</td>';
  449. print '</tr>'."\n";
  450. // Fields title label
  451. // --------------------------------------------------------------------
  452. print '<tr class="liste_titre">';
  453. foreach ($object->fields as $key => $val) {
  454. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  455. if ($key == 'status') {
  456. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  457. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  458. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  459. } elseif (in_array($val['type'], array('timestamp'))) {
  460. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  461. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  462. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  463. }
  464. if (!empty($arrayfields['t.'.$key]['checked'])) {
  465. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  466. }
  467. }
  468. // Extra fields
  469. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  470. // Hook fields
  471. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  472. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  473. print $hookmanager->resPrint;
  474. // Action column
  475. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  476. print '</tr>'."\n";
  477. // Detect if we need a fetch on each output line
  478. $needToFetchEachLine = 0;
  479. if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  480. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  481. if (preg_match('/\$object/', $val)) {
  482. $needToFetchEachLine++; // There is at least one compute field that use $object
  483. }
  484. }
  485. }
  486. // Loop on record
  487. // --------------------------------------------------------------------
  488. $i = 0;
  489. $totalarray = array();
  490. while ($i < ($limit ? min($num, $limit) : $num)) {
  491. $obj = $db->fetch_object($resql);
  492. if (empty($obj)) {
  493. break; // Should not happen
  494. }
  495. // Store properties in $object
  496. $object->setVarsFromFetchObj($obj);
  497. // Show here line of result
  498. print '<tr class="oddeven">';
  499. foreach ($object->fields as $key => $val) {
  500. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  501. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  502. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  503. } elseif ($key == 'status') {
  504. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  505. }
  506. if (in_array($val['type'], array('timestamp'))) {
  507. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  508. } elseif ($key == 'ref') {
  509. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  510. }
  511. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
  512. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  513. }
  514. if (!empty($arrayfields['t.'.$key]['checked'])) {
  515. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  516. if ($key == 'status' || $key == 'active') {
  517. print $object->getLibStatut(5);
  518. } else {
  519. print $object->showOutputField($val, $key, $object->$key, '');
  520. }
  521. print '</td>';
  522. if (!$i) {
  523. $totalarray['nbfield']++;
  524. }
  525. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  526. if (!$i) {
  527. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  528. }
  529. if (!isset($totalarray['val'])) {
  530. $totalarray['val'] = array();
  531. }
  532. if (!isset($totalarray['val']['t.'.$key])) {
  533. $totalarray['val']['t.'.$key] = 0;
  534. }
  535. $totalarray['val']['t.'.$key] += $object->$key;
  536. }
  537. }
  538. }
  539. // Extra fields
  540. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  541. // Fields from hook
  542. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  543. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  544. print $hookmanager->resPrint;
  545. // Action column
  546. print '<td class="nowrap center">';
  547. $url = $_SERVER["PHP_SELF"].'?id='.$obj->rowid;
  548. if ($limit) {
  549. $url .= '&limit='.urlencode($limit);
  550. }
  551. if ($page) {
  552. $url .= '&page='.urlencode($page);
  553. }
  554. if ($sortfield) {
  555. $url .= '&sortfield='.urlencode($sortfield);
  556. }
  557. if ($sortorder) {
  558. $url .= '&page='.urlencode($sortorder);
  559. }
  560. print '<a class="editfielda reposition marginrightonly marginleftonly" href="'.$url.'&action=edit&token='.newToken().'&rowid='.$obj->rowid.'">'.img_edit().'</a>';
  561. //print ' &nbsp; ';
  562. print '<a class=" marginrightonly marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a> &nbsp; ';
  563. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  564. $selected = 0;
  565. if (in_array($object->id, $arrayofselected)) {
  566. $selected = 1;
  567. }
  568. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  569. }
  570. print '</td>';
  571. if (!$i) {
  572. $totalarray['nbfield']++;
  573. }
  574. print '</tr>'."\n";
  575. $i++;
  576. }
  577. // Show total line
  578. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  579. // If no record found
  580. if ($num == 0) {
  581. $colspan = 1;
  582. foreach ($arrayfields as $key => $val) {
  583. if (!empty($val['checked'])) {
  584. $colspan++;
  585. }
  586. }
  587. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  588. }
  589. $db->free($resql);
  590. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  591. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  592. print $hookmanager->resPrint;
  593. print '</table>'."\n";
  594. print '</div>'."\n";
  595. print '</form>'."\n";
  596. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  597. $hidegeneratedfilelistifempty = 1;
  598. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  599. $hidegeneratedfilelistifempty = 0;
  600. }
  601. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  602. $formfile = new FormFile($db);
  603. // Show list of available documents
  604. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  605. $urlsource .= str_replace('&amp;', '&', $param);
  606. $filedir = $diroutputmassaction;
  607. $genallowed = $permissiontoread;
  608. $delallowed = $permissiontoadd;
  609. print $formfile->showdocuments('massfilesarea_emailsenderprofile', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  610. }
  611. print dol_get_fiche_end();
  612. // End of page
  613. llxFooter();
  614. $db->close();