list.php 43 KB

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