list.php 47 KB

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