list.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
  7. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  8. * Copyright (C) 2020 Tobias Sekan <tobias.sekan@startmail.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/comm/action/list.php
  25. * \ingroup agenda
  26. * \brief Page to list actions
  27. */
  28. // Load Dolibarr environment
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  34. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  36. require_once DOL_DOCUMENT_ROOT . '/comm/action/class/agendaplus.class.php';
  37. // Load translation files required by the page
  38. $langs->loadLangs(array("users", "companies", "agenda", "commercial", "other", "orders", "bills"));
  39. $action = GETPOST('action', 'aZ09');
  40. $massaction = GETPOST('massaction', 'alpha');
  41. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'actioncommlist'; // To manage different context of search
  42. $optioncss = GETPOST('optioncss', 'alpha');
  43. $toselect = GETPOST('toselect', 'array');
  44. $confirm = GETPOST('confirm', 'alpha');
  45. $disabledefaultvalues = GETPOST('disabledefaultvalues', 'int');
  46. $mode = GETPOST('mode', 'aZ09');
  47. if (empty($mode) && preg_match('/show_/', $action)) {
  48. $mode = $action; // For backward compatibility
  49. }
  50. $resourceid = GETPOST("search_resourceid", "int") ?GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int");
  51. $pid = GETPOST("search_projectid", 'int', 3) ?GETPOST("search_projectid", 'int', 3) : GETPOST("projectid", 'int', 3);
  52. $search_status = (GETPOST("search_status", 'aZ09') != '') ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09');
  53. $type = GETPOST('search_type', 'alphanohtml') ?GETPOST('search_type', 'alphanohtml') : GETPOST('type', 'alphanohtml');
  54. $year = GETPOST("year", 'int');
  55. $month = GETPOST("month", 'int');
  56. $day = GETPOST("day", 'int');
  57. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  58. if (GETPOST('search_actioncode', 'array')) {
  59. $actioncode = GETPOST('search_actioncode', 'array', 3);
  60. if (!count($actioncode)) {
  61. $actioncode = '0';
  62. }
  63. } else {
  64. $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : ((empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  65. }
  66. $search_id = GETPOST('search_id', 'alpha');
  67. $search_title = GETPOST('search_title', 'alpha');
  68. $search_note = GETPOST('search_note', 'alpha');
  69. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'), 'tzuserrel');
  70. $datestart_dtstart = dol_mktime(0, 0, 0, GETPOST('datestart_dtstartmonth', 'int'), GETPOST('datestart_dtstartday', 'int'), GETPOST('datestart_dtstartyear', 'int'), 'tzuserrel');
  71. $datestart_dtend = dol_mktime(23, 59, 59, GETPOST('datestart_dtendmonth', 'int'), GETPOST('datestart_dtendday', 'int'), GETPOST('datestart_dtendyear', 'int'), 'tzuserrel');
  72. $dateend_dtstart = dol_mktime(0, 0, 0, GETPOST('dateend_dtstartmonth', 'int'), GETPOST('dateend_dtstartday', 'int'), GETPOST('dateend_dtstartyear', 'int'), 'tzuserrel');
  73. $dateend_dtend = dol_mktime(23, 59, 59, GETPOST('dateend_dtendmonth', 'int'), GETPOST('dateend_dtendday', 'int'), GETPOST('dateend_dtendyear', 'int'), 'tzuserrel');
  74. if ($search_status == '' && !GETPOSTISSET('search_status')) {
  75. $search_status = ((empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) || $disabledefaultvalues) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  76. }
  77. if (empty($mode) && !GETPOSTISSET('mode')) {
  78. $mode = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  79. }
  80. $filter = GETPOST("search_filter", 'alpha', 3) ?GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  81. $filtert = GETPOST("search_filtert", "int", 3) ?GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  82. $usergroup = GETPOST("search_usergroup", "int", 3) ?GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  83. $showbirthday = empty($conf->use_javascript_ajax) ? (GETPOST("search_showbirthday", "int") ?GETPOST("search_showbirthday", "int") : GETPOST("showbirthday", "int")) : 1;
  84. $agendaplus = new AgendaPlus();
  85. // new filters (event_details, event products, event location from)
  86. $eventdetails = $agendaplus->getSearchedElement('eventdetails');
  87. $eventproduct = $agendaplus->getSearchedElement('eventproduct');
  88. $eventlocation = $agendaplus->getSearchedElement('eventlocation');
  89. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  90. $object = new ActionComm($db);
  91. $hookmanager->initHooks(array('agendalist'));
  92. $extrafields = new ExtraFields($db);
  93. // fetch optionals attributes and labels
  94. $extrafields->fetch_name_optionals_label($object->table_element);
  95. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  96. // If not choice done on calendar owner, we filter on user.
  97. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
  98. //$filtert = $user->id;
  99. }
  100. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  101. $sortfield = GETPOST('sortfield', 'aZ09comma');
  102. $sortorder = GETPOST('sortorder', 'aZ09comma');
  103. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  104. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  105. // If $page is not defined, or '' or -1 or if we click on clear filters
  106. $page = 0;
  107. }
  108. $offset = $limit * $page;
  109. if (!$sortorder) {
  110. $sortorder = "DESC,DESC";
  111. if ($search_status == 'todo') {
  112. $sortorder = "DESC,DESC";
  113. }
  114. }
  115. if (!$sortfield) {
  116. $sortfield = "a.datep,a.id";
  117. if ($search_status == 'todo') {
  118. $sortfield = "a.datep,a.id";
  119. }
  120. }
  121. // Security check
  122. $socid = GETPOST("search_socid", 'int') ?GETPOST("search_socid", 'int') : GETPOST("socid", 'int');
  123. if ($user->socid) {
  124. $socid = $user->socid;
  125. }
  126. if ($socid < 0) {
  127. $socid = '';
  128. }
  129. $canedit = 1;
  130. if (empty($user->rights->agenda->myactions->read)) {
  131. accessforbidden();
  132. }
  133. if (empty($user->rights->agenda->allactions->read)) {
  134. $canedit = 0;
  135. }
  136. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  137. $filtert = $user->id;
  138. }
  139. $arrayfields = array(
  140. 'a.id'=>array('label'=>"Ref", 'checked'=>1),
  141. 'owner'=>array('label'=>"Owner", 'checked'=>1),
  142. 'c.libelle'=>array('label'=>"Type", 'checked'=>1),
  143. 'a.label'=>array('label'=>"Title", 'checked'=>1),
  144. 'a.note'=>array('label'=>'Description', 'checked'=>0),
  145. 'a.datep'=>array('label'=>"DateStart", 'checked'=>1),
  146. 'a.datep2'=>array('label'=>"DateEnd", 'checked'=>1),
  147. 's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
  148. 'a.fk_contact'=>array('label'=>"Contact", 'checked'=>0),
  149. 'a.fk_element'=>array('label'=>"LinkedObject", 'checked'=>1, 'enabled'=>(!empty($conf->global->AGENDA_SHOW_LINKED_OBJECT))),
  150. 'a.datec'=>array('label'=>'DateCreation', 'checked'=>0, 'position'=>510),
  151. 'a.tms'=>array('label'=>'DateModification', 'checked'=>0, 'position'=>520),
  152. 'a.percent'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000)
  153. );
  154. // Extra fields
  155. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  156. $object->fields = dol_sort_array($object->fields, 'position');
  157. $arrayfields = dol_sort_array($arrayfields, 'position');
  158. $result = restrictedArea($user, 'agenda', 0, '', 'myactions');
  159. if ($user->socid && $socid) {
  160. $result = restrictedArea($user, 'societe', $socid);
  161. }
  162. /*
  163. * Actions
  164. */
  165. if (GETPOST('cancel', 'alpha')) {
  166. $mode = 'list';
  167. $massaction = '';
  168. }
  169. if (GETPOST("viewcal") || GETPOST("viewweek") || GETPOST("viewday")) {
  170. $param = '';
  171. if (is_array($_POST)) {
  172. foreach ($_POST as $key => $val) {
  173. $param .= '&'.$key.'='.urlencode($val);
  174. }
  175. }
  176. //print $param;
  177. header("Location: ".DOL_URL_ROOT.'/comm/action/index.php?'.$param);
  178. exit;
  179. }
  180. $parameters = array('id'=>$socid);
  181. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  182. if ($reshook < 0) {
  183. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  184. }
  185. // Selection of new fields
  186. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  187. // Purge search criteria
  188. 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
  189. //$actioncode='';
  190. $search_id = '';
  191. $search_title = '';
  192. $search_note = '';
  193. $datestart_dtstart = '';
  194. $datestart_dtend = '';
  195. $dateend_dtstart = '';
  196. $dateend_dtend = '';
  197. $actioncode = '';
  198. $search_status = '';
  199. $pid = '';
  200. $socid = '';
  201. $resourceid = '';
  202. $filter = '';
  203. $filtert = '';
  204. $usergroup = '';
  205. $toselect = array();
  206. $search_array_options = array();
  207. $eventdetails = '';
  208. $eventproduct = '';
  209. $eventlocation = '';
  210. }
  211. if (empty($reshook) && !empty($massaction)) {
  212. unset($percent);
  213. switch ($massaction) {
  214. case 'set_all_events_to_todo':
  215. $percent = ActionComm::EVENT_TODO;
  216. break;
  217. case 'set_all_events_to_in_progress':
  218. $percent = ActionComm::EVENT_IN_PROGRESS;
  219. break;
  220. case 'set_all_events_to_finished':
  221. $percent = ActionComm::EVENT_FINISHED;
  222. break;
  223. }
  224. if (isset($percent)) {
  225. foreach ($toselect as $toselectid) {
  226. $result = $object->updatePercent($toselectid, $percent);
  227. if ($result < 0) {
  228. dol_print_error($db);
  229. break;
  230. }
  231. }
  232. }
  233. }
  234. // As mass deletion happens with a confirm step, $massaction is not use for the final step (deletion).
  235. if (empty($reshook)) {
  236. $objectclass = 'ActionComm';
  237. $objectlabel = 'Events';
  238. $uploaddir = true;
  239. // Only users that can delete any event can remove records.
  240. $permissiontodelete = $user->rights->agenda->allactions->delete;
  241. $permissiontoadd = $user->rights->agenda->myactions->create;
  242. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  243. }
  244. /*
  245. * View
  246. */
  247. $form = new Form($db);
  248. $userstatic = new User($db);
  249. $formactions = new FormActions($db);
  250. $actionstatic = new ActionComm($db);
  251. $societestatic = new Societe($db);
  252. $contactstatic = new Contact($db);
  253. $nav = '';
  254. $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
  255. $nav .= ' <input type="submit" name="submitdateselect" class="button" value="'.$langs->trans("Refresh").'">';
  256. $now = dol_now();
  257. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda';
  258. $title = $langs->trans("Agenda");
  259. llxHeader('', $title, $help_url);
  260. // Define list of all external calendars
  261. $listofextcals = array();
  262. $param = '';
  263. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  264. $param .= '&contextpage='.urlencode($contextpage);
  265. }
  266. if ($limit > 0 && $limit != $conf->liste_limit) {
  267. $param .= '&limit='.urlencode($limit);
  268. }
  269. if ($actioncode != '') {
  270. if (is_array($actioncode)) {
  271. foreach ($actioncode as $str_action) {
  272. $param .= "&search_actioncode[]=".urlencode($str_action);
  273. }
  274. } else {
  275. $param .= "&search_actioncode=".urlencode($actioncode);
  276. }
  277. }
  278. if ($resourceid > 0) {
  279. $param .= "&search_resourceid=".urlencode($resourceid);
  280. }
  281. if ($search_status != '') {
  282. $param .= "&search_status=".urlencode($search_status);
  283. }
  284. if ($filter) {
  285. $param .= "&search_filter=".urlencode($filter);
  286. }
  287. if ($filtert) {
  288. $param .= "&search_filtert=".urlencode($filtert);
  289. }
  290. if ($usergroup > 0) {
  291. $param .= "&search_usergroup=".urlencode($usergroup);
  292. }
  293. if ($socid > 0) {
  294. $param .= "&search_socid=".urlencode($socid);
  295. }
  296. if ($showbirthday) {
  297. $param .= "&search_showbirthday=1";
  298. }
  299. if ($pid) {
  300. $param .= "&search_projectid=".urlencode($pid);
  301. }
  302. if ($type) {
  303. $param .= "&search_type=".urlencode($type);
  304. }
  305. if ($search_id != '') {
  306. $param .= '&search_title='.urlencode($search_id);
  307. }
  308. if ($search_title != '') {
  309. $param .= '&search_title='.urlencode($search_title);
  310. }
  311. if ($search_note != '') {
  312. $param .= '&search_note='.urlencode($search_note);
  313. }
  314. if (GETPOST('datestartday_dtstart', 'int')) {
  315. $param .= '&datestartday_dtstart='.GETPOST('datestartday_dtstart', 'int');
  316. }
  317. if (GETPOST('datestartmonth_dtstart', 'int')) {
  318. $param .= '&datestartmonth_dtstart='.GETPOST('datestartmonth_dtstart', 'int');
  319. }
  320. if (GETPOST('datestartyear_dtstart', 'int')) {
  321. $param .= '&datestartyear_dtstart='.GETPOST('datestartyear_dtstart', 'int');
  322. }
  323. if (GETPOST('datestartday_dtend', 'int')) {
  324. $param .= '&datestartday_dtend='.GETPOST('datestartday_dtend', 'int');
  325. }
  326. if (GETPOST('datestartmonth_dtend', 'int')) {
  327. $param .= '&datestartmonth_dtend='.GETPOST('datestartmonth_dtend', 'int');
  328. }
  329. if (GETPOST('datestartyear_dtend', 'int')) {
  330. $param .= '&datestartyear_dtend='.GETPOST('datestartyear_dtend', 'int');
  331. }
  332. if (GETPOST('dateendday_dtstart', 'int')) {
  333. $param .= '&dateendday_dtstart='.GETPOST('dateendday_dtstart', 'int');
  334. }
  335. if (GETPOST('dateendmonth_dtstart', 'int')) {
  336. $param .= '&dateendmonth_dtstart='.GETPOST('dateendmonth_dtstart', 'int');
  337. }
  338. if (GETPOST('dateendyear_dtstart', 'int')) {
  339. $param .= '&dateendyear_dtstart='.GETPOST('dateendyear_dtstart', 'int');
  340. }
  341. if (GETPOST('dateendday_dtend', 'int')) {
  342. $param .= '&dateendday_dtend='.GETPOST('dateendday_dtend', 'int');
  343. }
  344. if (GETPOST('dateendmonth_dtend', 'int')) {
  345. $param .= '&dateendmonth_dtend='.GETPOST('dateendmonth_dtend', 'int');
  346. }
  347. if (GETPOST('dateendyear_dtend', 'int')) {
  348. $param .= '&dateendyear_dtend='.GETPOST('dateendyear_dtend', 'int');
  349. }
  350. if ($optioncss != '') {
  351. $param .= '&optioncss='.urlencode($optioncss);
  352. }
  353. $param .= $agendaplus->completeParamString($eventdetails, $eventproduct, $eventlocation);
  354. // Add $param from extra fields
  355. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  356. $paramnoactionodate = $param;
  357. // List of mass actions available
  358. $arrayofmassactions = array(
  359. 'set_all_events_to_todo' => $langs->trans("SetAllEventsToTodo"),
  360. 'set_all_events_to_in_progress' => $langs->trans("SetAllEventsToInProgress"),
  361. 'set_all_events_to_finished' => $langs->trans("SetAllEventsToFinished"),
  362. );
  363. if ($user->rights->agenda->allactions->delete) {
  364. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  365. }
  366. if (isModEnabled('category') && $user->rights->agenda->myactions->create) {
  367. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  368. }
  369. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  370. $arrayofmassactions = array();
  371. }
  372. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  373. $sql = "SELECT";
  374. if ($usergroup > 0) {
  375. $sql .= " DISTINCT";
  376. }
  377. $sql .= $agendaplus->completeSqlSelectString($eventdetails, $eventproduct, $eventlocation);
  378. $sql .= " s.nom as societe, s.rowid as socid, s.client, s.email as socemail,";
  379. $sql .= " a.id, a.code, a.label, a.note, a.datep as dp, a.datep2 as dp2, a.fulldayevent, a.location,";
  380. $sql .= " a.fk_user_author, a.fk_user_action,";
  381. $sql .= " a.fk_contact, a.note, a.percent as percent,";
  382. $sql .= " a.fk_element, a.elementtype, a.datec, a.tms as datem,";
  383. $sql .= " c.code as type_code, c.libelle as type_label, c.color as type_color, c.type as type_type, c.picto as type_picto,";
  384. $sql .= " sp.lastname, sp.firstname, sp.email, sp.phone, sp.address, sp.phone as phone_pro, sp.phone_mobile, sp.phone_perso, sp.fk_pays as country_id";
  385. // Add fields from extrafields
  386. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  387. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  388. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  389. }
  390. }
  391. // Add fields from hooks
  392. $parameters = array();
  393. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  394. $sql .= $hookmanager->resPrint;
  395. $sqlfields = $sql; // $sql fields to remove for count total
  396. $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
  397. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_extrafields as ef ON (a.id = ef.fk_object)";
  398. if (empty($user->rights->societe->client->voir) && !$socid) {
  399. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  400. }
  401. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid";
  402. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON a.fk_contact = sp.rowid";
  403. $sql .= $agendaplus->completeSqlFromString($eventlocation);
  404. $sql .= " ,".MAIN_DB_PREFIX."c_actioncomm as c";
  405. // We must filter on resource table
  406. if ($resourceid > 0) {
  407. $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
  408. }
  409. // We must filter on assignement table
  410. if ($filtert > 0 || $usergroup > 0) {
  411. $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  412. }
  413. if ($usergroup > 0) {
  414. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  415. }
  416. $sql .= " WHERE c.id = a.fk_action";
  417. $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
  418. // Condition on actioncode
  419. if (!empty($actioncode)) {
  420. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  421. if ($actioncode == 'AC_NON_AUTO') {
  422. $sql .= " AND c.type != 'systemauto'";
  423. } elseif ($actioncode == 'AC_ALL_AUTO') {
  424. $sql .= " AND c.type = 'systemauto'";
  425. } else {
  426. if ($actioncode == 'AC_OTH') {
  427. $sql .= " AND c.type != 'systemauto'";
  428. }
  429. if ($actioncode == 'AC_OTH_AUTO') {
  430. $sql .= " AND c.type = 'systemauto'";
  431. }
  432. }
  433. } else {
  434. if ($actioncode == 'AC_NON_AUTO') {
  435. $sql .= " AND c.type != 'systemauto'";
  436. } elseif ($actioncode == 'AC_ALL_AUTO') {
  437. $sql .= " AND c.type = 'systemauto'";
  438. } else {
  439. if (is_array($actioncode)) {
  440. $sql .= " AND c.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
  441. } else {
  442. $sql .= " AND c.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
  443. }
  444. }
  445. }
  446. }
  447. if ($resourceid > 0) {
  448. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
  449. }
  450. if ($pid) {
  451. $sql .= " AND a.fk_project=".((int) $pid);
  452. }
  453. if (empty($user->rights->societe->client->voir) && !$socid) {
  454. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
  455. }
  456. if ($socid > 0) {
  457. $sql .= " AND s.rowid = ".((int) $socid);
  458. }
  459. // We must filter on assignement table
  460. if ($filtert > 0 || $usergroup > 0) {
  461. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  462. }
  463. if ($type) {
  464. $sql .= " AND c.id = ".((int) $type);
  465. }
  466. if ($search_status == '0') {
  467. $sql .= " AND a.percent = 0";
  468. }
  469. if ($search_status == 'na') {
  470. $sql .= " AND a.percent = -1";
  471. } // Not applicable
  472. if ($search_status == '50') {
  473. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  474. } // Running already started
  475. if ($search_status == '100') {
  476. $sql .= " AND a.percent = 100";
  477. }
  478. if ($search_status == 'done') {
  479. $sql .= " AND (a.percent = 100)";
  480. }
  481. if ($search_status == 'todo') {
  482. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  483. }
  484. if ($search_id) {
  485. $sql .= natural_search("a.id", $search_id, 1);
  486. }
  487. if ($search_title) {
  488. $sql .= natural_search("a.label", $search_title);
  489. }
  490. if ($search_note) {
  491. $sql .= natural_search('a.note', $search_note);
  492. }
  493. // We must filter on assignement table
  494. if ($filtert > 0 || $usergroup > 0) {
  495. $sql .= " AND (";
  496. if ($filtert > 0) {
  497. $sql .= "(ar.fk_element = ".((int) $filtert)." OR (ar.fk_element IS NULL AND a.fk_user_action = ".((int) $filtert)."))"; // The OR is for backward compatibility
  498. }
  499. if ($usergroup > 0) {
  500. $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
  501. }
  502. $sql .= ")";
  503. }
  504. // The second or of next test is to take event with no end date (we suppose duration is 1 hour in such case)
  505. if ($dateselect > 0) {
  506. $sql .= " AND ((a.datep2 >= '".$db->idate($dateselect)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."') OR (a.datep2 IS NULL AND a.datep > '".$db->idate($dateselect - 3600)."' AND a.datep <= '".$db->idate($dateselect + 3600 * 24 - 1)."'))";
  507. }
  508. if ($datestart_dtstart > 0) {
  509. $sql .= " AND a.datep >= '".$db->idate($datestart_dtstart)."'";
  510. }
  511. if ($datestart_dtend > 0) {
  512. $sql .= " AND a.datep <= '".$db->idate($datestart_dtend)."'";
  513. }
  514. if ($dateend_dtstart > 0) {
  515. $sql .= " AND a.datep2 >= '".$db->idate($dateend_dtstart)."'";
  516. }
  517. if ($dateend_dtend > 0) {
  518. $sql .= " AND a.datep2 <= '".$db->idate($dateend_dtend)."'";
  519. }
  520. // Add where from extra fields
  521. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  522. // Add where from hooks
  523. $parameters = array();
  524. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  525. $sql .= $hookmanager->resPrint;
  526. // Count total nb of records
  527. $nbtotalofrecords = '';
  528. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  529. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  530. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  531. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  532. $resql = $db->query($sqlforcount);
  533. if ($resql) {
  534. $objforcount = $db->fetch_object($resql);
  535. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  536. } else {
  537. dol_print_error($db);
  538. }
  539. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  540. $page = 0;
  541. $offset = 0;
  542. }
  543. $db->free($resql);
  544. }
  545. $sql .= " AND a.code = 'AC_EVENT'";
  546. $sql .= $agendaplus->completeSqlWhereString($eventdetails, $eventproduct, $eventlocation);
  547. // Complete request and execute it with limit
  548. $sql .= $db->order($sortfield, $sortorder);
  549. if ($limit) {
  550. $sql .= $db->plimit($limit + 1, $offset);
  551. }
  552. //print $sql;
  553. $resql = $db->query($sql);
  554. if (!$resql) {
  555. dol_print_error($db);
  556. exit;
  557. }
  558. $num = $db->num_rows($resql);
  559. $arrayofselected = is_array($toselect) ? $toselect : array();
  560. // Local calendar
  561. $newtitle = '<div class="nowrap clear inline-block minheight30 margintoponly">';
  562. //$newtitle .= '<input type="checkbox" id="check_mytasks" name="check_mytasks" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; ';
  563. $newtitle .= '</div>';
  564. //$newtitle=$langs->trans($title);
  565. $tabactive = 'cardlist';
  566. $head = calendars_prepare_head($param);
  567. print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  568. if ($optioncss != '') {
  569. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  570. }
  571. print '<input type="hidden" name="token" value="'.newToken().'">';
  572. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  573. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  574. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  575. print '<input type="hidden" name="type" value="'.$type.'">';
  576. $nav = '';
  577. if ($filter) {
  578. $nav .= '<input type="hidden" name="search_filter" value="'.$filter.'">';
  579. }
  580. if ($showbirthday) {
  581. $nav .= '<input type="hidden" name="search_showbirthday" value="1">';
  582. }
  583. print $nav;
  584. //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  585. //print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  586. //print dol_get_fiche_end();
  587. $s = $newtitle;
  588. // Calendars from hooks
  589. $parameters = array();
  590. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  591. if (empty($reshook)) {
  592. $s .= $hookmanager->resPrint;
  593. } elseif ($reshook > 1) {
  594. $s = $hookmanager->resPrint;
  595. }
  596. $viewyear = is_object($object) ? dol_print_date($object->datep, '%Y') : '';
  597. $viewmonth = is_object($object) ? dol_print_date($object->datep, '%m') : '';
  598. $viewday = is_object($object) ? dol_print_date($object->datep, '%d') : '';
  599. $viewmode = '';
  600. $viewmode .= '<a class="btnTitle btnTitleSelected reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
  601. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  602. $viewmode .= img_picto($langs->trans("List"), 'object_calendarlist', 'class="imgforviewmode pictoactionview block"');
  603. //$viewmode .= '</span>';
  604. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
  605. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
  606. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  607. $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
  608. //$viewmode .= '</span>';
  609. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
  610. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
  611. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  612. $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
  613. //$viewmode .= '</span>';
  614. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
  615. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
  616. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  617. $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
  618. //$viewmode .= '</span>';
  619. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
  620. $viewmode .= '<a class="btnTitle reposition marginrightonly" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.$viewyear.'&month='.$viewmonth.'&day='.$viewday.$paramnoactionodate.'">';
  621. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  622. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  623. //$viewmode .= '</span>';
  624. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
  625. $viewmode .= '<span class="marginrightonly"></span>';
  626. // Add more views from hooks
  627. $parameters = array();
  628. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  629. if (empty($reshook)) {
  630. $viewmode .= $hookmanager->resPrint;
  631. } elseif ($reshook > 1) {
  632. $viewmode = $hookmanager->resPrint;
  633. }
  634. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  635. $newparam = '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$tmpforcreatebutton['year'];
  636. //$param='month='.$monthshown.'&year='.$year;
  637. $hourminsec = dol_print_date(dol_mktime(10, 0, 0, 1, 1, 1970, 'gmt'), '%H', 'gmt').'0000'; // Set $hourminsec to '100000' to auto set hour to 10:00 at creation
  638. $url = DOL_URL_ROOT.'/comm/action/card.php?action=create';
  639. $url .= '&datep='.sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']).$hourminsec;
  640. $url .= '&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
  641. //$newcardbutton = dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', $url, '', $user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create);
  642. $param .= '&mode='.$mode;
  643. print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1 * $nbtotalofrecords, 'object_action', 0, $nav.$newcardbutton, '', $limit, 0, 0, 1, $viewmode);
  644. print $s;
  645. $objecttmp = new ActionComm($db);
  646. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  647. $moreforfilter = '';
  648. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  649. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  650. if ($massactionbutton) {
  651. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  652. }
  653. $i = 0;
  654. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  655. //print_actions_filter($form, $canedit, $search_status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  656. $agendaplus->new_print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, $eventdetails, $eventproduct, $eventlocation, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  657. print '</div>';
  658. print '<div class="div-table-responsive">';
  659. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  660. print '<tr class="liste_titre_filter">';
  661. // Action column
  662. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  663. print '<td class="liste_titre" align="middle">';
  664. $searchpicto = $form->showFilterButtons('left');
  665. print $searchpicto;
  666. print '</td>';
  667. }
  668. if (!empty($arrayfields['a.id']['checked'])) {
  669. print '<td class="liste_titre"><input type="text" class="maxwidth50" name="search_id" value="'.$search_id.'"></td>';
  670. }
  671. if (!empty($arrayfields['owner']['checked'])) {
  672. print '<td class="liste_titre"></td>';
  673. }
  674. if (!empty($arrayfields['c.libelle']['checked'])) {
  675. print '<td class="liste_titre"></td>';
  676. }
  677. if (!empty($arrayfields['a.label']['checked'])) {
  678. print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_title" value="'.$search_title.'"></td>';
  679. }
  680. if (!empty($arrayfields['a.note']['checked'])) {
  681. print '<td class="liste_titre"><input type="text" class="maxwidth75" name="search_note" value="'.$search_note.'"></td>';
  682. }
  683. if (!empty($arrayfields['a.datep']['checked'])) {
  684. print '<td class="liste_titre nowraponall" align="center">';
  685. print '<div class="nowrap">';
  686. print $form->selectDate($datestart_dtstart, 'datestart_dtstart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
  687. print '</div>';
  688. print '<div class="nowrap">';
  689. print $form->selectDate($datestart_dtend, 'datestart_dtend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('To'), 'tzuserrel');
  690. print '</div>';
  691. print '</td>';
  692. }
  693. if (!empty($arrayfields['a.datep2']['checked'])) {
  694. print '<td class="liste_titre nowraponall" align="center">';
  695. print '<div class="nowrap">';
  696. print $form->selectDate($dateend_dtstart, 'dateend_dtstart', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'), 'tzuserrel');
  697. print '</div>';
  698. print '<div class="nowrap">';
  699. print $form->selectDate($dateend_dtend, 'dateend_dtend', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('To'), 'tzuserrel');
  700. print '</div>';
  701. print '</td>';
  702. }
  703. if (!empty($arrayfields['s.nom']['checked'])) {
  704. print '<td class="liste_titre"></td>';
  705. }
  706. if (!empty($arrayfields['a.fk_contact']['checked'])) {
  707. print '<td class="liste_titre"></td>';
  708. }
  709. if (!empty($arrayfields['a.fk_element']['checked'])) {
  710. print '<td class="liste_titre"></td>';
  711. }
  712. // Extra fields
  713. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  714. // Fields from hook
  715. $parameters = array('arrayfields'=>$arrayfields);
  716. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  717. print $hookmanager->resPrint;
  718. if (!empty($arrayfields['a.datec']['checked'])) {
  719. print '<td class="liste_titre"></td>';
  720. }
  721. if (!empty($arrayfields['a.tms']['checked'])) {
  722. print '<td class="liste_titre"></td>';
  723. }
  724. if (!empty($arrayfields['a.percent']['checked'])) {
  725. print '<td class="liste_titre right parentonrightofpage">';
  726. $formactions->form_select_status_action('formaction', $search_status, 1, 'search_status', 1, 2, 'search_status width100 onrightofpage');
  727. print '</td>';
  728. }
  729. // Action column
  730. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  731. print '<td class="liste_titre" align="middle">';
  732. $searchpicto = $form->showFilterButtons();
  733. print $searchpicto;
  734. print '</td>';
  735. }
  736. print '</tr>'."\n";
  737. $totalarray = array();
  738. $totalarray['nbfield'] = 0;
  739. // Fields title label
  740. // --------------------------------------------------------------------
  741. print '<tr class="liste_titre">';
  742. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  743. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  744. }
  745. if (!empty($arrayfields['a.id']['checked'])) {
  746. print_liste_field_titre($arrayfields['a.id']['label'], $_SERVER["PHP_SELF"], "a.id", $param, "", "", $sortfield, $sortorder);
  747. $totalarray['nbfield']++;
  748. }
  749. if (!empty($arrayfields['owner']['checked'])) {
  750. print_liste_field_titre($arrayfields['owner']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
  751. $totalarray['nbfield']++;
  752. }
  753. if (!empty($arrayfields['c.libelle']['checked'])) {
  754. print_liste_field_titre($arrayfields['c.libelle']['label'], $_SERVER["PHP_SELF"], "c.libelle", $param, "", "", $sortfield, $sortorder);
  755. $totalarray['nbfield']++;
  756. }
  757. if (!empty($arrayfields['a.label']['checked'])) {
  758. print_liste_field_titre($arrayfields['a.label']['label'], $_SERVER["PHP_SELF"], "a.label", $param, "", "", $sortfield, $sortorder);
  759. $totalarray['nbfield']++;
  760. }
  761. if (!empty($arrayfields['a.note']['checked'])) {
  762. print_liste_field_titre($arrayfields['a.note']['label'], $_SERVER["PHP_SELF"], "a.note", $param, "", "", $sortfield, $sortorder);
  763. $totalarray['nbfield']++;
  764. }
  765. //if (!empty($conf->global->AGENDA_USE_EVENT_TYPE))
  766. if (!empty($arrayfields['a.datep']['checked'])) {
  767. print_liste_field_titre($arrayfields['a.datep']['label'], $_SERVER["PHP_SELF"], "a.datep,a.id", $param, '', 'align="center"', $sortfield, $sortorder);
  768. $totalarray['nbfield']++;
  769. }
  770. if (!empty($arrayfields['a.datep2']['checked'])) {
  771. print_liste_field_titre($arrayfields['a.datep2']['label'], $_SERVER["PHP_SELF"], "a.datep2", $param, '', 'align="center"', $sortfield, $sortorder);
  772. $totalarray['nbfield']++;
  773. }
  774. if (!empty($arrayfields['s.nom']['checked'])) {
  775. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $param, "", "", $sortfield, $sortorder);
  776. $totalarray['nbfield']++;
  777. }
  778. if (!empty($arrayfields['a.fk_contact']['checked'])) {
  779. print_liste_field_titre($arrayfields['a.fk_contact']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
  780. $totalarray['nbfield']++;
  781. }
  782. if (!empty($arrayfields['a.fk_element']['checked'])) {
  783. print_liste_field_titre($arrayfields['a.fk_element']['label'], $_SERVER["PHP_SELF"], "", $param, "", "", $sortfield, $sortorder);
  784. $totalarray['nbfield']++;
  785. }
  786. // Extra fields
  787. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  788. // Hook fields
  789. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  790. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  791. print $hookmanager->resPrint;
  792. if (!empty($arrayfields['a.datec']['checked'])) {
  793. print_liste_field_titre($arrayfields['a.datec']['label'], $_SERVER["PHP_SELF"], "a.datec,a.id", $param, "", 'align="center"', $sortfield, $sortorder);
  794. $totalarray['nbfield']++;
  795. }
  796. if (!empty($arrayfields['a.tms']['checked'])) {
  797. print_liste_field_titre($arrayfields['a.tms']['label'], $_SERVER["PHP_SELF"], "a.tms,a.id", $param, "", 'align="center"', $sortfield, $sortorder);
  798. $totalarray['nbfield']++;
  799. }
  800. if (!empty($arrayfields['a.percent']['checked'])) {
  801. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "a.percent", $param, "", 'align="center"', $sortfield, $sortorder);
  802. $totalarray['nbfield']++;
  803. }
  804. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  805. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  806. }
  807. $totalarray['nbfield']++;
  808. print "</tr>\n";
  809. $now = dol_now();
  810. $delay_warning = $conf->global->MAIN_DELAY_ACTIONS_TODO * 24 * 60 * 60;
  811. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php';
  812. $caction = new CActionComm($db);
  813. $arraylist = $caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE) ? 1 : 0), '', 1);
  814. $contactListCache = array();
  815. // Loop on record
  816. // --------------------------------------------------------------------
  817. $i = 0;
  818. //$savnbfield = $totalarray['nbfield'];
  819. //$totalarray['nbfield'] = 0;
  820. $imaxinloop = ($limit ? min($num, $limit) : $num);
  821. while ($i < $imaxinloop) {
  822. $obj = $db->fetch_object($resql);
  823. if (empty($obj)) {
  824. break; // Should not happen
  825. }
  826. // Store properties in $object
  827. $object->setVarsFromFetchObj($obj);
  828. // Discard auto action if option is on
  829. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
  830. $i++;
  831. continue;
  832. }
  833. $actionstatic->id = $obj->id;
  834. $actionstatic->ref = $obj->id;
  835. $actionstatic->code = $obj->code;
  836. $actionstatic->type_code = $obj->type_code;
  837. $actionstatic->type_label = $obj->type_label;
  838. $actionstatic->type_picto = $obj->type_picto;
  839. $actionstatic->type_color = $obj->type_color;
  840. $actionstatic->label = $obj->label;
  841. $actionstatic->location = $obj->location;
  842. $actionstatic->note_private = dol_htmlentitiesbr($obj->note);
  843. $actionstatic->datep = $db->jdate($obj->dp);
  844. $actionstatic->percentage = $obj->percent;
  845. $actionstatic->authorid = $obj->fk_user_author;
  846. // Initialize $this->userassigned && this->socpeopleassigned array && this->userownerid
  847. // but only if we need it
  848. if (!empty($arrayfields['a.fk_contact']['checked'])) {
  849. $actionstatic->fetchResources();
  850. }
  851. print '<tr class="oddeven">';
  852. // Action column
  853. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  854. print '<td class="nowrap center">';
  855. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  856. $selected = 0;
  857. if (in_array($obj->id, $arrayofselected)) {
  858. $selected = 1;
  859. }
  860. print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
  861. }
  862. print '</td>';
  863. }
  864. // Ref
  865. if (!empty($arrayfields['a.id']['checked'])) {
  866. print '<td class="nowraponall">';
  867. print $actionstatic->getNomUrl(1, -1);
  868. print '</td>';
  869. }
  870. // User owner
  871. if (!empty($arrayfields['owner']['checked'])) {
  872. print '<td class="tdoverflowmax150">'; // With edge and chrome the td overflow is not supported correctly when content is not full text.
  873. if ($obj->fk_user_action > 0) {
  874. $userstatic->fetch($obj->fk_user_action);
  875. print $userstatic->getNomUrl(-1);
  876. } else {
  877. print '&nbsp;';
  878. }
  879. print '</td>';
  880. }
  881. // Type
  882. if (!empty($arrayfields['c.libelle']['checked'])) {
  883. print '<td class="nowraponall">';
  884. print $actionstatic->getTypePicto();
  885. $labeltype = $obj->type_code;
  886. if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && empty($arraylist[$labeltype])) {
  887. $labeltype = 'AC_OTH';
  888. }
  889. if (preg_match('/^TICKET_MSG/', $actionstatic->code)) {
  890. $labeltype = $langs->trans("Message");
  891. } else {
  892. if (!empty($arraylist[$labeltype])) {
  893. $labeltype = $arraylist[$labeltype];
  894. }
  895. if ($obj->type_code == 'AC_OTH_AUTO' && ($obj->type_code != $obj->code) && $labeltype && !empty($arraylist[$obj->code])) {
  896. $labeltype .= ' - '.$arraylist[$obj->code]; // Use code in priority on type_code
  897. }
  898. }
  899. print dol_trunc($labeltype, 28);
  900. print '</td>';
  901. }
  902. // Label
  903. if (!empty($arrayfields['a.label']['checked'])) {
  904. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($actionstatic->label).'">';
  905. print $actionstatic->label;
  906. print '</td>';
  907. }
  908. // Description
  909. if (!empty($arrayfields['a.note']['checked'])) {
  910. print '<td class="tdoverflowonsmartphone">';
  911. $text = dolGetFirstLineOfText(dol_string_nohtmltag($actionstatic->note_private, 1));
  912. print $form->textwithtooltip(dol_trunc($text, 48), $actionstatic->note_private);
  913. print '</td>';
  914. }
  915. $formatToUse = $obj->fulldayevent ? 'day' : 'dayhour';
  916. // Start date
  917. if (!empty($arrayfields['a.datep']['checked'])) {
  918. print '<td class="center nowraponall">';
  919. if (empty($obj->fulldayevent)) {
  920. print dol_print_date($db->jdate($obj->dp), $formatToUse, 'tzuserrel');
  921. } else {
  922. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  923. print dol_print_date($db->jdate($obj->dp), $formatToUse, ($tzforfullday ? $tzforfullday : 'tzuserrel'));
  924. }
  925. $late = 0;
  926. if ($actionstatic->hasDelay() && $actionstatic->percentage >= 0 && $actionstatic->percentage < 100 ) {
  927. $late = 1;
  928. }
  929. if ($late) {
  930. print img_warning($langs->trans("Late")).' ';
  931. }
  932. print '</td>';
  933. }
  934. // End date
  935. if (!empty($arrayfields['a.datep2']['checked'])) {
  936. print '<td class="center nowraponall">';
  937. if (empty($obj->fulldayevent)) {
  938. print dol_print_date($db->jdate($obj->dp2), $formatToUse, 'tzuserrel');
  939. } else {
  940. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  941. print dol_print_date($db->jdate($obj->dp2), $formatToUse, ($tzforfullday ? $tzforfullday : 'tzuserrel'));
  942. }
  943. print '</td>';
  944. }
  945. // Third party
  946. if (!empty($arrayfields['s.nom']['checked'])) {
  947. print '<td class="tdoverflowmax150">';
  948. if ($obj->socid > 0) {
  949. $societestatic->id = $obj->socid;
  950. $societestatic->client = $obj->client;
  951. $societestatic->name = $obj->societe;
  952. $societestatic->email = $obj->socemail;
  953. print $societestatic->getNomUrl(1, '', 28);
  954. } else {
  955. print '&nbsp;';
  956. }
  957. print '</td>';
  958. }
  959. // Contact
  960. if (!empty($arrayfields['a.fk_contact']['checked'])) {
  961. print '<td class="tdoverflowmax100">';
  962. if (!empty($actionstatic->socpeopleassigned)) {
  963. $contactList = array();
  964. foreach ($actionstatic->socpeopleassigned as $socpeopleassigned) {
  965. if (!isset($contactListCache[$socpeopleassigned['id']])) {
  966. // if no cache found we fetch it
  967. $contact = new Contact($db);
  968. if ($contact->fetch($socpeopleassigned['id']) > 0) {
  969. $contactListCache[$socpeopleassigned['id']] = $contact->getNomUrl(1, '', 0);
  970. $contactList[] = $contact->getNomUrl(1, '', 0);
  971. }
  972. } else {
  973. // use cache
  974. $contactList[] = $contactListCache[$socpeopleassigned['id']];
  975. }
  976. }
  977. if (!empty($contactList)) {
  978. print implode(', ', $contactList);
  979. }
  980. } elseif ($obj->fk_contact > 0) { //keep for retrocompatibility with faraway event
  981. $contactstatic->id = $obj->fk_contact;
  982. $contactstatic->email = $obj->email;
  983. $contactstatic->lastname = $obj->lastname;
  984. $contactstatic->firstname = $obj->firstname;
  985. $contactstatic->phone_pro = $obj->phone_pro;
  986. $contactstatic->phone_mobile = $obj->phone_mobile;
  987. $contactstatic->phone_perso = $obj->phone_perso;
  988. $contactstatic->country_id = $obj->country_id;
  989. print $contactstatic->getNomUrl(1, '', 0);
  990. } else {
  991. print "&nbsp;";
  992. }
  993. print '</td>';
  994. }
  995. // Linked object
  996. if (!empty($arrayfields['a.fk_element']['checked'])) {
  997. print '<td class="tdoverflowmax150">';
  998. //var_dump($obj->fkelement.' '.$obj->elementtype);
  999. if ($obj->fk_element > 0 && !empty($obj->elementtype)) {
  1000. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1001. print dolGetElementUrl($obj->fk_element, $obj->elementtype, 1);
  1002. } else {
  1003. print "&nbsp;";
  1004. }
  1005. print '</td>';
  1006. }
  1007. // Extra fields
  1008. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1009. // Fields from hook
  1010. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1011. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1012. print $hookmanager->resPrint;
  1013. // Date creation
  1014. if (!empty($arrayfields['a.datec']['checked'])) {
  1015. // Status/Percent
  1016. print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datec), 'dayhour', 'tzuserrel').'</td>';
  1017. }
  1018. // Date update
  1019. if (!empty($arrayfields['a.tms']['checked'])) {
  1020. print '<td align="center" class="nowrap">'.dol_print_date($db->jdate($obj->datem), 'dayhour', 'tzuserrel').'</td>';
  1021. }
  1022. if (!empty($arrayfields['a.percent']['checked'])) {
  1023. // Status/Percent
  1024. $datep = $db->jdate($obj->dp);
  1025. print '<td align="center" class="nowrap">'.$actionstatic->LibStatut($obj->percent, 5, 0, $datep).'</td>';
  1026. }
  1027. // Action column
  1028. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1029. print '<td class="nowrap center">';
  1030. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1031. $selected = 0;
  1032. if (in_array($obj->id, $arrayofselected)) {
  1033. $selected = 1;
  1034. }
  1035. print '<input id="cb'.$obj->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1036. }
  1037. print '</td>';
  1038. }
  1039. print '</tr>'."\n";
  1040. $i++;
  1041. }
  1042. // If no record found
  1043. if ($num == 0) {
  1044. print '<tr><td colspan="'.$totalarray['nbfield'].'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1045. }
  1046. print '</table>'."\n";
  1047. print '</div>'."\n";
  1048. print '</form>'."\n";
  1049. $db->free($resql);
  1050. // End of page
  1051. llxFooter();
  1052. $db->close();