list.php 44 KB

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