userloginnaplo_list.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  1. <?php
  2. // Load Dolibarr environment
  3. $res = 0;
  4. // Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
  5. if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
  6. $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
  7. }
  8. // Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
  9. $tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; $tmp2 = realpath(__FILE__); $i = strlen($tmp) - 1; $j = strlen($tmp2) - 1;
  10. while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
  11. $i--; $j--;
  12. }
  13. if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
  14. $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
  15. }
  16. if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
  17. $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
  18. }
  19. // Try main.inc.php using relative path
  20. if (!$res && file_exists("../main.inc.php")) {
  21. $res = @include "../main.inc.php";
  22. }
  23. if (!$res && file_exists("../../main.inc.php")) {
  24. $res = @include "../../main.inc.php";
  25. }
  26. if (!$res && file_exists("../../../main.inc.php")) {
  27. $res = @include "../../../main.inc.php";
  28. }
  29. if (!$res) {
  30. die("Include of main fails");
  31. }
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  35. // load bbus libraries
  36. require_once __DIR__.'/class/userloginnaplo.class.php';
  37. // for other modules
  38. //dol_include_once('/othermodule/class/otherobject.class.php');
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("bbus@bbus", "other"));
  41. $id = GETPOST('id', 'int');
  42. $ref = GETPOST('ref', 'alpha');
  43. $user_id = GETPOST('user_id', 'int');
  44. $idmenu = GETPOST('idmenu', 'int');
  45. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  46. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  47. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  48. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  49. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  50. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  51. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  52. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  53. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  54. $mode = GETPOST('mode', 'aZ');
  55. // Load variable for pagination
  56. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  57. $sortfield = GETPOST('sortfield', 'aZ09comma');
  58. $sortorder = GETPOST('sortorder', 'aZ09comma');
  59. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  60. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  61. // If $page is not defined, or '' or -1 or if we click on clear filters
  62. $page = 0;
  63. }
  64. $offset = $limit * $page;
  65. $pageprev = $page - 1;
  66. $pagenext = $page + 1;
  67. // Initialize technical objects
  68. $object = new UserLoginNaplo($db);
  69. $extrafields = new ExtraFields($db);
  70. $diroutputmassaction = $conf->bbus->dir_output.'/temp/massgeneration/'.$user->id;
  71. $hookmanager->initHooks(array('userloginnaplolist')); // Note that conf->hooks_modules contains array
  72. // Fetch optionals attributes and labels
  73. $extrafields->fetch_name_optionals_label($object->table_element);
  74. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  75. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  76. // Default sort order (if not yet defined by previous GETPOST)
  77. if (!$sortfield) {
  78. reset($object->fields); // Reset is required to avoid key() to return null.
  79. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  80. }
  81. if (!$sortorder) {
  82. $sortorder = "ASC";
  83. }
  84. // Initialize array of search criterias
  85. $search_all = GETPOST('search_all', 'alphanohtml');
  86. $search = array();
  87. foreach ($object->fields as $key => $val) {
  88. if (GETPOST('search_'.$key, 'alpha') !== '') {
  89. $search[$key] = GETPOST('search_'.$key, 'alpha');
  90. }
  91. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  92. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  93. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  94. }
  95. }
  96. // List of fields to search into when doing a "search in all"
  97. $fieldstosearchall = array();
  98. foreach ($object->fields as $key => $val) {
  99. if (!empty($val['searchall'])) {
  100. $fieldstosearchall['t.'.$key] = $val['label'];
  101. }
  102. }
  103. // Definition of array of fields for columns
  104. $arrayfields = array();
  105. foreach ($object->fields as $key => $val) {
  106. // If $val['visible']==0, then we never show the field
  107. if (!empty($val['visible'])) {
  108. $visible = (int) dol_eval($val['visible'], 1);
  109. $arrayfields['t.'.$key] = array(
  110. 'label'=>$val['label'],
  111. 'checked'=>(($visible < 0) ? 0 : 1),
  112. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  113. 'position'=>$val['position'],
  114. 'help'=> isset($val['help']) ? $val['help'] : ''
  115. );
  116. }
  117. }
  118. // Extra fields
  119. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  120. $object->fields = dol_sort_array($object->fields, 'position');
  121. //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
  122. $arrayfields = dol_sort_array($arrayfields, 'position');
  123. // There is several ways to check permission.
  124. // Set $enablepermissioncheck to 1 to enable a minimum low level of checks
  125. $enablepermissioncheck = 0;
  126. if ($enablepermissioncheck) {
  127. $permissiontoread = $user->rights->bbus->userloginnaplo->read;
  128. $permissiontoadd = $user->rights->bbus->userloginnaplo->write;
  129. $permissiontodelete = $user->rights->bbus->userloginnaplo->delete;
  130. } else {
  131. $permissiontoread = 1;
  132. $permissiontoadd = 1;
  133. $permissiontodelete = 1;
  134. }
  135. // Security check (enable the most restrictive one)
  136. if ($user->socid > 0) accessforbidden();
  137. //if ($user->socid > 0) accessforbidden();
  138. //$socid = 0; if ($user->socid > 0) $socid = $user->socid;
  139. //$isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  140. //restrictedArea($user, $object->element, 0, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  141. if (empty($conf->bbus->enabled)) accessforbidden('Module not enabled');
  142. if (!$permissiontoread) accessforbidden();
  143. /*
  144. * Actions
  145. */
  146. if (GETPOST('cancel', 'alpha')) {
  147. $action = 'list';
  148. $massaction = '';
  149. }
  150. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  151. $massaction = '';
  152. }
  153. $parameters = array();
  154. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  155. if ($reshook < 0) {
  156. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  157. }
  158. if (empty($reshook)) {
  159. // Selection of new fields
  160. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  161. // Purge search criteria
  162. 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
  163. foreach ($object->fields as $key => $val) {
  164. $search[$key] = '';
  165. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  166. $search[$key.'_dtstart'] = '';
  167. $search[$key.'_dtend'] = '';
  168. }
  169. }
  170. $toselect = array();
  171. $search_array_options = array();
  172. }
  173. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  174. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  175. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  176. }
  177. // Mass actions
  178. $objectclass = 'UserLoginNaplo';
  179. $objectlabel = 'UserLoginNaplo';
  180. $uploaddir = $conf->bbus->dir_output;
  181. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  182. }
  183. /*
  184. * View
  185. */
  186. $form = new Form($db);
  187. $now = dol_now();
  188. //$help_url = "EN:Module_UserLoginNaplo|FR:Module_UserLoginNaplo_FR|ES:Módulo_UserLoginNaplo";
  189. $help_url = '';
  190. $title = $langs->trans("UserLoginNaplos");
  191. $morejs = array();
  192. $morecss = array();
  193. // Build and execute select
  194. // --------------------------------------------------------------------
  195. $sql = 'SELECT ';
  196. $sql .= $object->getFieldList('t');
  197. // Add fields from extrafields
  198. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  199. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  200. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  201. }
  202. }
  203. // Add fields from hooks
  204. $parameters = array();
  205. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  206. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  207. $sql = preg_replace('/,\s*$/', '', $sql);
  208. //$sql .= ", COUNT(rc.rowid) as anotherfield";
  209. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  210. //$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."anothertable as rc ON rc.parent = t.rowid";
  211. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  212. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  213. }
  214. // Add table from hooks
  215. $parameters = array();
  216. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  217. $sql .= $hookmanager->resPrint;
  218. if ($object->ismultientitymanaged == 1) {
  219. $sql .= " WHERE t.entity IN (".getEntity($object->element).") AND user_id = {$user_id}";
  220. } else {
  221. $sql .= " WHERE 1 = 1 AND user_id = {$user_id}";
  222. }
  223. foreach ($search as $key => $val) {
  224. if (array_key_exists($key, $object->fields)) {
  225. if ($key == 'status' && $search[$key] == -1) {
  226. continue;
  227. }
  228. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  229. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  230. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  231. $search[$key] = '';
  232. }
  233. $mode_search = 2;
  234. }
  235. if ($search[$key] != '') {
  236. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  237. }
  238. } else {
  239. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  240. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  241. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  242. if (preg_match('/_dtstart$/', $key)) {
  243. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  244. }
  245. if (preg_match('/_dtend$/', $key)) {
  246. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  247. }
  248. }
  249. }
  250. }
  251. }
  252. if ($search_all) {
  253. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  254. }
  255. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  256. // Add where from extra fields
  257. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  258. // Add where from hooks
  259. $parameters = array();
  260. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  261. $sql .= $hookmanager->resPrint;
  262. /* If a group by is required
  263. $sql .= " GROUP BY ";
  264. foreach($object->fields as $key => $val) {
  265. $sql .= "t.".$db->escape($key).", ";
  266. }
  267. // Add fields from extrafields
  268. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  269. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  270. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  271. }
  272. }
  273. // Add where from hooks
  274. $parameters = array();
  275. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  276. $sql .= $hookmanager->resPrint;
  277. $sql = preg_replace('/,\s*$/', '', $sql);
  278. */
  279. // Add HAVING from hooks
  280. /*
  281. $parameters = array();
  282. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  283. $sql .= empty($hookmanager->resPrint) ? "" : " HAVING 1=1 ".$hookmanager->resPrint;
  284. */
  285. // Count total nb of records
  286. $nbtotalofrecords = '';
  287. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  288. /* This old and fast method to get and count full list returns all record so use a high amount of memory.
  289. $resql = $db->query($sql);
  290. $nbtotalofrecords = $db->num_rows($resql);
  291. */
  292. /* The slow method does not consume memory on mysql (not tested on pgsql) */
  293. /*$resql = $db->query($sql, 0, 'auto', 1);
  294. while ($db->fetch_object($resql)) {
  295. if (empty($nbtotalofrecords)) {
  296. $nbtotalofrecords = 1; // We can't make +1 because init value is ''
  297. } else {
  298. $nbtotalofrecords++;
  299. }
  300. }*/
  301. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  302. $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  303. $resql = $db->query($sqlforcount);
  304. if ($resql) {
  305. $objforcount = $db->fetch_object($resql);
  306. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  307. } else {
  308. dol_print_error($db);
  309. }
  310. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  311. $page = 0;
  312. $offset = 0;
  313. }
  314. $db->free($resql);
  315. }
  316. // Complete request and execute it with limit
  317. $sql .= $db->order($sortfield, $sortorder);
  318. if ($limit) {
  319. $sql .= $db->plimit($limit + 1, $offset);
  320. }
  321. $resql = $db->query($sql);
  322. if (!$resql) {
  323. dol_print_error($db);
  324. exit;
  325. }
  326. $num = $db->num_rows($resql);
  327. // Direct jump if only one record found
  328. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  329. $obj = $db->fetch_object($resql);
  330. $id = $obj->rowid;
  331. header("Location: ".dol_buildpath('/bbus/userloginnaplo_card.php', 1).'?id='.$id);
  332. exit;
  333. }
  334. // Output page
  335. // --------------------------------------------------------------------
  336. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  337. // Example : Adding jquery code
  338. // print '<script type="text/javascript">
  339. // jQuery(document).ready(function() {
  340. // function init_myfunc()
  341. // {
  342. // jQuery("#myid").removeAttr(\'disabled\');
  343. // jQuery("#myid").attr(\'disabled\',\'disabled\');
  344. // }
  345. // init_myfunc();
  346. // jQuery("#mybutton").click(function() {
  347. // init_myfunc();
  348. // });
  349. // });
  350. // </script>';
  351. $arrayofselected = is_array($toselect) ? $toselect : array();
  352. $param = '';
  353. if (!empty($mode)) {
  354. $param .= '&mode='.urlencode($mode);
  355. }
  356. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  357. $param .= '&contextpage='.urlencode($contextpage);
  358. }
  359. if ($limit > 0 && $limit != $conf->liste_limit) {
  360. $param .= '&limit='.urlencode($limit);
  361. }
  362. foreach ($search as $key => $val) {
  363. if (is_array($search[$key])) {
  364. foreach ($search[$key] as $skey) {
  365. if ($skey != '') {
  366. $param .= '&search_'.$key.'[]='.urlencode($skey);
  367. }
  368. }
  369. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  370. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  371. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  372. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  373. } elseif ($search[$key] != '') {
  374. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  375. }
  376. }
  377. if ($optioncss != '') {
  378. $param .= '&optioncss='.urlencode($optioncss);
  379. }
  380. // Add $param from extra fields
  381. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  382. // Add $param from hooks
  383. $parameters = array();
  384. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  385. $param .= $hookmanager->resPrint;
  386. // List of mass actions available
  387. $arrayofmassactions = array(
  388. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  389. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  390. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  391. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  392. );
  393. if (!empty($permissiontodelete)) {
  394. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  395. }
  396. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  397. $arrayofmassactions = array();
  398. }
  399. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  400. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  401. if ($optioncss != '') {
  402. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  403. }
  404. print '<input type="hidden" name="token" value="'.newToken().'">';
  405. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  406. print '<input type="hidden" name="action" value="list">';
  407. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  408. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  409. print '<input type="hidden" name="page" value="'.$page.'">';
  410. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  411. print '<input type="hidden" name="mode" value="'.$mode.'">';
  412. $newcardbutton = '';
  413. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  414. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  415. $newcardbutton .= dolGetButtonTitleSeparator();
  416. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/bbus/userloginnaplo_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  417. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  418. // Add code for pre mass action (confirmation or email presend form)
  419. $topicmail = "SendUserLoginNaploRef";
  420. $modelmail = "userloginnaplo";
  421. $objecttmp = new UserLoginNaplo($db);
  422. $trackid = 'xxxx'.$object->id;
  423. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  424. if ($search_all) {
  425. $setupstring = '';
  426. foreach ($fieldstosearchall as $key => $val) {
  427. $fieldstosearchall[$key] = $langs->trans($val);
  428. $setupstring .= $key."=".$val.";";
  429. }
  430. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  431. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  432. }
  433. $moreforfilter = '';
  434. /*$moreforfilter.='<div class="divsearchfield">';
  435. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  436. $moreforfilter.= '</div>';*/
  437. $parameters = array();
  438. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  439. if (empty($reshook)) {
  440. $moreforfilter .= $hookmanager->resPrint;
  441. } else {
  442. $moreforfilter = $hookmanager->resPrint;
  443. }
  444. if (!empty($moreforfilter)) {
  445. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  446. print $moreforfilter;
  447. print '</div>';
  448. }
  449. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  450. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  451. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  452. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  453. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  454. // Fields title search
  455. // --------------------------------------------------------------------
  456. print '<tr class="liste_titre">';
  457. // Action column
  458. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  459. print '<td class="liste_titre maxwidthsearch">';
  460. $searchpicto = $form->showFilterButtons('left');
  461. print $searchpicto;
  462. print '</td>';
  463. }
  464. foreach ($object->fields as $key => $val) {
  465. $searchkey = empty($search[$key]) ? '' : $search[$key];
  466. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  467. if ($key == 'status') {
  468. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  469. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  470. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  471. } elseif (in_array($val['type'], array('timestamp'))) {
  472. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  473. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  474. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  475. }
  476. if (!empty($arrayfields['t.'.$key]['checked'])) {
  477. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  478. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  479. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  480. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  481. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  482. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  483. print '<div class="nowrap">';
  484. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  485. print '</div>';
  486. print '<div class="nowrap">';
  487. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  488. print '</div>';
  489. } elseif ($key == 'lang') {
  490. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  491. $formadmin = new FormAdmin($db);
  492. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  493. } else {
  494. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  495. }
  496. print '</td>';
  497. }
  498. }
  499. // Extra fields
  500. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  501. // Fields from hook
  502. $parameters = array('arrayfields'=>$arrayfields);
  503. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  504. print $hookmanager->resPrint;
  505. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  506. print '<td class="liste_titre"></td>';
  507. }*/
  508. // Action column
  509. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  510. print '<td class="liste_titre maxwidthsearch">';
  511. $searchpicto = $form->showFilterButtons();
  512. print $searchpicto;
  513. print '</td>';
  514. }
  515. print '</tr>'."\n";
  516. $totalarray = array();
  517. $totalarray['nbfield'] = 0;
  518. // Fields title label
  519. // --------------------------------------------------------------------
  520. print '<tr class="liste_titre">';
  521. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  522. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  523. }
  524. foreach ($object->fields as $key => $val) {
  525. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  526. if ($key == 'status') {
  527. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  528. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  529. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  530. } elseif (in_array($val['type'], array('timestamp'))) {
  531. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  532. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  533. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  534. }
  535. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  536. if (!empty($arrayfields['t.'.$key]['checked'])) {
  537. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  538. $totalarray['nbfield']++;
  539. }
  540. }
  541. // Extra fields
  542. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  543. // Hook fields
  544. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  545. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  546. print $hookmanager->resPrint;
  547. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  548. print '<th class="liste_titre right">'.$langs->trans("AnotherField").'</th>';
  549. $totalarray['nbfield']++;
  550. }*/
  551. // Action column
  552. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  553. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  554. }
  555. $totalarray['nbfield']++;
  556. print '</tr>'."\n";
  557. // Detect if we need a fetch on each output line
  558. $needToFetchEachLine = 0;
  559. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  560. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  561. if (preg_match('/\$object/', $val)) {
  562. $needToFetchEachLine++; // There is at least one compute field that use $object
  563. }
  564. }
  565. }
  566. // Loop on record
  567. // --------------------------------------------------------------------
  568. $i = 0;
  569. $savnbfield = $totalarray['nbfield'];
  570. $totalarray = array();
  571. $totalarray['nbfield'] = 0;
  572. $imaxinloop = ($limit ? min($num, $limit) : $num);
  573. while ($i < $imaxinloop) {
  574. $obj = $db->fetch_object($resql);
  575. if (empty($obj)) {
  576. break; // Should not happen
  577. }
  578. // Store properties in $object
  579. $object->setVarsFromFetchObj($obj);
  580. if ($mode == 'kanban') {
  581. if ($i == 0) {
  582. print '<tr><td colspan="'.$savnbfield.'">';
  583. print '<div class="box-flex-container">';
  584. }
  585. // Output Kanban
  586. print $object->getKanbanView('');
  587. if ($i == ($imaxinloop - 1)) {
  588. print '</div>';
  589. print '</td></tr>';
  590. }
  591. } else {
  592. // Show here line of result
  593. $j = 0;
  594. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  595. // Action column
  596. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  597. print '<td class="nowrap center">';
  598. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  599. $selected = 0;
  600. if (in_array($object->id, $arrayofselected)) {
  601. $selected = 1;
  602. }
  603. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  604. }
  605. print '</td>';
  606. }
  607. foreach ($object->fields as $key => $val) {
  608. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  609. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  610. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  611. } elseif ($key == 'status') {
  612. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  613. }
  614. if (in_array($val['type'], array('timestamp'))) {
  615. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  616. } elseif ($key == 'ref') {
  617. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  618. }
  619. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  620. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  621. }
  622. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  623. if (!empty($arrayfields['t.'.$key]['checked'])) {
  624. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '');
  625. if (preg_match('/tdoverflow/', $cssforfield)) {
  626. print ' title="'.dol_escape_htmltag($object->$key).'"';
  627. }
  628. print '>';
  629. if ($key == 'status') {
  630. print $object->getLibStatut(5);
  631. } elseif ($key == 'rowid') {
  632. print $object->showOutputField($val, $key, $object->id, '');
  633. } else {
  634. print $object->showOutputField($val, $key, $object->$key, '');
  635. }
  636. print '</td>';
  637. if (!$i) {
  638. $totalarray['nbfield']++;
  639. }
  640. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  641. if (!$i) {
  642. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  643. }
  644. if (!isset($totalarray['val'])) {
  645. $totalarray['val'] = array();
  646. }
  647. if (!isset($totalarray['val']['t.'.$key])) {
  648. $totalarray['val']['t.'.$key] = 0;
  649. }
  650. $totalarray['val']['t.'.$key] += $object->$key;
  651. }
  652. }
  653. }
  654. // Extra fields
  655. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  656. // Fields from hook
  657. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  658. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  659. print $hookmanager->resPrint;
  660. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  661. print '<td class="right">'.$obj->anotherfield.'</td>';
  662. }*/
  663. // Action column
  664. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  665. print '<td class="nowrap center">';
  666. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  667. $selected = 0;
  668. if (in_array($object->id, $arrayofselected)) {
  669. $selected = 1;
  670. }
  671. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  672. }
  673. print '</td>';
  674. }
  675. if (!$i) {
  676. $totalarray['nbfield']++;
  677. }
  678. print '</tr>'."\n";
  679. }
  680. $i++;
  681. }
  682. // Show total line
  683. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  684. // If no record found
  685. if ($num == 0) {
  686. $colspan = 1;
  687. foreach ($arrayfields as $key => $val) {
  688. if (!empty($val['checked'])) {
  689. $colspan++;
  690. }
  691. }
  692. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  693. }
  694. $db->free($resql);
  695. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  696. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  697. print $hookmanager->resPrint;
  698. print '</table>'."\n";
  699. print '</div>'."\n";
  700. print '</form>'."\n";
  701. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  702. $hidegeneratedfilelistifempty = 1;
  703. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  704. $hidegeneratedfilelistifempty = 0;
  705. }
  706. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  707. $formfile = new FormFile($db);
  708. // Show list of available documents
  709. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  710. $urlsource .= str_replace('&amp;', '&', $param);
  711. $filedir = $diroutputmassaction;
  712. $genallowed = $permissiontoread;
  713. $delallowed = $permissiontoadd;
  714. print $formfile->showdocuments('massfilesarea_bbus', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  715. }
  716. // End of page
  717. llxFooter();
  718. $db->close();