partnership_list.php 32 KB

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