website.php 22 KB

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