website.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675
  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2005 Brice Davoleau <brice.davoleau@gmail.com>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2006-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  6. * Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
  7. * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/societe/website.php
  26. * \ingroup website
  27. * \brief Page of web sites accounts
  28. */
  29. // Load Dolibarr environment
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  36. // Load translation files required by the page
  37. $langs->loadLangs(array("companies", "website"));
  38. // Get parameters
  39. $id = GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('socid', 'int');
  40. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  41. $show_files = GETPOST('show_files', 'int');
  42. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'websitelist'; // To manage different context of search
  43. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  44. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  45. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  46. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  47. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  48. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  49. $sortfield = GETPOST('sortfield', 'aZ09comma');
  50. $sortorder = GETPOST('sortorder', 'aZ09comma');
  51. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  52. if (empty($page) || $page == -1) {
  53. $page = 0;
  54. } // If $page is not defined, or '' or -1
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. if (!$sortfield) {
  59. $sortfield = 't.login';
  60. }
  61. if (!$sortorder) {
  62. $sortorder = 'ASC';
  63. }
  64. // Initialize technical objects
  65. $object = new Societe($db);
  66. $objectwebsiteaccount = new SocieteAccount($db);
  67. $extrafields = new ExtraFields($db);
  68. $diroutputmassaction = $conf->website->dir_output.'/temp/massgeneration/'.$user->id;
  69. $hookmanager->initHooks(array('websitethirdpartylist')); // Note that conf->hooks_modules contains array
  70. // Fetch optionals attributes and labels
  71. $extrafields->fetch_name_optionals_label($objectwebsiteaccount->table_element);
  72. $search_array_options = $extrafields->getOptionalsFromPost($objectwebsiteaccount->table_element, '', 'search_');
  73. unset($objectwebsiteaccount->fields['fk_soc']); // Remove this field, we are already on the thirdparty
  74. // Initialize array of search criterias
  75. $search_all = GETPOST("search_all", 'alpha');
  76. $search = array();
  77. foreach ($objectwebsiteaccount->fields as $key => $val) {
  78. if (GETPOST('search_'.$key, 'alpha')) {
  79. $search[$key] = GETPOST('search_'.$key, 'alpha');
  80. }
  81. }
  82. // List of fields to search into when doing a "search in all"
  83. $fieldstosearchall = array();
  84. foreach ($objectwebsiteaccount->fields as $key => $val) {
  85. if (!empty($val['searchall'])) {
  86. $fieldstosearchall['t.'.$key] = $val['label'];
  87. }
  88. }
  89. // Definition of fields for list
  90. $arrayfields = array();
  91. foreach ($objectwebsiteaccount->fields as $key => $val) {
  92. // If $val['visible']==0, then we never show the field
  93. if (!empty($val['visible'])) {
  94. $arrayfields['t.'.$key] = array('label'=>$val['label'], 'checked'=>(($val['visible'] < 0) ? 0 : 1), 'enabled'=>$val['enabled']);
  95. }
  96. }
  97. // Extra fields
  98. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  99. $object->fields = dol_sort_array($object->fields, 'position');
  100. $arrayfields = dol_sort_array($arrayfields, 'position');
  101. if ($id > 0) {
  102. $result = $object->fetch($id);
  103. }
  104. // Security check
  105. $id = GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('socid', 'int');
  106. if ($user->socid) {
  107. $id = $user->socid;
  108. }
  109. $result = restrictedArea($user, 'societe', $object->id, '&societe');
  110. /*
  111. * Actions
  112. */
  113. $parameters = array('id'=>$id);
  114. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  115. if ($reshook < 0) {
  116. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  117. }
  118. if (empty($reshook)) {
  119. // Cancel
  120. if (GETPOST('cancel', 'alpha') && !empty($backtopage)) {
  121. header("Location: ".$backtopage);
  122. exit;
  123. }
  124. // Selection of new fields
  125. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  126. // Purge search criteria
  127. 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
  128. foreach ($objectwebsiteaccount->fields as $key => $val) {
  129. $search[$key] = '';
  130. }
  131. $toselect = array();
  132. $search_array_options = array();
  133. }
  134. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  135. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  136. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  137. }
  138. // Mass actions
  139. $objectclass = 'WebsiteAccount';
  140. $objectlabel = 'WebsiteAccount';
  141. $permissiontoread = $user->hasRight('societe', 'lire');
  142. $permissiontodelete = $user->hasRight('societe', 'supprimer');
  143. $uploaddir = $conf->societe->multidir_output[$object->entity];
  144. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  145. }
  146. /*
  147. * View
  148. */
  149. $contactstatic = new Contact($db);
  150. $form = new Form($db);
  151. $langs->load("companies");
  152. $title = $langs->trans("WebsiteAccounts");
  153. llxHeader('', $title);
  154. $param = '';
  155. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  156. $param .= '&contextpage='.urlencode($contextpage);
  157. }
  158. if ($id > 0) {
  159. $param .= '&id='.urlencode($id);
  160. }
  161. if ($limit > 0 && $limit != $conf->liste_limit) {
  162. $param .= '&limit='.((int) $limit);
  163. }
  164. foreach ($search as $key => $val) {
  165. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  166. }
  167. if ($optioncss != '') {
  168. $param .= '&optioncss='.urlencode($optioncss);
  169. }
  170. // Add $param from extra fields
  171. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  172. $head = societe_prepare_head($object);
  173. print dol_get_fiche_head($head, 'website', $langs->trans("ThirdParty"), - 1, 'company');
  174. $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  175. dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
  176. print '<div class="fichecenter">';
  177. print '<div class="underbanner clearboth"></div>';
  178. print '<table class="border centpercent">';
  179. // Prefix
  180. if (getDolGlobalString('SOCIETE_USEPREFIX')) { // Old not used prefix field
  181. print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>';
  182. }
  183. if ($object->client) {
  184. print '<tr><td class="titlefield">';
  185. print $langs->trans('CustomerCode').'</td><td colspan="3">';
  186. print $object->code_client;
  187. $tmpcheck = $object->check_codeclient();
  188. if ($tmpcheck != 0 && $tmpcheck != -5) {
  189. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  190. }
  191. print '</td></tr>';
  192. }
  193. if ($object->fournisseur) {
  194. print '<tr><td class="titlefield">';
  195. print $langs->trans('SupplierCode').'</td><td colspan="3">';
  196. print $object->code_fournisseur;
  197. $tmpcheck = $object->check_codefournisseur();
  198. if ($tmpcheck != 0 && $tmpcheck != -5) {
  199. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  200. }
  201. print '</td></tr>';
  202. }
  203. print '</table>';
  204. print '</div>';
  205. print dol_get_fiche_end();
  206. $newcardbutton = '';
  207. if (isModEnabled('website') || isModEnabled('webportal')) {
  208. if ($user->hasRight('societe', 'lire')) {
  209. $newcardbutton .= dolGetButtonTitle($langs->trans("AddWebsiteAccount"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id));
  210. } else {
  211. $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/website/websiteaccount_card.php?action=create&fk_soc='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?id='.$object->id), '', 0);
  212. }
  213. }
  214. print '<br>';
  215. // Build and execute select
  216. // --------------------------------------------------------------------
  217. $site_filter_list = array();
  218. if (isModEnabled('website')) {
  219. $site_filter_list[] = 'dolibarr_website';
  220. }
  221. if (isModEnabled('webportal')) {
  222. $site_filter_list[] = 'dolibarr_portal';
  223. }
  224. $sql = 'SELECT ';
  225. foreach ($objectwebsiteaccount->fields as $key => $val) {
  226. $sql .= "t.".$key.", ";
  227. }
  228. // Add fields from extrafields
  229. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  230. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  231. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key." as options_".$key.', ' : '');
  232. }
  233. }
  234. // Add fields from hooks
  235. $parameters = array();
  236. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $objectwebsiteaccount); // Note that $action and $object may have been modified by hook
  237. $sql .= $hookmanager->resPrint;
  238. $sql = preg_replace('/, $/', '', $sql);
  239. $sql .= " FROM ".MAIN_DB_PREFIX."societe_account as t";
  240. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  241. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  242. }
  243. if ($objectwebsiteaccount->ismultientitymanaged == 1) {
  244. $sql .= " WHERE t.entity IN (".getEntity('thirdpartyaccount').")";
  245. } else {
  246. $sql .= " WHERE 1 = 1";
  247. }
  248. $sql .= " AND fk_soc = ".((int) $object->id);
  249. if (!empty($site_filter_list)) {
  250. $sql .= " AND t.site IN (".$db->sanitize("'".implode("','", $site_filter_list)."'", 1).")";
  251. }
  252. foreach ($search as $key => $val) {
  253. $mode_search = (($objectwebsiteaccount->isInt($objectwebsiteaccount->fields[$key]) || $objectwebsiteaccount->isFloat($objectwebsiteaccount->fields[$key])) ? 1 : 0);
  254. if ($search[$key] != '') {
  255. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  256. }
  257. }
  258. if ($search_all) {
  259. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  260. }
  261. // Add where from extra fields
  262. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  263. // Add where from hooks
  264. $parameters = array();
  265. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $objectwebsiteaccount); // Note that $action and $objectwebsiteaccount may have been modified by hook
  266. $sql .= $hookmanager->resPrint;
  267. /* If a group by is required
  268. $sql.= " GROUP BY "
  269. foreach($objectwebsiteaccount->fields as $key => $val)
  270. {
  271. $sql .= "t.".$key.", ";
  272. }
  273. // Add fields from extrafields
  274. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  275. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  276. // Add where from hooks
  277. $parameters=array();
  278. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $objectwebsiteaccount may have been modified by hook
  279. $sql.=$hookmanager->resPrint;
  280. */
  281. $sql .= $db->order($sortfield, $sortorder);
  282. // Count total nb of records
  283. $nbtotalofrecords = '';
  284. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  285. $result = $db->query($sql);
  286. $nbtotalofrecords = $db->num_rows($result);
  287. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  288. $page = 0;
  289. $offset = 0;
  290. }
  291. }
  292. $sql .= $db->plimit($limit + 1, $offset);
  293. $resql = $db->query($sql);
  294. if (!$resql) {
  295. dol_print_error($db);
  296. exit;
  297. }
  298. $num = $db->num_rows($resql);
  299. $arrayofselected = is_array($toselect) ? $toselect : array();
  300. // List of mass actions available
  301. $arrayofmassactions = array(
  302. //'presend'=>$langs->trans("SendByMail"),
  303. //'builddoc'=>$langs->trans("PDFMerge"),
  304. );
  305. if ($user->hasRight('mymodule', 'delete')) {
  306. $arrayofmassactions['predelete'] = '<span class="fa fa-trash paddingrightonly"></span>'.$langs->trans("Delete");
  307. }
  308. if (in_array($massaction, array('presend', 'predelete'))) {
  309. $arrayofmassactions = array();
  310. }
  311. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  312. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  313. if ($optioncss != '') {
  314. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  315. }
  316. print '<input type="hidden" name="token" value="'.newToken().'">';
  317. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  318. print '<input type="hidden" name="action" value="list">';
  319. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  320. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  321. print '<input type="hidden" name="page" value="'.$page.'">';
  322. print '<input type="hidden" name="id" value="'.$id.'">';
  323. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  324. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
  325. $topicmail = "Information";
  326. $modelmail = "societeaccount";
  327. $objecttmp = new SocieteAccount($db);
  328. $trackid = 'thi'.$object->id;
  329. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  330. /*if ($sall)
  331. {
  332. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  333. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'</div>';
  334. }*/
  335. $moreforfilter = '';
  336. /*$moreforfilter.='<div class="divsearchfield">';
  337. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  338. $moreforfilter.= '</div>';*/
  339. $parameters = array();
  340. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $objectwebsiteaccount); // Note that $action and $objectwebsiteaccount may have been modified by hook
  341. if (empty($reshook)) {
  342. $moreforfilter .= $hookmanager->resPrint;
  343. } else {
  344. $moreforfilter = $hookmanager->resPrint;
  345. }
  346. if (!empty($moreforfilter)) {
  347. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  348. print $moreforfilter;
  349. print '</div>';
  350. }
  351. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  352. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  353. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  354. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  355. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  356. // Fields title search
  357. // --------------------------------------------------------------------
  358. print '<tr class="liste_titre">';
  359. // Action column
  360. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  361. print '<td class="liste_titre center maxwidthsearch">';
  362. $searchpicto = $form->showFilterButtons('left');
  363. print $searchpicto;
  364. print '</td>';
  365. }
  366. foreach ($objectwebsiteaccount->fields as $key => $val) {
  367. $align = '';
  368. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  369. $align = 'center';
  370. }
  371. if (in_array($val['type'], array('timestamp'))) {
  372. $align .= ' nowrap';
  373. }
  374. if ($key == 'status') {
  375. $align .= ($align ? ' ' : '').'center';
  376. }
  377. if (!empty($arrayfields['t.'.$key]['checked'])) {
  378. print '<td class="liste_titre'.($align ? ' '.$align : '').'"><input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(empty($search[$key]) ? '' : $search[$key]).'"></td>';
  379. }
  380. }
  381. // Extra fields
  382. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  383. // Fields from hook
  384. $parameters = array('arrayfields'=>$arrayfields);
  385. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $objectwebsiteaccount); // Note that $action and $object may have been modified by hook
  386. print $hookmanager->resPrint;
  387. // Action column
  388. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  389. print '<td class="liste_titre maxwidthsearch">';
  390. $searchpicto = $form->showFilterButtons();
  391. print $searchpicto;
  392. print '</td>';
  393. }
  394. print '</tr>'."\n";
  395. $totalarray = array();
  396. $totalarray['nbfield'] = 0;
  397. // Fields title label
  398. // --------------------------------------------------------------------
  399. print '<tr class="liste_titre">';
  400. // Action column
  401. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  402. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  403. $totalarray['nbfield']++;
  404. }
  405. foreach ($objectwebsiteaccount->fields as $key => $val) {
  406. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  407. if ($key == 'status') {
  408. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  409. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  410. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  411. } elseif (in_array($val['type'], array('timestamp'))) {
  412. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  413. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  414. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  415. }
  416. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  417. if (!empty($arrayfields['t.'.$key]['checked'])) {
  418. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
  419. $totalarray['nbfield']++;
  420. }
  421. }
  422. // Extra fields
  423. // Extra fields
  424. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  425. // Hook fields
  426. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  427. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $objectwebsiteaccount); // Note that $action and $object may have been modified by hook
  428. print $hookmanager->resPrint;
  429. // Action column
  430. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  431. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'maxwidthsearch center ')."\n";
  432. $totalarray['nbfield']++;
  433. }
  434. print '</tr>'."\n";
  435. // Detect if we need a fetch on each output line
  436. $needToFetchEachLine = 0;
  437. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  438. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  439. if (!is_null($val) && preg_match('/\$object/', $val)) {
  440. $needToFetchEachLine++; // There is at least one compute field that use $object
  441. }
  442. }
  443. }
  444. // Loop on record
  445. // --------------------------------------------------------------------
  446. $i = 0;
  447. $totalarray = array('nbfield' => 0);
  448. while ($i < min($num, $limit)) {
  449. $obj = $db->fetch_object($resql);
  450. if (empty($obj)) {
  451. break; // Should not happen
  452. }
  453. // Store properties in $object
  454. $objectwebsiteaccount->id = $obj->rowid;
  455. $objectwebsiteaccount->login = $obj->login;
  456. $objectwebsiteaccount->ref = $obj->login;
  457. foreach ($objectwebsiteaccount->fields as $key => $val) {
  458. if (property_exists($objectwebsiteaccount, $key)) {
  459. $objectwebsiteaccount->$key = $obj->$key;
  460. }
  461. }
  462. // Show here line of result
  463. print '<tr class="oddeven">';
  464. // Action column
  465. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  466. print '<td class="nowrap center">';
  467. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  468. $selected = 0;
  469. if (in_array($obj->rowid, $arrayofselected)) {
  470. $selected = 1;
  471. }
  472. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  473. }
  474. print '</td>';
  475. if (!$i) {
  476. $totalarray['nbfield']++;
  477. }
  478. }
  479. foreach ($objectwebsiteaccount->fields as $key => $val) {
  480. $align = '';
  481. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  482. $align = 'center';
  483. }
  484. if (in_array($val['type'], array('timestamp'))) {
  485. $align .= 'nowrap';
  486. }
  487. if ($key == 'status') {
  488. $align .= ($align ? ' ' : '').'center';
  489. }
  490. if (!empty($arrayfields['t.'.$key]['checked'])) {
  491. print '<td';
  492. if ($align) {
  493. print ' class="'.$align.'"';
  494. }
  495. print '>';
  496. if ($key == 'login') {
  497. print $objectwebsiteaccount->getNomUrl(1, '', 0, '', 1);
  498. } else {
  499. print $objectwebsiteaccount->showOutputField($val, $key, $obj->$key, '');
  500. }
  501. print '</td>';
  502. if (!$i) {
  503. $totalarray['nbfield']++;
  504. }
  505. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  506. if (!$i) {
  507. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  508. }
  509. if (!isset($totalarray['val'])) {
  510. $totalarray['val'] = array();
  511. }
  512. if (!isset($totalarray['val']['t.'.$key])) {
  513. $totalarray['val']['t.'.$key] = 0;
  514. }
  515. $totalarray['val']['t.'.$key] += $objectwebsiteaccount->$key;
  516. }
  517. }
  518. }
  519. // Extra fields
  520. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  521. // Fields from hook
  522. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  523. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $objectwebsiteaccount); // Note that $action and $object may have been modified by hook
  524. print $hookmanager->resPrint;
  525. // Action column
  526. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  527. print '<td class="nowrap center">';
  528. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  529. $selected = 0;
  530. if (in_array($obj->rowid, $arrayofselected)) {
  531. $selected = 1;
  532. }
  533. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  534. }
  535. print '</td>';
  536. if (!$i) {
  537. $totalarray['nbfield']++;
  538. }
  539. }
  540. print '</tr>';
  541. $i++;
  542. }
  543. // Show total line
  544. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  545. // If no record found
  546. if ($num == 0) {
  547. $colspan = 1;
  548. foreach ($arrayfields as $key => $val) {
  549. if (!empty($val['checked'])) {
  550. $colspan++;
  551. }
  552. }
  553. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  554. }
  555. $db->free($resql);
  556. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  557. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $objectwebsiteaccount); // Note that $action and $object may have been modified by hook
  558. print $hookmanager->resPrint;
  559. print '</table>'."\n";
  560. print '</div>'."\n";
  561. print '</form>'."\n";
  562. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  563. $hidegeneratedfilelistifempty = 1;
  564. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  565. $hidegeneratedfilelistifempty = 0;
  566. }
  567. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  568. $formfile = new FormFile($db);
  569. // Show list of available documents
  570. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  571. $urlsource .= str_replace('&amp;', '&', $param);
  572. $filedir = $diroutputmassaction;
  573. $genallowed = $user->rights->mymodule->read;
  574. $delallowed = $user->rights->mymodule->create;
  575. print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  576. }
  577. // End of page
  578. llxFooter();
  579. $db->close();