mails_senderprofile_list.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  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. foreach ($object->fields as $key => $val) {
  192. $sql .= "t.".$key.", ";
  193. }
  194. // Add fields from extrafields
  195. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  196. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  197. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
  198. }
  199. }
  200. // Add fields from hooks
  201. $parameters = array();
  202. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  203. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  204. $sql = preg_replace('/,\s*$/', '', $sql);
  205. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  206. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  207. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  208. }
  209. if ($object->ismultientitymanaged == 1) {
  210. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  211. } else {
  212. $sql .= " WHERE 1 = 1";
  213. }
  214. foreach ($search as $key => $val) {
  215. if ($key == 'status' && $search[$key] == -1) {
  216. continue;
  217. }
  218. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  219. if (strpos($object->fields[$key]['type'], 'integer:') === 0 || $key == 'active') {
  220. if ($search[$key] == '-1') {
  221. $search[$key] = '';
  222. }
  223. $mode_search = 2;
  224. }
  225. if ($search[$key] != '') {
  226. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  227. }
  228. }
  229. if ($search_all) {
  230. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  231. }
  232. // If non admin, restrict list to itself
  233. if (empty($user->admin)) {
  234. $sql .= " AND private = ".((int) $user->id);
  235. }
  236. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  237. // Add where from extra fields
  238. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  239. // Add where from hooks
  240. $parameters = array();
  241. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  242. $sql .= $hookmanager->resPrint;
  243. /* If a group by is required
  244. $sql.= " GROUP BY "
  245. foreach($object->fields as $key => $val)
  246. {
  247. $sql .= "t.".$key.", ";
  248. }
  249. // Add fields from extrafields
  250. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  251. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  252. }
  253. // Add where from hooks
  254. $parameters=array();
  255. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
  256. $sql.=$hookmanager->resPrint;
  257. $sql=preg_replace('/,\s*$/','', $sql);
  258. */
  259. $sql .= $db->order($sortfield, $sortorder);
  260. // Count total nb of records
  261. $nbtotalofrecords = '';
  262. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  263. $resql = $db->query($sql);
  264. $nbtotalofrecords = $db->num_rows($resql);
  265. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  266. $page = 0;
  267. $offset = 0;
  268. }
  269. }
  270. // if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
  271. if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
  272. $num = $nbtotalofrecords;
  273. } else {
  274. if ($limit) {
  275. $sql .= $db->plimit($limit + 1, $offset);
  276. }
  277. $resql = $db->query($sql);
  278. if (!$resql) {
  279. dol_print_error($db);
  280. exit;
  281. }
  282. $num = $db->num_rows($resql);
  283. }
  284. // Output page
  285. // --------------------------------------------------------------------
  286. $arrayofselected = is_array($toselect) ? $toselect : array();
  287. $param = '';
  288. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  289. $param .= '&contextpage='.urlencode($contextpage);
  290. }
  291. if ($limit > 0 && $limit != $conf->liste_limit) {
  292. $param .= '&limit='.urlencode($limit);
  293. }
  294. foreach ($search as $key => $val) {
  295. if (is_array($search[$key]) && count($search[$key])) {
  296. foreach ($search[$key] as $skey) {
  297. $param .= '&search_'.$key.'[]='.urlencode($skey);
  298. }
  299. } else {
  300. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  301. }
  302. }
  303. if ($optioncss != '') {
  304. $param .= '&optioncss='.urlencode($optioncss);
  305. }
  306. // Add $param from extra fields
  307. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  308. // List of mass actions available
  309. $arrayofmassactions = array(
  310. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  311. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  312. );
  313. //if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  314. //if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) $arrayofmassactions = array();
  315. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  316. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  317. if ($optioncss != '') {
  318. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  319. }
  320. print '<input type="hidden" name="token" value="'.newToken().'">';
  321. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  322. print '<input type="hidden" name="action" value="'.($action == 'create' ? 'add' : ($action == 'edit' ? 'update' : 'list')).'">';
  323. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  324. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  325. print '<input type="hidden" name="page" value="'.$page.'">';
  326. print '<input type="hidden" name="id" value="'.$id.'">';
  327. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  328. $newcardbutton = '';
  329. if ($action != 'create') {
  330. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', $_SERVER['PHP_SELF'].'?action=create', '', $permissiontoadd);
  331. if ($action == 'edit') {
  332. print '<table class="border centpercent tableforfield">';
  333. 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>';
  334. print '<tr><td>'.$langs->trans("Email").'</td><td>';
  335. print img_picto('', 'email', 'class="pictofixedwidth"');
  336. print '<input type="text" name="email" value="'.(GETPOSTISSET('email') ? GETPOST('email', 'alphanohtml') : $object->email).'"></td></tr>';
  337. print '<tr><td>'.$langs->trans("Signature").'</td><td>';
  338. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  339. $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%');
  340. print $doleditor->Create(1);
  341. print '</td></tr>';
  342. print '<tr><td>'.$langs->trans("User").'</td><td>';
  343. print img_picto('', 'user', 'class="pictofixedwidth"');
  344. print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : $object->private), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
  345. print '</td></tr>';
  346. 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>';
  347. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  348. print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], (GETPOSTISSET('active') ? GETPOST('active', 'int') : $object->active), 0, 0, 0, '', 1);
  349. print '</td></tr>';
  350. print '</table>';
  351. print $form->buttonsSaveCancel();
  352. }
  353. } else {
  354. /*print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  355. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  356. print '<input type="hidden" name="token" value="'.newToken().'">';
  357. print '<input type="hidden" name="action" value="add">';
  358. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  359. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  360. print '<input type="hidden" name="page" value="'.$page.'">';
  361. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  362. */
  363. print '<table class="border centpercent tableforfield">';
  364. print '<tr><td class="fieldrequired">'.$langs->trans("Label").'</td><td><input type="text" name="label" class="width300" value="'.GETPOST('label', 'alphanohtml').'" autofocus></td></tr>';
  365. print '<tr><td class="fieldrequired">'.$langs->trans("Email").'</td><td>';
  366. print img_picto('', 'email', 'class="pictofixedwidth"');
  367. print '<input type="text" name="email" class="width300" value="'.GETPOST('email', 'alphanohtml').'"></td></tr>';
  368. print '<tr><td>'.$langs->trans("Signature").'</td><td>';
  369. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  370. $doleditor = new DolEditor('signature', GETPOST('signature'), '', 138, 'dolibarr_notes', 'In', true, true, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
  371. print $doleditor->Create(1);
  372. print '</td></tr>';
  373. print '<tr><td>'.$langs->trans("User").'</td><td>';
  374. print img_picto('', 'user', 'class="pictofixedwidth"');
  375. print $form->select_dolusers((GETPOSTISSET('private') ? GETPOST('private', 'int') : -1), 'private', 1, null, 0, ($user->admin ? '' : $user->id));
  376. print '</td></tr>';
  377. print '<tr><td>'.$langs->trans("Position").'</td><td><input type="text" name="position" class="maxwidth50" value="'.GETPOST('position', 'int').'"></td></tr>';
  378. print '<tr><td>'.$langs->trans("Status").'</td><td>';
  379. print $form->selectarray('active', $object->fields['active']['arrayofkeyval'], GETPOST('active', 'int'), 0);
  380. print '</td></tr>';
  381. print '</table>';
  382. print $form->buttonsSaveCancel();
  383. //print '</form>';
  384. }
  385. print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, $newcardbutton, '', $limit);
  386. //print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_companies', 0, '', '', $limit);
  387. $topicmail = "Information";
  388. //$modelmail="subscription";
  389. $objecttmp = new EmailSenderProfile($db);
  390. //$trackid = (($action == 'testhtml') ? "testhtml" : "test");
  391. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  392. if ($search_all) {
  393. foreach ($fieldstosearchall as $key => $val) {
  394. $fieldstosearchall[$key] = $langs->trans($val);
  395. }
  396. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  397. }
  398. $moreforfilter = '';
  399. /*$moreforfilter.='<div class="divsearchfield">';
  400. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  401. $moreforfilter.= '</div>';*/
  402. $parameters = array();
  403. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  404. if (empty($reshook)) {
  405. $moreforfilter .= $hookmanager->resPrint;
  406. } else {
  407. $moreforfilter = $hookmanager->resPrint;
  408. }
  409. if (!empty($moreforfilter)) {
  410. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  411. print $moreforfilter;
  412. print '</div>';
  413. }
  414. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  415. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  416. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  417. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  418. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  419. // Fields title search
  420. // --------------------------------------------------------------------
  421. print '<tr class="liste_titre">';
  422. foreach ($object->fields as $key => $val) {
  423. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  424. if ($key == 'status') {
  425. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  426. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  427. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  428. } elseif (in_array($val['type'], array('timestamp'))) {
  429. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  430. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  431. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  432. }
  433. if (!empty($arrayfields['t.'.$key]['checked'])) {
  434. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  435. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  436. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], empty($search[$key]) ? '' : $search[$key], $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  437. } elseif (strpos($val['type'], 'integer:') === 0) {
  438. print $object->showInputField($val, $key, empty($search[$key]) ? '' : $search[$key], '', '', 'search_', 'maxwidth150', 1);
  439. } elseif (!preg_match('/^(date|timestamp)/', $val['type'])) {
  440. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'">';
  441. }
  442. print '</td>';
  443. }
  444. }
  445. // Extra fields
  446. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  447. // Fields from hook
  448. $parameters = array('arrayfields'=>$arrayfields);
  449. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  450. print $hookmanager->resPrint;
  451. // Action column
  452. print '<td class="liste_titre maxwidthsearch">';
  453. $searchpicto = $form->showFilterButtons();
  454. print $searchpicto;
  455. print '</td>';
  456. print '</tr>'."\n";
  457. // Fields title label
  458. // --------------------------------------------------------------------
  459. print '<tr class="liste_titre">';
  460. foreach ($object->fields as $key => $val) {
  461. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  462. if ($key == 'status') {
  463. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  464. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  465. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  466. } elseif (in_array($val['type'], array('timestamp'))) {
  467. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  468. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID') {
  469. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  470. }
  471. if (!empty($arrayfields['t.'.$key]['checked'])) {
  472. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  473. }
  474. }
  475. // Extra fields
  476. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  477. // Hook fields
  478. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  479. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  480. print $hookmanager->resPrint;
  481. // Action column
  482. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  483. print '</tr>'."\n";
  484. // Detect if we need a fetch on each output line
  485. $needToFetchEachLine = 0;
  486. if (!empty($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  487. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  488. if (preg_match('/\$object/', $val)) {
  489. $needToFetchEachLine++; // There is at least one compute field that use $object
  490. }
  491. }
  492. }
  493. // Loop on record
  494. // --------------------------------------------------------------------
  495. $i = 0;
  496. $totalarray = array();
  497. $totalarray['nbfield'] = 0;
  498. while ($i < ($limit ? min($num, $limit) : $num)) {
  499. $obj = $db->fetch_object($resql);
  500. if (empty($obj)) {
  501. break; // Should not happen
  502. }
  503. // Store properties in $object
  504. $object->setVarsFromFetchObj($obj);
  505. // Show here line of result
  506. print '<tr class="oddeven">';
  507. foreach ($object->fields as $key => $val) {
  508. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  509. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  510. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  511. } elseif ($key == 'status') {
  512. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  513. }
  514. if (in_array($val['type'], array('timestamp'))) {
  515. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  516. } elseif ($key == 'ref') {
  517. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  518. }
  519. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'status') {
  520. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  521. }
  522. if (!empty($arrayfields['t.'.$key]['checked'])) {
  523. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  524. if ($key == 'status' || $key == 'active') {
  525. print $object->getLibStatut(5);
  526. } else {
  527. print $object->showOutputField($val, $key, $object->$key, '');
  528. }
  529. print '</td>';
  530. if (!$i) {
  531. $totalarray['nbfield']++;
  532. }
  533. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  534. if (!$i) {
  535. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  536. }
  537. if (!isset($totalarray['val'])) {
  538. $totalarray['val'] = array();
  539. }
  540. if (!isset($totalarray['val']['t.'.$key])) {
  541. $totalarray['val']['t.'.$key] = 0;
  542. }
  543. $totalarray['val']['t.'.$key] += $object->$key;
  544. }
  545. }
  546. }
  547. // Extra fields
  548. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  549. // Fields from hook
  550. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  551. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  552. print $hookmanager->resPrint;
  553. // Action column
  554. print '<td class="nowrap center">';
  555. $url = $_SERVER["PHP_SELF"].'?id='.$obj->rowid;
  556. if ($limit) {
  557. $url .= '&limit='.urlencode($limit);
  558. }
  559. if ($page) {
  560. $url .= '&page='.urlencode($page);
  561. }
  562. if ($sortfield) {
  563. $url .= '&sortfield='.urlencode($sortfield);
  564. }
  565. if ($sortorder) {
  566. $url .= '&page='.urlencode($sortorder);
  567. }
  568. print '<a class="editfielda reposition marginrightonly marginleftonly" href="'.$url.'&action=edit&token='.newToken().'&rowid='.$obj->rowid.'">'.img_edit().'</a>';
  569. //print ' &nbsp; ';
  570. print '<a class=" marginrightonly marginleftonly" href="'.$url.'&action=delete&token='.newToken().'">'.img_delete().'</a> &nbsp; ';
  571. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  572. $selected = 0;
  573. if (in_array($object->id, $arrayofselected)) {
  574. $selected = 1;
  575. }
  576. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  577. }
  578. print '</td>';
  579. if (!$i) {
  580. $totalarray['nbfield']++;
  581. }
  582. print '</tr>'."\n";
  583. $i++;
  584. }
  585. // Show total line
  586. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  587. // If no record found
  588. if ($num == 0) {
  589. $colspan = 1;
  590. foreach ($arrayfields as $key => $val) {
  591. if (!empty($val['checked'])) {
  592. $colspan++;
  593. }
  594. }
  595. print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
  596. }
  597. $db->free($resql);
  598. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  599. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  600. print $hookmanager->resPrint;
  601. print '</table>'."\n";
  602. print '</div>'."\n";
  603. print '</form>'."\n";
  604. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  605. $hidegeneratedfilelistifempty = 1;
  606. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  607. $hidegeneratedfilelistifempty = 0;
  608. }
  609. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  610. $formfile = new FormFile($db);
  611. // Show list of available documents
  612. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  613. $urlsource .= str_replace('&amp;', '&', $param);
  614. $filedir = $diroutputmassaction;
  615. $genallowed = $permissiontoread;
  616. $delallowed = $permissiontoadd;
  617. print $formfile->showdocuments('massfilesarea_emailsenderprofile', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  618. }
  619. print dol_get_fiche_end();
  620. // End of page
  621. llxFooter();
  622. $db->close();