website.php 23 KB

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