list.php 44 KB

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