partnership_list.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 NextGestion <contact@nextgestion.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file partnership_list.php
  20. * \ingroup partnership
  21. * \brief List page for partnership
  22. */
  23. // Load Dolibarr environment
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/member.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/partnership/class/partnership.class.php';
  33. // for other modules
  34. //dol_include_once('/othermodule/class/otherobject.class.php');
  35. // Load translation files required by the page
  36. $langs->loadLangs(array("partnership", "members", "other"));
  37. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'create'/'add', 'edit'/'update', 'view', ...
  38. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  39. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  40. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  41. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  42. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  43. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
  44. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  45. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  46. $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
  47. $id = GETPOST('id', 'int');
  48. $socid = GETPOST('socid', 'int');
  49. $memberid = GETPOST('rowid', 'int');
  50. // Load variable for pagination
  51. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  52. $sortfield = GETPOST('sortfield', 'aZ09comma');
  53. $sortorder = GETPOST('sortorder', 'aZ09comma');
  54. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  55. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  56. // If $page is not defined, or '' or -1 or if we click on clear filters
  57. $page = 0;
  58. }
  59. $offset = $limit * $page;
  60. $pageprev = $page - 1;
  61. $pagenext = $page + 1;
  62. // Initialize technical objects
  63. $object = new Partnership($db);
  64. $extrafields = new ExtraFields($db);
  65. $adherent = new Adherent($db);
  66. $diroutputmassaction = $conf->partnership->dir_output.'/temp/massgeneration/'.$user->id;
  67. if ($socid > 0) {
  68. $hookmanager->initHooks(array('thirdpartypartnership', 'globalcard'));
  69. } elseif ($memberid > 0) {
  70. $hookmanager->initHooks(array('memberpartnership', 'globalcard'));
  71. } else {
  72. $hookmanager->initHooks(array('partnershiplist')); // Note that conf->hooks_modules contains array
  73. }
  74. // Fetch optionals attributes and labels
  75. $extrafields->fetch_name_optionals_label($object->table_element);
  76. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  77. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  78. $error = 0;
  79. $managedfor = getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty');
  80. if ($managedfor != 'member' && $sortfield == 'd.datefin') {
  81. $sortfield = '';
  82. }
  83. // Default sort order (if not yet defined by previous GETPOST)
  84. if (!$sortfield) {
  85. reset($object->fields); // Reset is required to avoid key() to return null.
  86. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  87. }
  88. if (!$sortorder) {
  89. $sortorder = "ASC";
  90. }
  91. // Initialize array of search criterias
  92. $search_all = GETPOST('search_all', 'alphanohtml');
  93. $search = array();
  94. foreach ($object->fields as $key => $val) {
  95. if (GETPOST('search_'.$key, 'alpha') !== '') {
  96. $search[$key] = GETPOST('search_'.$key, 'alpha');
  97. }
  98. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  99. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  100. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  101. }
  102. }
  103. $search_filter = GETPOST("search_filter", 'alpha');
  104. $filter = GETPOST("filter", 'alpha');
  105. if ($filter) {
  106. $search_filter = $filter; // For backward compatibility
  107. }
  108. // List of fields to search into when doing a "search in all"
  109. $fieldstosearchall = array();
  110. foreach ($object->fields as $key => $val) {
  111. if (!empty($val['searchall'])) {
  112. $fieldstosearchall['t.'.$key] = $val['label'];
  113. }
  114. }
  115. // Definition of array of fields for columns
  116. $arrayfields = array();
  117. foreach ($object->fields as $key => $val) {
  118. // If $val['visible']==0, then we never show the field
  119. if (!empty($val['visible'])) {
  120. $visible = (int) dol_eval($val['visible'], 1);
  121. $arrayfields['t.'.$key] = array(
  122. 'label'=>$val['label'],
  123. 'checked'=>(($visible < 0) ? 0 : 1),
  124. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  125. 'position'=>$val['position'],
  126. 'help'=> isset($val['help']) ? $val['help'] : ''
  127. );
  128. }
  129. }
  130. // Extra fields
  131. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  132. $object->fields = dol_sort_array($object->fields, 'position');
  133. $arrayfields = dol_sort_array($arrayfields, 'position');
  134. $permissiontoread = $user->rights->partnership->read;
  135. $permissiontoadd = $user->rights->partnership->write;
  136. $permissiontodelete = $user->rights->partnership->delete;
  137. // Security check - Protection if external user
  138. //if ($user->socid > 0) accessforbidden();
  139. //if ($user->socid > 0) $socid = $user->socid;
  140. //$result = restrictedArea($user, 'partnership', $object->id);
  141. if (empty($conf->partnership->enabled)) {
  142. accessforbidden();
  143. }
  144. if (empty($permissiontoread)) {
  145. accessforbidden();
  146. }
  147. if ($object->id > 0 && !($object->fk_member > 0) && $managedfor == 'member') {
  148. accessforbidden();
  149. }
  150. if ($object->id > 0 && !($object->fk_soc > 0) && $managedfor == 'thirdparty') {
  151. accessforbidden();
  152. }
  153. /*
  154. * Actions
  155. */
  156. if (GETPOST('cancel', 'alpha')) {
  157. $action = 'list';
  158. $massaction = '';
  159. }
  160. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  161. $massaction = '';
  162. }
  163. $parameters = array();
  164. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  165. if ($reshook < 0) {
  166. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  167. }
  168. if (empty($reshook)) {
  169. // Selection of new fields
  170. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  171. // Purge search criteria
  172. 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
  173. foreach ($object->fields as $key => $val) {
  174. $search[$key] = '';
  175. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  176. $search[$key.'_dtstart'] = '';
  177. $search[$key.'_dtend'] = '';
  178. }
  179. }
  180. $toselect = array();
  181. $search_array_options = array();
  182. }
  183. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  184. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  185. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  186. }
  187. // Mass actions
  188. $objectclass = 'Partnership';
  189. $objectlabel = 'Partnership';
  190. $uploaddir = $conf->partnership->dir_output;
  191. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  192. // Validate and approve
  193. if (!$error && $massaction == 'approve' && $permissiontoadd) {
  194. $objecttmp = new Partnership($db);
  195. $db->begin();
  196. $error = 0;
  197. $result = 0;
  198. foreach ($toselect as $checked) {
  199. if ($objecttmp->fetch($checked)) {
  200. if ($objecttmp->status == $objecttmp::STATUS_DRAFT) {
  201. //$objecttmp->date = dol_now();
  202. $result = $objecttmp->validate($user);
  203. }
  204. if ($result >= 0 && $objecttmp->status == $objecttmp::STATUS_VALIDATED) {
  205. $result = $objecttmp->approve($user);
  206. if ($result > 0) {
  207. setEventMessages($langs->trans("PartnershipRefApproved", $objecttmp->ref), null);
  208. } else {
  209. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  210. $error++;
  211. }
  212. } else {
  213. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  214. $error++;
  215. }
  216. }
  217. }
  218. if (!$error) {
  219. $db->commit();
  220. } else {
  221. $db->rollback();
  222. }
  223. }
  224. // Cancel partnership
  225. if ($massaction == 'cancel' && $permissiontoadd) {
  226. $db->begin();
  227. $objecttmp = new $objectclass($db);
  228. $nbok = 0;
  229. foreach ($toselect as $toselectid) {
  230. $result = $objecttmp->fetch($toselectid);
  231. if ($result > 0) {
  232. $result = $objecttmp->cancel($user, 0);
  233. if ($result == 0) {
  234. setEventMessages($langs->trans('StatusOfRefMustBe', $objecttmp->ref, $objecttmp->LibStatut($objecttmp::STATUS_APPROVED)), null, 'warnings');
  235. $error++;
  236. } elseif ($result <= 0) {
  237. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  238. $error++;
  239. break;
  240. } else {
  241. $nbok++;
  242. }
  243. } else {
  244. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  245. $error++;
  246. break;
  247. }
  248. }
  249. if (!$error) {
  250. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  251. $db->commit();
  252. } else {
  253. $db->rollback();
  254. }
  255. }
  256. }
  257. /*
  258. * View
  259. */
  260. $form = new Form($db);
  261. $companystatic = new Societe($db);
  262. $now = dol_now();
  263. //$help_url="EN:Module_Partnership|FR:Module_Partnership_FR|ES:Módulo_Partnership";
  264. $help_url = '';
  265. $title = $langs->trans("Partnerships");
  266. $morejs = array();
  267. $morecss = array();
  268. // Build and execute select
  269. // --------------------------------------------------------------------
  270. $sql = 'SELECT ';
  271. $sql .= $object->getFieldList('t');
  272. if ($managedfor == 'member') {
  273. $sql .= ', d.datefin, d.fk_adherent_type, dty.subscription';
  274. }
  275. // Add fields from extrafields
  276. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  277. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  278. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  279. }
  280. }
  281. // Add fields from hooks
  282. $parameters = array();
  283. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  284. $sql .= $hookmanager->resPrint;
  285. $sql = preg_replace('/,\s*$/', '', $sql);
  286. $sqlfields = $sql; // $sql fields to remove for count total
  287. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  288. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  289. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  290. }
  291. if ($managedfor == 'member') {
  292. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent as d on (d.rowid = t.fk_member)";
  293. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."adherent_type as dty on (dty.rowid = d.fk_adherent_type)";
  294. }
  295. // Add table from hooks
  296. $parameters = array();
  297. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  298. $sql .= $hookmanager->resPrint;
  299. if ($object->ismultientitymanaged == 1) {
  300. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  301. } else {
  302. $sql .= " WHERE 1 = 1";
  303. }
  304. if ($managedfor == 'member') {
  305. if ($memberid > 0) {
  306. $sql .= " AND t.fk_member = ".((int) $memberid);
  307. } else {
  308. $sql .= " AND fk_member > 0";
  309. }
  310. } else {
  311. if ($socid > 0) {
  312. $sql .= " AND t.fk_soc = ".((int) $socid);
  313. } else {
  314. $sql .= " AND fk_soc > 0";
  315. }
  316. }
  317. foreach ($search as $key => $val) {
  318. if (array_key_exists($key, $object->fields)) {
  319. if ($key == 'status' && $search[$key] == -1) {
  320. continue;
  321. }
  322. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  323. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  324. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  325. $search[$key] = '';
  326. }
  327. $mode_search = 2;
  328. }
  329. if ($search[$key] != '') {
  330. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  331. }
  332. } else {
  333. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  334. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  335. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  336. if (preg_match('/_dtstart$/', $key)) {
  337. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  338. }
  339. if (preg_match('/_dtend$/', $key)) {
  340. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  341. }
  342. }
  343. }
  344. }
  345. }
  346. if ($managedfor == 'member') {
  347. if ($search_filter == 'withoutsubscription') {
  348. $sql .= " AND (d.datefin IS NULL)";
  349. }
  350. if ($search_filter == 'waitingsubscription') {
  351. $sql .= " AND (d.datefin IS NULL AND t.subscription = '1')";
  352. }
  353. if ($search_filter == 'uptodate') {
  354. $sql .= " AND (d.datefin >= '".$db->idate($now)."' OR dty.subscription = '0')";
  355. }
  356. if ($search_filter == 'outofdate') {
  357. $sql .= " AND (d.datefin < '".$db->idate($now)."' AND dty.subscription = '1')";
  358. }
  359. }
  360. if ($search_all) {
  361. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  362. }
  363. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  364. // Add where from extra fields
  365. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  366. // Add where from hooks
  367. $parameters = array();
  368. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  369. $sql .= $hookmanager->resPrint;
  370. /* If a group by is required
  371. $sql.= " GROUP BY ";
  372. foreach($object->fields as $key => $val) {
  373. $sql .= "t.".$db->escape($key).", ";
  374. }
  375. // Add fields from extrafields
  376. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  377. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  378. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  379. }
  380. }
  381. // Add where from hooks
  382. $parameters=array();
  383. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
  384. $sql.=$hookmanager->resPrint;
  385. $sql=preg_replace('/,\s*$/','', $sql);
  386. */
  387. // Count total nb of records
  388. $nbtotalofrecords = '';
  389. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  390. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  391. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  392. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  393. $resql = $db->query($sqlforcount);
  394. if ($resql) {
  395. $objforcount = $db->fetch_object($resql);
  396. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  397. } else {
  398. dol_print_error($db);
  399. }
  400. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  401. $page = 0;
  402. $offset = 0;
  403. }
  404. $db->free($resql);
  405. }
  406. // Complete request and execute it with limit
  407. $sql .= $db->order($sortfield, $sortorder);
  408. if ($limit) {
  409. $sql .= $db->plimit($limit + 1, $offset);
  410. }
  411. $resql = $db->query($sql);
  412. if (!$resql) {
  413. dol_print_error($db);
  414. exit;
  415. }
  416. $num = $db->num_rows($resql);
  417. // Direct jump if only one record found
  418. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  419. $obj = $db->fetch_object($resql);
  420. $id = $obj->rowid;
  421. header("Location: ".dol_buildpath('/partnership/partnership_card.php', 1).'?id='.$id);
  422. exit;
  423. }
  424. // Output page
  425. // --------------------------------------------------------------------
  426. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  427. if ($managedfor == "member") {
  428. if ($memberid > 0 && $user->hasRight('adherent', 'lire')) {
  429. $langs->load("members");
  430. $adhstat = new Adherent($db);
  431. $adht = new AdherentType($db);
  432. $result = $adhstat->fetch($memberid);
  433. if (isModEnabled('notification')) {
  434. $langs->load("mails");
  435. }
  436. $adht->fetch($adhstat->typeid);
  437. $head = member_prepare_head($adhstat);
  438. print dol_get_fiche_head($head, 'partnerships', $langs->trans("ThirdParty"), -1, 'user');
  439. $linkback = '<a href="'.DOL_URL_ROOT.'/adherents/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  440. dol_banner_tab($object, 'rowid', $linkback);
  441. print '<div class="fichecenter">';
  442. print '<div class="underbanner clearboth"></div>';
  443. print '<table class="border centpercent tableforfield">';
  444. // Login
  445. if (!getDolGlobalString('ADHERENT_LOGIN_NOT_REQUIRED')) {
  446. print '<tr><td class="titlefield">'.$langs->trans("Login").' / '.$langs->trans("Id").'</td><td class="valeur">'.$object->login.'&nbsp;</td></tr>';
  447. }
  448. // Type
  449. print '<tr><td class="titlefield">'.$langs->trans("Type").'</td><td class="valeur">'.$adht->getNomUrl(1)."</td></tr>\n";
  450. // Morphy
  451. print '<tr><td>'.$langs->trans("MemberNature").'</td><td class="valeur" >'.$adhstat->getmorphylib().'</td>';
  452. print '</tr>';
  453. // Company
  454. print '<tr><td>'.$langs->trans("Company").'</td><td class="valeur">'.$adhstat->company.'</td></tr>';
  455. // Civility
  456. print '<tr><td>'.$langs->trans("UserTitle").'</td><td class="valeur">'.$adhstat->getCivilityLabel().'&nbsp;</td>';
  457. print '</tr>';
  458. print '</table>';
  459. print '</div>';
  460. print dol_get_fiche_end();
  461. }
  462. } elseif ($managedfor == "thirdparty") {
  463. if ($socid && $user->hasRight('societe', 'lire')) {
  464. $socstat = new Societe($db);
  465. $res = $socstat->fetch($socid);
  466. if ($res > 0) {
  467. $tmpobject = $object;
  468. $object = $socstat; // $object must be of type Societe when calling societe_prepare_head
  469. $head = societe_prepare_head($socstat);
  470. $object = $tmpobject;
  471. print dol_get_fiche_head($head, 'partnerships', $langs->trans("ThirdParty"), -1, 'company');
  472. dol_banner_tab($socstat, 'socid', '', ($user->socid ? 0 : 1), 'rowid', 'nom');
  473. print '<div class="fichecenter">';
  474. print '<div class="underbanner clearboth"></div>';
  475. print '<table class="border centpercent tableforfield">';
  476. // Type Prospect/Customer/Supplier
  477. print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
  478. print $socstat->getTypeUrl(1);
  479. print '</td></tr>';
  480. // Customer code
  481. if ($socstat->client && !empty($socstat->code_client)) {
  482. print '<tr><td class="titlefield">';
  483. print $langs->trans('CustomerCode').'</td><td>';
  484. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_client));
  485. $tmpcheck = $socstat->check_codeclient();
  486. if ($tmpcheck != 0 && $tmpcheck != -5) {
  487. print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
  488. }
  489. print '</td>';
  490. print '</tr>';
  491. }
  492. // Supplier code
  493. if ($socstat->fournisseur && !empty($socstat->code_fournisseur)) {
  494. print '<tr><td class="titlefield">';
  495. print $langs->trans('SupplierCode').'</td><td>';
  496. print showValueWithClipboardCPButton(dol_escape_htmltag($socstat->code_fournisseur));
  497. $tmpcheck = $socstat->check_codefournisseur();
  498. if ($tmpcheck != 0 && $tmpcheck != -5) {
  499. print ' <span class="error">('.$langs->trans("WrongSupplierCode").')</span>';
  500. }
  501. print '</td>';
  502. print '</tr>';
  503. }
  504. print '</table>';
  505. print '</div>';
  506. print dol_get_fiche_end();
  507. }
  508. }
  509. }
  510. $arrayofselected = is_array($toselect) ? $toselect : array();
  511. $param = '';
  512. if (!empty($mode)) {
  513. $param .= '&mode='.urlencode($mode);
  514. }
  515. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  516. $param .= '&contextpage='.urlencode($contextpage);
  517. }
  518. if ($limit > 0 && $limit != $conf->liste_limit) {
  519. $param .= '&limit='.((int) $limit);
  520. }
  521. if ($socid) {
  522. $param .= '&socid='.urlencode($socid);
  523. }
  524. if ($memberid) {
  525. $param .= '&rowid='.urlencode($memberid);
  526. }
  527. foreach ($search as $key => $val) {
  528. if (is_array($search[$key])) {
  529. foreach ($search[$key] as $skey) {
  530. if ($skey != '') {
  531. $param .= '&search_'.$key.'[]='.urlencode($skey);
  532. }
  533. }
  534. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  535. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  536. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  537. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  538. } elseif ($search[$key] != '') {
  539. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  540. }
  541. }
  542. if ($optioncss != '') {
  543. $param .= '&optioncss='.urlencode($optioncss);
  544. }
  545. if ($search_filter && $search_filter != '-1') {
  546. $param .= "&search_filter=".urlencode($search_filter);
  547. }
  548. // Add $param from extra fields
  549. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  550. // Add $param from hooks
  551. $parameters = array();
  552. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  553. $param .= $hookmanager->resPrint;
  554. // List of mass actions available
  555. $arrayofmassactions = array(
  556. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  557. 'approve'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("ValidateAndApprove"),
  558. 'cancel'=>img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Cancel"),
  559. //'generate_doc'=>img_picto('', 'pdf').$langs->trans("ReGeneratePDF"),
  560. //'builddoc'=>img_picto('', 'pdf').$langs->trans("PDFMerge"),
  561. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendMail"),
  562. );
  563. if ($permissiontodelete) {
  564. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  565. }
  566. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('prevalidate', 'presend', 'predelete'))) {
  567. $arrayofmassactions = array();
  568. }
  569. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  570. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  571. if ($optioncss != '') {
  572. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  573. }
  574. print '<input type="hidden" name="token" value="'.newToken().'">';
  575. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  576. print '<input type="hidden" name="action" value="list">';
  577. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  578. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  579. print '<input type="hidden" name="page" value="'.$page.'">';
  580. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  581. print '<input type="hidden" name="page_y" value="">';
  582. print '<input type="hidden" name="mode" value="'.$mode.'">';
  583. if ($socid) {
  584. print '<input type="hidden" name="socid" value="'.$socid.'" >';
  585. } elseif ($memberid) {
  586. print '<input type="hidden" name="rowid" value="'.$memberid.'" >';
  587. }
  588. $newcardbutton = '';
  589. $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'));
  590. $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'));
  591. $newcardbutton .= dolGetButtonTitleSeparator();
  592. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/partnership/partnership_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  593. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  594. // Add code for pre mass action (confirmation or email presend form)
  595. $topicmail = "SendPartnershipRef";
  596. $modelmail = "partnership_send";
  597. $objecttmp = new Partnership($db);
  598. $trackid = 'pship'.$object->id;
  599. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  600. if ($search_all) {
  601. $setupstring = '';
  602. foreach ($fieldstosearchall as $key => $val) {
  603. $fieldstosearchall[$key] = $langs->trans($val);
  604. $setupstring .= $key."=".$val.";";
  605. }
  606. print '<!-- Search done like if PARTNERSHIP_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  607. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  608. }
  609. $moreforfilter = '';
  610. /*$moreforfilter.='<div class="divsearchfield">';
  611. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  612. $moreforfilter.= '</div>';*/
  613. $parameters = array();
  614. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  615. if (empty($reshook)) {
  616. $moreforfilter .= $hookmanager->resPrint;
  617. } else {
  618. $moreforfilter = $hookmanager->resPrint;
  619. }
  620. if (!empty($moreforfilter)) {
  621. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  622. print $moreforfilter;
  623. $parameters = array('type'=>$type);
  624. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  625. print $hookmanager->resPrint;
  626. print '</div>';
  627. }
  628. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  629. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  630. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  631. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  632. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  633. if ($managedfor == 'member') {
  634. $arrayfields['t.fk_member']['checked'] = 1;
  635. } else {
  636. $arrayfields['t.fk_soc']['checked'] = 1;
  637. }
  638. // Fields title search
  639. // --------------------------------------------------------------------
  640. print '<tr class="liste_titre_filter">';
  641. // Action column
  642. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  643. print '<td class="liste_titre maxwidthsearch">';
  644. $searchpicto = $form->showFilterButtons('left');
  645. print $searchpicto;
  646. print '</td>';
  647. }
  648. foreach ($object->fields as $key => $val) {
  649. $searchkey = empty($search[$key]) ? '' : $search[$key];
  650. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  651. if ($key == 'status') {
  652. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  653. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  654. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  655. } elseif (in_array($val['type'], array('timestamp'))) {
  656. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  657. } 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'])) {
  658. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  659. }
  660. if (!empty($arrayfields['t.'.$key]['checked'])) {
  661. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
  662. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  663. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
  664. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  665. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  666. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  667. print '<div class="nowrap">';
  668. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  669. print '</div>';
  670. print '<div class="nowrap">';
  671. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  672. print '</div>';
  673. } elseif ($key == 'lang') {
  674. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  675. $formadmin = new FormAdmin($db);
  676. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  677. } else {
  678. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  679. }
  680. print '</td>';
  681. }
  682. }
  683. // End of subscription date
  684. if ($managedfor == 'member') {
  685. print '<td class="liste_titre center">';
  686. $selectarray = array('-1'=>'', 'withoutsubscription'=>$langs->trans("WithoutSubscription"), 'uptodate'=>$langs->trans("UpToDate"), 'outofdate'=>$langs->trans("OutOfDate"));
  687. print $form->selectarray('search_filter', $selectarray, $search_filter);
  688. print '</td>';
  689. }
  690. // Extra fields
  691. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  692. // Fields from hook
  693. $parameters = array('arrayfields'=>$arrayfields);
  694. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  695. print $hookmanager->resPrint;
  696. // Action column
  697. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  698. print '<td class="liste_titre maxwidthsearch">';
  699. $searchpicto = $form->showFilterButtons();
  700. print $searchpicto;
  701. print '</td>';
  702. }
  703. print '</tr>'."\n";
  704. $totalarray = array();
  705. $totalarray['nbfield'] = 0;
  706. // Fields title label
  707. // --------------------------------------------------------------------
  708. print '<tr class="liste_titre">';
  709. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  710. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  711. $totalarray['nbfield']++; // For the column action
  712. }
  713. foreach ($object->fields as $key => $val) {
  714. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  715. if ($key == 'status') {
  716. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  717. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  718. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  719. } elseif (in_array($val['type'], array('timestamp'))) {
  720. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  721. } 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'])) {
  722. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  723. }
  724. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  725. if (!empty($arrayfields['t.'.$key]['checked'])) {
  726. 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";
  727. $totalarray['nbfield']++;
  728. }
  729. }
  730. // End of subscription date
  731. if ($managedfor == 'member') {
  732. $key = 'datefin';
  733. $cssforfield = 'center';
  734. print getTitleFieldOfList('SubscriptionEndDate', 0, $_SERVER['PHP_SELF'], 'd.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  735. }
  736. // Extra fields
  737. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  738. // Hook fields
  739. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  740. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  741. print $hookmanager->resPrint;
  742. // Action column
  743. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  744. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  745. $totalarray['nbfield']++; // For the column action
  746. }
  747. print '</tr>'."\n";
  748. // Detect if we need a fetch on each output line
  749. $needToFetchEachLine = 0;
  750. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  751. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  752. if (!is_null($val) && preg_match('/\$object/', $val)) {
  753. $needToFetchEachLine++; // There is at least one compute field that use $object
  754. }
  755. }
  756. }
  757. // Loop on record
  758. // --------------------------------------------------------------------
  759. $i = 0;
  760. $savnbfield = $totalarray['nbfield'];
  761. $totalarray = array();
  762. $totalarray['nbfield'] = 0;
  763. $imaxinloop = ($limit ? min($num, $limit) : $num);
  764. while ($i < $imaxinloop) {
  765. $obj = $db->fetch_object($resql);
  766. if (empty($obj)) {
  767. break; // Should not happen
  768. }
  769. // Store properties in $object
  770. $object->setVarsFromFetchObj($obj);
  771. $object->thirdparty = null;
  772. if ($obj->fk_soc > 0) {
  773. if (!empty($conf->cache['thirdparty'][$obj->fk_soc])) {
  774. $companyobj = $conf->cache['thirdparty'][$obj->fk_soc];
  775. } else {
  776. $companyobj = new Societe($db);
  777. $companyobj->fetch($obj->fk_soc);
  778. $conf->cache['thirdparty'][$obj->fk_soc] = $companyobj;
  779. }
  780. $object->thirdparty = $companyobj;
  781. }
  782. if ($mode == 'kanban') {
  783. if ($i == 0) {
  784. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  785. print '<div class="box-flex-container kanban">';
  786. }
  787. // Output Kanban
  788. $selected = -1;
  789. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  790. $selected = 0;
  791. if (in_array($object->id, $arrayofselected)) {
  792. $selected = 1;
  793. }
  794. }
  795. print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
  796. if ($i == ($imaxinloop - 1)) {
  797. print '</div>';
  798. print '</td></tr>';
  799. }
  800. } else {
  801. // Show here line of result
  802. $j = 0;
  803. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  804. // Action column
  805. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  806. print '<td class="nowrap center">';
  807. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  808. $selected = 0;
  809. if (in_array($object->id, $arrayofselected)) {
  810. $selected = 1;
  811. }
  812. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  813. }
  814. print '</td>';
  815. if (!$i) {
  816. $totalarray['nbfield']++;
  817. }
  818. }
  819. foreach ($object->fields as $key => $val) {
  820. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  821. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  822. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  823. } elseif ($key == 'status') {
  824. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  825. }
  826. if (in_array($val['type'], array('timestamp'))) {
  827. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  828. } elseif ($key == 'ref') {
  829. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  830. }
  831. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  832. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  833. }
  834. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  835. if (!empty($arrayfields['t.'.$key]['checked'])) {
  836. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  837. if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
  838. print ' title="'.dol_escape_htmltag($object->$key).'"';
  839. }
  840. print '>';
  841. if ($key == 'status') {
  842. print $object->getLibStatut(5);
  843. } elseif ($key == 'rowid') {
  844. print $object->showOutputField($val, $key, $object->id, '');
  845. } else {
  846. print $object->showOutputField($val, $key, $object->$key, '');
  847. }
  848. print '</td>';
  849. if (!$i) {
  850. $totalarray['nbfield']++;
  851. }
  852. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  853. if (!$i) {
  854. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  855. }
  856. if (!isset($totalarray['val'])) {
  857. $totalarray['val'] = array();
  858. }
  859. if (!isset($totalarray['val']['t.'.$key])) {
  860. $totalarray['val']['t.'.$key] = 0;
  861. }
  862. $totalarray['val']['t.'.$key] += $object->$key;
  863. }
  864. }
  865. }
  866. // End of subscription date
  867. if ($managedfor == 'member') {
  868. print '<td class="nowrap center endofsubscriptiondate">';
  869. $result = $adherent->fetch($object->fk_member);
  870. if ($result) {
  871. $datefin = $adherent->datefin;
  872. if ($datefin) {
  873. print dol_print_date($datefin, 'day');
  874. if ($adherent->hasDelay()) {
  875. $textlate .= ' ('.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($conf->adherent->subscription->warning_delay / 60 / 60 / 24) >= 0 ? '+' : '').ceil($conf->adherent->subscription->warning_delay / 60 / 60 / 24).' '.$langs->trans("days").')';
  876. print " ".img_warning($langs->trans("SubscriptionLate").$textlate);
  877. }
  878. } else {
  879. if ($adherent->subscription == 'yes') {
  880. print $langs->trans("SubscriptionNotReceived");
  881. if ($adherent->statut > 0) {
  882. print " ".img_warning();
  883. }
  884. } else {
  885. print '&nbsp;';
  886. }
  887. }
  888. }
  889. print '</td>';
  890. }
  891. // Extra fields
  892. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  893. // Fields from hook
  894. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  895. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  896. print $hookmanager->resPrint;
  897. // Action column
  898. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  899. print '<td class="nowrap center">';
  900. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  901. $selected = 0;
  902. if (in_array($object->id, $arrayofselected)) {
  903. $selected = 1;
  904. }
  905. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  906. }
  907. print '</td>';
  908. if (!$i) {
  909. $totalarray['nbfield']++;
  910. }
  911. }
  912. print '</tr>'."\n";
  913. }
  914. $i++;
  915. }
  916. if ($managedfor != 'member') {
  917. $totalarray['nbfield']++; // End of subscription date
  918. }
  919. // Show total line
  920. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  921. // If no record found
  922. if ($num == 0) {
  923. $colspan = 1;
  924. foreach ($arrayfields as $key => $val) {
  925. if (!empty($val['checked'])) {
  926. $colspan++;
  927. }
  928. }
  929. if ($managedfor != 'member') {
  930. $colspan++; // End of subscription date
  931. }
  932. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  933. }
  934. $db->free($resql);
  935. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  936. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  937. print $hookmanager->resPrint;
  938. print '</table>'."\n";
  939. print '</div>'."\n";
  940. print '</form>'."\n";
  941. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  942. $hidegeneratedfilelistifempty = 1;
  943. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  944. $hidegeneratedfilelistifempty = 0;
  945. }
  946. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  947. $formfile = new FormFile($db);
  948. // Show list of available documents
  949. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  950. $urlsource .= str_replace('&amp;', '&', $param);
  951. $filedir = $diroutputmassaction;
  952. $genallowed = $permissiontoread;
  953. $delallowed = $permissiontoadd;
  954. print $formfile->showdocuments('massfilesarea_partnership', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  955. }
  956. // End of page
  957. llxFooter();
  958. $db->close();