mails_senderprofile_list.php 30 KB

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