index.php 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224
  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-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2014 Cedric GROSS <c.gross@kreiz-it.fr>
  8. * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
  9. * Copyright (C) 2017 Open-DSI <support@open-dsi.fr>
  10. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/comm/action/index.php
  27. * \ingroup agenda
  28. * \brief Home page of calendar events
  29. */
  30. require '../../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.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. if (!empty($conf->projet->enabled)) {
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  38. }
  39. if (!isset($conf->global->AGENDA_MAX_EVENTS_DAY_VIEW)) {
  40. $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3;
  41. }
  42. if (empty($conf->global->AGENDA_EXT_NB)) {
  43. $conf->global->AGENDA_EXT_NB = 5;
  44. }
  45. $MAXAGENDA = $conf->global->AGENDA_EXT_NB;
  46. $check_holiday = GETPOST('check_holiday', 'int');
  47. $filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3);
  48. $filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3);
  49. $usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3);
  50. $showbirthday = empty($conf->use_javascript_ajax) ? GETPOST("showbirthday", "int") : 1;
  51. // If not choice done on calendar owner (like on left menu link "Agenda"), we filter on user.
  52. if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) {
  53. $filtert = $user->id;
  54. }
  55. $newparam = '';
  56. $sortfield = GETPOST('sortfield', 'aZ09comma');
  57. $sortorder = GETPOST('sortorder', 'aZ09comma');
  58. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  59. if (empty($page) || $page == -1) {
  60. $page = 0;
  61. } // If $page is not defined, or '' or -1
  62. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  63. $offset = $limit * $page;
  64. if (!$sortorder) {
  65. $sortorder = "ASC";
  66. }
  67. if (!$sortfield) {
  68. $sortfield = "a.datec";
  69. }
  70. // Security check
  71. $socid = GETPOST("search_socid", "int") ?GETPOST("search_socid", "int") : GETPOST("socid", "int");
  72. if ($user->socid) {
  73. $socid = $user->socid;
  74. }
  75. if ($socid < 0) {
  76. $socid = '';
  77. }
  78. $canedit = 1;
  79. if (empty($user->rights->agenda->myactions->read)) {
  80. accessforbidden();
  81. }
  82. if (empty($user->rights->agenda->allactions->read)) {
  83. $canedit = 0;
  84. }
  85. if (empty($user->rights->agenda->allactions->read) || $filter == 'mine') { // If no permission to see all, we show only affected to me
  86. $filtert = $user->id;
  87. }
  88. $action = GETPOST('action', 'aZ09');
  89. $mode = GETPOST('mode', 'aZ09');
  90. if (empty($mode) && preg_match('/show_/', $action)) {
  91. $mode = $action; // For backward compatibility
  92. }
  93. $resourceid = GETPOST("search_resourceid", "int");
  94. $year = GETPOST("year", "int") ?GETPOST("year", "int") : date("Y");
  95. $month = GETPOST("month", "int") ?GETPOST("month", "int") : date("m");
  96. $week = GETPOST("week", "int") ?GETPOST("week", "int") : date("W");
  97. $day = GETPOST("day", "int") ?GETPOST("day", "int") : date("d");
  98. $pid = GETPOST("search_projectid", "int", 3) ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3);
  99. $status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo'
  100. $type = GETPOSTISSET("search_type", 'aZ09') ? GETPOST("search_type", 'aZ09') : GETPOST("type", 'aZ09');
  101. $maxprint = GETPOSTISSET("maxprint") ? GETPOST("maxprint", 'int') : $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW;
  102. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  103. $dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int'));
  104. if ($dateselect > 0) {
  105. $day = GETPOST('dateselectday', 'int');
  106. $month = GETPOST('dateselectmonth', 'int');
  107. $year = GETPOST('dateselectyear', 'int');
  108. }
  109. // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index)
  110. if (GETPOST('search_actioncode', 'array:aZ09')) {
  111. $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3);
  112. if (!count($actioncode)) {
  113. $actioncode = '0';
  114. }
  115. } else {
  116. $actioncode = GETPOST("search_actioncode", "alpha", 3) ?GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode") == '0' ? '0' : (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE));
  117. }
  118. if ($actioncode == '' && empty($actioncodearray)) {
  119. $actioncode = (empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_TYPE);
  120. }
  121. if ($status == '' && !GETPOSTISSET('search_status')) {
  122. $status = (empty($conf->global->AGENDA_DEFAULT_FILTER_STATUS) ? '' : $conf->global->AGENDA_DEFAULT_FILTER_STATUS);
  123. }
  124. $defaultview = (empty($conf->global->AGENDA_DEFAULT_VIEW) ? 'show_month' : $conf->global->AGENDA_DEFAULT_VIEW);
  125. $defaultview = (empty($user->conf->AGENDA_DEFAULT_VIEW) ? $defaultview : $user->conf->AGENDA_DEFAULT_VIEW);
  126. if (empty($mode) && !GETPOSTISSET('mode')) {
  127. $mode = $defaultview;
  128. }
  129. if ($mode == 'default') { // When action is default, we want a calendar view and not the list
  130. $mode = (($defaultview != 'show_list') ? $defaultview : 'show_month');
  131. }
  132. if (GETPOST('viewcal', 'int') && GETPOST('mode', 'alpha') != 'show_day' && GETPOST('mode', 'alpha') != 'show_week') {
  133. $mode = 'show_month'; $day = '';
  134. } // View by month
  135. if (GETPOST('viewweek', 'int') || GETPOST('mode', 'alpha') == 'show_week') {
  136. $mode = 'show_week'; $week = ($week ? $week : date("W")); $day = ($day ? $day : date("d"));
  137. } // View by week
  138. if (GETPOST('viewday', 'int') || GETPOST('mode', 'alpha') == 'show_day') {
  139. $mode = 'show_day'; $day = ($day ? $day : date("d"));
  140. } // View by day
  141. $object = new ActionComm($db);
  142. // Load translation files required by the page
  143. $langs->loadLangs(array('agenda', 'other', 'commercial'));
  144. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  145. $hookmanager->initHooks(array('agenda'));
  146. $result = restrictedArea($user, 'agenda', 0, 'actioncomm&societe', 'myactions|allactions', 'fk_soc', 'id');
  147. if ($user->socid && $socid) {
  148. $result = restrictedArea($user, 'societe', $socid);
  149. }
  150. /*
  151. * Actions
  152. */
  153. if (GETPOST("viewlist", 'alpha') || $mode == 'show_list') {
  154. $param = '';
  155. if (is_array($_POST)) {
  156. foreach ($_POST as $key => $val) {
  157. if ($key == 'token') {
  158. continue;
  159. }
  160. $param .= '&'.$key.'='.urlencode($val);
  161. }
  162. }
  163. if (!preg_match('/action=/', $param)) {
  164. $param .= ($param ? '&' : '').'mode=show_list';
  165. }
  166. //print $param;
  167. header("Location: ".DOL_URL_ROOT.'/comm/action/list.php?'.$param);
  168. exit;
  169. }
  170. if (GETPOST("viewperuser", 'alpha') || $mode == 'show_peruser') {
  171. $param = '';
  172. if (is_array($_POST)) {
  173. foreach ($_POST as $key => $val) {
  174. if ($key == 'token') {
  175. continue;
  176. }
  177. $param .= '&'.$key.'='.urlencode($val);
  178. }
  179. }
  180. //print $param;
  181. header("Location: ".DOL_URL_ROOT.'/comm/action/peruser.php?'.$param);
  182. exit;
  183. }
  184. /*
  185. if ($action == 'delete_action' && $user->rights->agenda->delete) {
  186. $event = new ActionComm($db);
  187. $event->fetch($actionid);
  188. $event->fetch_optionals();
  189. $event->fetch_userassigned();
  190. $event->oldcopy = clone $event;
  191. $result = $event->delete();
  192. }
  193. */
  194. /*
  195. * View
  196. */
  197. $parameters = array(
  198. 'socid' => $socid,
  199. 'status' => $status,
  200. 'year' => $year,
  201. 'month' => $month,
  202. 'day' => $day,
  203. 'type' => $type,
  204. 'maxprint' => $maxprint,
  205. 'filter' => $filter,
  206. 'filtert' => $filtert,
  207. 'showbirthday' => $showbirthday,
  208. 'canedit' => $canedit,
  209. 'optioncss' => $optioncss,
  210. 'actioncode' => $actioncode,
  211. 'pid' => $pid,
  212. 'resourceid' => $resourceid,
  213. 'usergroup' => $usergroup,
  214. );
  215. $reshook = $hookmanager->executeHooks('beforeAgenda', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  216. if ($reshook < 0) {
  217. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  218. }
  219. $help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:M&oacute;dulo_Agenda';
  220. llxHeader('', $langs->trans("Agenda"), $help_url);
  221. $form = new Form($db);
  222. $companystatic = new Societe($db);
  223. $contactstatic = new Contact($db);
  224. $userstatic = new User($db);
  225. $now = dol_now();
  226. $nowarray = dol_getdate($now);
  227. $nowyear = $nowarray['year'];
  228. $nowmonth = $nowarray['mon'];
  229. $nowday = $nowarray['mday'];
  230. $listofextcals = array();
  231. // Define list of external calendars (global admin setup)
  232. if (empty($conf->global->AGENDA_DISABLE_EXT)) {
  233. $i = 0;
  234. while ($i < $MAXAGENDA) {
  235. $i++;
  236. $source = 'AGENDA_EXT_SRC'.$i;
  237. $name = 'AGENDA_EXT_NAME'.$i;
  238. $offsettz = 'AGENDA_EXT_OFFSETTZ'.$i;
  239. $color = 'AGENDA_EXT_COLOR'.$i;
  240. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT'.$i;
  241. $buggedfile = 'AGENDA_EXT_BUGGEDFILE'.$i;
  242. if (!empty($conf->global->$source) && !empty($conf->global->$name)) {
  243. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  244. $listofextcals[] = array(
  245. 'src' => getDolGlobalString($source),
  246. 'name' => getDolGlobalString($name),
  247. 'offsettz' => (!empty($conf->global->$offsettz) ? $conf->global->$offsettz : 0),
  248. 'color' => getDolGlobalString($color),
  249. 'default' => getDolGlobalString($default),
  250. 'buggedfile' => (isset($conf->global->buggedfile) ? $conf->global->buggedfile : 0)
  251. );
  252. }
  253. }
  254. }
  255. // Define list of external calendars (user setup)
  256. if (empty($user->conf->AGENDA_DISABLE_EXT)) {
  257. $i = 0;
  258. while ($i < $MAXAGENDA) {
  259. $i++;
  260. $source = 'AGENDA_EXT_SRC_'.$user->id.'_'.$i;
  261. $name = 'AGENDA_EXT_NAME_'.$user->id.'_'.$i;
  262. $offsettz = 'AGENDA_EXT_OFFSETTZ_'.$user->id.'_'.$i;
  263. $color = 'AGENDA_EXT_COLOR_'.$user->id.'_'.$i;
  264. $enabled = 'AGENDA_EXT_ENABLED_'.$user->id.'_'.$i;
  265. $default = 'AGENDA_EXT_ACTIVEBYDEFAULT_'.$user->id.'_'.$i;
  266. $buggedfile = 'AGENDA_EXT_BUGGEDFILE_'.$user->id.'_'.$i;
  267. if (!empty($user->conf->$source) && !empty($user->conf->$name)) {
  268. // Note: $conf->global->buggedfile can be empty or 'uselocalandtznodaylight' or 'uselocalandtzdaylight'
  269. $listofextcals[] = array(
  270. 'src' => $user->conf->$source,
  271. 'name' => $user->conf->$name,
  272. 'offsettz' => (!empty($user->conf->$offsettz) ? $user->conf->$offsettz : 0),
  273. 'color' => $user->conf->$color,
  274. 'default' => $user->conf->$default,
  275. 'buggedfile' => (isset($user->conf->buggedfile) ? $user->conf->buggedfile : 0)
  276. );
  277. }
  278. }
  279. }
  280. if (empty($mode) || $mode == 'show_month') {
  281. $prev = dol_get_prev_month($month, $year);
  282. $prev_year = $prev['year'];
  283. $prev_month = $prev['month'];
  284. $next = dol_get_next_month($month, $year);
  285. $next_year = $next['year'];
  286. $next_month = $next['month'];
  287. $max_day_in_prev_month = date("t", dol_mktime(0, 0, 0, $prev_month, 1, $prev_year, 'gmt')); // Nb of days in previous month
  288. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); // Nb of days in next month
  289. // tmpday is a negative or null cursor to know how many days before the 1st to show on month view (if tmpday=0, 1st is monday)
  290. $tmpday = -date("w", dol_mktime(12, 0, 0, $month, 1, $year, 'gmt')) + 2; // date('w') is 0 fo sunday
  291. $tmpday += ((isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1) - 1);
  292. if ($tmpday >= 1) {
  293. $tmpday -= 7; // If tmpday is 0 we start with sunday, if -6, we start with monday of previous week.
  294. }
  295. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  296. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $max_day_in_prev_month + $tmpday, $prev_year, 'tzuserrel');
  297. $next_day = 7 - ($max_day_in_month + 1 - $tmpday) % 7;
  298. if ($next_day < 6) {
  299. $next_day += 7;
  300. }
  301. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  302. }
  303. if ($mode == 'show_week') {
  304. $prev = dol_get_first_day_week($day, $month, $year);
  305. $prev_year = $prev['prev_year'];
  306. $prev_month = $prev['prev_month'];
  307. $prev_day = $prev['prev_day'];
  308. $first_day = $prev['first_day'];
  309. $first_month = $prev['first_month'];
  310. $first_year = $prev['first_year'];
  311. $week = $prev['week'];
  312. $day = (int) $day;
  313. $next = dol_get_next_week($first_day, $week, $first_month, $first_year);
  314. $next_year = $next['year'];
  315. $next_month = $next['month'];
  316. $next_day = $next['day'];
  317. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  318. $firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'tzuserrel');
  319. $lastdaytoshow = dol_time_plus_duree($firstdaytoshow, 7, 'd');
  320. $max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt'));
  321. $tmpday = $first_day;
  322. }
  323. if ($mode == 'show_day') {
  324. $prev = dol_get_prev_day($day, $month, $year);
  325. $prev_year = $prev['year'];
  326. $prev_month = $prev['month'];
  327. $prev_day = $prev['day'];
  328. $next = dol_get_next_day($day, $month, $year);
  329. $next_year = $next['year'];
  330. $next_month = $next['month'];
  331. $next_day = $next['day'];
  332. // Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1)
  333. $firstdaytoshow = dol_mktime(0, 0, 0, $prev_month, $prev_day, $prev_year, 'tzuserrel');
  334. $lastdaytoshow = dol_mktime(0, 0, 0, $next_month, $next_day, $next_year, 'tzuserrel');
  335. }
  336. //print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day;
  337. //print 'xx'.$next_year.'-'.$next_month.'-'.$next_day;
  338. //print dol_print_date($firstdaytoshow,'dayhour').' '.dol_print_date($lastdaytoshow,'dayhour');
  339. /*$title = $langs->trans("DoneAndToDoActions");
  340. if ($status == 'done') $title = $langs->trans("DoneActions");
  341. if ($status == 'todo') $title = $langs->trans("ToDoActions");
  342. */
  343. $param = '';
  344. if ($actioncode || GETPOSTISSET('search_actioncode')) {
  345. if (is_array($actioncode)) {
  346. foreach ($actioncode as $str_action) {
  347. $param .= "&search_actioncode[]=".urlencode($str_action);
  348. }
  349. } else {
  350. $param .= "&search_actioncode=".urlencode($actioncode);
  351. }
  352. }
  353. if ($resourceid > 0) {
  354. $param .= "&search_resourceid=".urlencode($resourceid);
  355. }
  356. if ($status || GETPOSTISSET('status') || GETPOSTISSET('search_status')) {
  357. $param .= "&search_status=".urlencode($status);
  358. }
  359. if ($filter) {
  360. $param .= "&search_filter=".urlencode($filter);
  361. }
  362. if ($filtert) {
  363. $param .= "&search_filtert=".urlencode($filtert);
  364. }
  365. if ($usergroup > 0) {
  366. $param .= "&search_usergroup=".urlencode($usergroup);
  367. }
  368. if ($socid > 0) {
  369. $param .= "&search_socid=".urlencode($socid);
  370. }
  371. if ($showbirthday) {
  372. $param .= "&search_showbirthday=1";
  373. }
  374. if ($pid) {
  375. $param .= "&search_projectid=".urlencode($pid);
  376. }
  377. if ($type) {
  378. $param .= "&search_type=".urlencode($type);
  379. }
  380. $param .= "&maxprint=".urlencode($maxprint);
  381. if ($mode == 'show_day' || $mode == 'show_week' || $mode == 'show_month') {
  382. $param .= '&mode='.urlencode($mode);
  383. }
  384. // Show navigation bar
  385. if (empty($mode) || $mode == 'show_month') {
  386. $nav = "<a href=\"?year=".$prev_year."&month=".$prev_month.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  387. $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, 1, $year), "%b %Y");
  388. $nav .= " </span>\n";
  389. $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  390. if (empty($conf->dol_optimize_smallscreen)) {
  391. $nav .= " &nbsp; <a href=\"?year=".$nowyear."&month=".$nowmonth.$param."\">".$langs->trans("Today")."</a> ";
  392. }
  393. $picto = 'calendar';
  394. }
  395. if ($mode == 'show_week') {
  396. $nav = "<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\" title=\"".dol_escape_htmltag($langs->trans("Previous"))."\"></i></a> &nbsp;\n";
  397. $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y").", ".$langs->trans("Week")." ".$week;
  398. $nav .= " </span>\n";
  399. $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\" title=\"".dol_escape_htmltag($langs->trans("Next"))."\"></i></a>\n";
  400. if (empty($conf->dol_optimize_smallscreen)) {
  401. $nav .= " &nbsp; <a href=\"?year=".$nowyear."&month=".$nowmonth."&day=".$nowday.$param."\">".$langs->trans("Today")."</a> ";
  402. }
  403. $picto = 'calendarweek';
  404. }
  405. if ($mode == 'show_day') {
  406. $nav = "<a href=\"?year=".$prev_year."&month=".$prev_month."&day=".$prev_day.$param."\"><i class=\"fa fa-chevron-left\"></i></a> &nbsp;\n";
  407. $nav .= " <span id=\"month_name\">".dol_print_date(dol_mktime(0, 0, 0, $month, $day, $year), "daytextshort");
  408. $nav .= " </span>\n";
  409. $nav .= " &nbsp; <a href=\"?year=".$next_year."&month=".$next_month."&day=".$next_day.$param."\"><i class=\"fa fa-chevron-right\"></i></a>\n";
  410. if (empty($conf->dol_optimize_smallscreen)) {
  411. $nav .= " &nbsp; <a href=\"?year=".$nowyear."&amp;month=".$nowmonth."&amp;day=".$nowday.$param."\">".$langs->trans("Today")."</a> ";
  412. }
  413. $picto = 'calendarday';
  414. }
  415. $nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0);
  416. //$nav .= ' <input type="submit" class="button button-save" name="submitdateselect" value="'.$langs->trans("Refresh").'">';
  417. $nav .= '<button type="submit" class="liste_titre button_search valignmiddle" name="button_search_x" value="x"><span class="fa fa-search"></span></button>';
  418. // Must be after the nav definition
  419. $paramnodate = $param;
  420. $param .= '&year='.$year.'&month='.$month.($day ? '&day='.$day : '');
  421. //print 'x'.$param;
  422. /*$tabactive = '';
  423. if ($mode == 'show_month') $tabactive = 'cardmonth';
  424. if ($mode == 'show_week') $tabactive = 'cardweek';
  425. if ($mode == 'show_day') $tabactive = 'cardday';
  426. if ($mode == 'show_list') $tabactive = 'cardlist';
  427. if ($mode == 'show_pertuser') $tabactive = 'cardperuser';
  428. if ($mode == 'show_pertype') $tabactive = 'cardpertype';
  429. */
  430. $paramnoaction = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $param));
  431. $paramnoactionodate = preg_replace('/mode=[a-z_]+/', '', preg_replace('/action=[a-z_]+/', '', $paramnodate));
  432. $head = calendars_prepare_head($paramnoaction);
  433. print '<form method="POST" id="searchFormList" class="listactionsfilter" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  434. if ($optioncss != '') {
  435. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  436. }
  437. print '<input type="hidden" name="token" value="'.newToken().'">';
  438. print '<input type="hidden" name="mode" value="'.$mode.'">';
  439. //print dol_get_fiche_head($head, $tabactive, $langs->trans('Agenda'), 0, 'action');
  440. //print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, $listofextcals, $actioncode, $usergroup, '', $resourceid);
  441. //print dol_get_fiche_end();
  442. $viewmode = '';
  443. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&restore_lastsearch_values=1'.$paramnoactionodate.'">';
  444. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  445. $viewmode .= img_picto($langs->trans("List"), 'object_list', 'class="imgforviewmode pictoactionview block"');
  446. //$viewmode .= '</span>';
  447. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewList").'</span></a>';
  448. $viewmode .= '<a class="btnTitle'.($mode == 'show_month' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_month&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
  449. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  450. $viewmode .= img_picto($langs->trans("ViewCal"), 'object_calendarmonth', 'class="pictoactionview block"');
  451. //$viewmode .= '</span>';
  452. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewCal").'</span></a>';
  453. $viewmode .= '<a class="btnTitle'.($mode == 'show_week' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_week&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
  454. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  455. $viewmode .= img_picto($langs->trans("ViewWeek"), 'object_calendarweek', 'class="pictoactionview block"');
  456. //$viewmode .= '</span>';
  457. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewWeek").'</span></a>';
  458. $viewmode .= '<a class="btnTitle'.($mode == 'show_day' ? ' btnTitleSelected' : '').' reposition" href="'.DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
  459. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  460. $viewmode .= img_picto($langs->trans("ViewDay"), 'object_calendarday', 'class="pictoactionview block"');
  461. //$viewmode .= '</span>';
  462. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewDay").'</span></a>';
  463. $viewmode .= '<a class="btnTitle reposition" href="'.DOL_URL_ROOT.'/comm/action/peruser.php?mode=show_peruser&year='.(isset($object->datep) ? dol_print_date($object->datep, '%Y') : $year).'&month='.(isset($object->datep) ? dol_print_date($object->datep, '%m') : $month).'&day='.(isset($object->datep) ? dol_print_date($object->datep, '%d') : $day).$paramnoactionodate.'">';
  464. //$viewmode .= '<span class="fa paddingleft imgforviewmode valignmiddle btnTitle-icon">';
  465. $viewmode .= img_picto($langs->trans("ViewPerUser"), 'object_calendarperuser', 'class="pictoactionview block"');
  466. //$viewmode .= '</span>';
  467. $viewmode .= '<span class="valignmiddle text-plus-circle btnTitle-label hideonsmartphone">'.$langs->trans("ViewPerUser").'</span></a>';
  468. // Add more views from hooks
  469. $parameters = array(); $object = null;
  470. $reshook = $hookmanager->executeHooks('addCalendarView', $parameters, $object, $action);
  471. if (empty($reshook)) {
  472. $viewmode .= $hookmanager->resPrint;
  473. } elseif ($reshook > 1) {
  474. $viewmode = $hookmanager->resPrint;
  475. }
  476. $viewmode .= '<span class="marginrightonly"></span>'; // To add a space before the navigation tools
  477. $newcardbutton = '';
  478. $newparam = '';
  479. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  480. $tmpforcreatebutton = dol_getdate(dol_now(), true);
  481. $newparam .= '&month='.((int) $month).'&year='.((int) $tmpforcreatebutton['year']).'&mode='.urlencode($mode);
  482. //$param='month='.$monthshown.'&year='.$year;
  483. $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
  484. $newcardbutton .= dolGetButtonTitle($langs->trans("AddAction"), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $tmpforcreatebutton['year'], $tmpforcreatebutton['mon'], $tmpforcreatebutton['mday']).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : '')));
  485. }
  486. // Define the legend/list of calendard to show
  487. $s = ''; $link = '';
  488. $showextcals = $listofextcals;
  489. if (!empty($conf->use_javascript_ajax)) { // If javascript on
  490. $s .= "\n".'<!-- Div to calendars selectors -->'."\n";
  491. $s .= '<script type="text/javascript">'."\n";
  492. $s .= 'jQuery(document).ready(function () {'."\n";
  493. $s .= 'jQuery(".check_birthday").click(function() { console.log("Toggle birthdays"); jQuery(".family_birthday").toggle(); });'."\n";
  494. $s .= 'jQuery(".check_holiday").click(function() { console.log("Toggle holidays"); jQuery(".family_holiday").toggle(); });'."\n";
  495. if ($mode == "show_week" || $mode == "show_month" || empty($mode)) {
  496. // Code to enable drag and drop
  497. $s .= 'jQuery( "div.sortable" ).sortable({connectWith: ".sortable", placeholder: "ui-state-highlight", items: "div.movable", receive: function( event, ui ) {'."\n";
  498. // Code to submit form
  499. $s .= 'console.log("submit form to record new event");'."\n";
  500. //$s.='console.log(event.target);';
  501. $s .= 'var newval = jQuery(event.target).closest("div.dayevent").attr("id");'."\n";
  502. $s .= 'console.log("found parent div.dayevent with id = "+newval);'."\n";
  503. $s .= 'var frm=jQuery("#searchFormList");'."\n";
  504. $s .= 'var newurl = ui.item.find("a.cal_event").attr("href");'."\n";
  505. $s .= 'console.log("Found url on href of a.cal_event"+newurl+", we submit form with actionmove=mupdate");'."\n";
  506. $s .= 'frm.attr("action", newurl).children("#newdate").val(newval);frm.submit();}'."\n";
  507. $s .= '});'."\n";
  508. }
  509. $s .= '});'."\n";
  510. $s .= '</script>'."\n";
  511. // Local calendar
  512. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_mytasks" name="check_mytasks" value="1" checked disabled> '.$langs->trans("LocalAgenda").' &nbsp; </div>';
  513. // Holiday calendar
  514. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_holiday" name="check_holiday" value="1" class="check_holiday"'.($check_holiday ? ' checked' : '').'><label for="check_holiday"> <span class="check_holiday_text">'.$langs->trans("Holidays").'</span></label> &nbsp; </div>';
  515. // External calendars
  516. if (is_array($showextcals) && count($showextcals) > 0) {
  517. $s .= '<script type="text/javascript">'."\n";
  518. $s .= 'jQuery(document).ready(function () {
  519. jQuery("div input[name^=\"check_ext\"]").each(function(index, elem) {
  520. var name = jQuery(elem).attr("name");
  521. if (jQuery(elem).is(":checked")) {
  522. jQuery(".family_ext" + name.replace("check_ext", "")).show();
  523. } else {
  524. jQuery(".family_ext" + name.replace("check_ext", "")).hide();
  525. }
  526. });
  527. jQuery("div input[name^=\"check_ext\"]").click(function() {
  528. var name = $(this).attr("name");
  529. jQuery(".family_ext" + name.replace("check_ext", "")).toggle();
  530. });
  531. });' . "\n";
  532. $s .= '</script>'."\n";
  533. foreach ($showextcals as $val) {
  534. $htmlname = md5($val['name']);
  535. if (!empty($val['default']) || GETPOST('check_ext'.$htmlname, 'int')) {
  536. $default = "checked";
  537. } else {
  538. $default = '';
  539. }
  540. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_ext'.$htmlname.'" name="check_ext'.$htmlname.'" value="1" '.$default.'> <label for="check_ext'.$htmlname.'">'.$val['name'].'</label> &nbsp; </div>';
  541. }
  542. }
  543. // Birthdays
  544. $s .= '<div class="nowrap inline-block minheight30"><input type="checkbox" id="check_birthday" name="check_birthday" class="check_birthday"><label for="check_birthday"> <span class="check_birthday_text">'.$langs->trans("AgendaShowBirthdayEvents").'</span></label> &nbsp; </div>';
  545. // Calendars from hooks
  546. $parameters = array();
  547. $reshook = $hookmanager->executeHooks('addCalendarChoice', $parameters, $object, $action);
  548. if (empty($reshook)) {
  549. $s .= $hookmanager->resPrint;
  550. } elseif ($reshook > 1) {
  551. $s = $hookmanager->resPrint;
  552. }
  553. $s .= "\n".'<!-- End div to calendars selectors -->'."\n";
  554. } else { // If javascript off
  555. $newparam = $param; // newparam is for birthday links
  556. $newparam = preg_replace('/showbirthday=[0-1]/i', 'showbirthday='.(empty($showbirthday) ? 1 : 0), $newparam);
  557. if (!preg_match('/showbirthday=/i', $newparam)) {
  558. $newparam .= '&showbirthday=1';
  559. }
  560. $link = '<a href="'.dol_escape_htmltag($_SERVER['PHP_SELF']);
  561. $link .= '?'.dol_escape_htmltag($newparam);
  562. $link .= '">';
  563. if (empty($showbirthday)) {
  564. $link .= $langs->trans("AgendaShowBirthdayEvents");
  565. } else {
  566. $link .= $langs->trans("AgendaHideBirthdayEvents");
  567. }
  568. $link .= '</a>';
  569. }
  570. // Load events from database into $eventarray
  571. $eventarray = array();
  572. // DEFAULT CALENDAR + AUTOEVENT CALENDAR + CONFERENCEBOOTH CALENDAR
  573. $sql = 'SELECT ';
  574. if ($usergroup > 0) {
  575. $sql .= " DISTINCT";
  576. }
  577. $sql .= ' a.id, a.label,';
  578. $sql .= ' a.datep,';
  579. $sql .= ' a.datep2,';
  580. $sql .= ' a.percent,';
  581. $sql .= ' a.fk_user_author,a.fk_user_action,';
  582. $sql .= ' a.transparency, a.priority, a.fulldayevent, a.location,';
  583. $sql .= ' a.fk_soc, a.fk_contact, a.fk_project,';
  584. $sql .= ' a.fk_element, a.elementtype,';
  585. $sql .= ' ca.code as type_code, ca.libelle as type_label, ca.color as type_color, ca.type as type_type, ca.picto as type_picto';
  586. $sql .= ' FROM '.MAIN_DB_PREFIX.'c_actioncomm as ca, '.MAIN_DB_PREFIX."actioncomm as a";
  587. if (empty($user->rights->societe->client->voir) && !$socid) {
  588. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc";
  589. }
  590. // We must filter on resource table
  591. if ($resourceid > 0) {
  592. $sql .= ", ".MAIN_DB_PREFIX."element_resources as r";
  593. }
  594. // We must filter on assignement table
  595. if ($filtert > 0 || $usergroup > 0) {
  596. $sql .= ", ".MAIN_DB_PREFIX."actioncomm_resources as ar";
  597. }
  598. if ($usergroup > 0) {
  599. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element";
  600. }
  601. $sql .= ' WHERE a.fk_action = ca.id';
  602. $sql .= ' AND a.entity IN ('.getEntity('agenda').')';
  603. // Condition on actioncode
  604. if (!empty($actioncode)) {
  605. if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) {
  606. if ($actioncode == 'AC_NON_AUTO') {
  607. $sql .= " AND ca.type != 'systemauto'";
  608. } elseif ($actioncode == 'AC_ALL_AUTO') {
  609. $sql .= " AND ca.type = 'systemauto'";
  610. } else {
  611. if ($actioncode == 'AC_OTH') {
  612. $sql .= " AND ca.type != 'systemauto'";
  613. }
  614. if ($actioncode == 'AC_OTH_AUTO') {
  615. $sql .= " AND ca.type = 'systemauto'";
  616. }
  617. }
  618. } else {
  619. if ($actioncode == 'AC_NON_AUTO') {
  620. $sql .= " AND ca.type != 'systemauto'";
  621. } elseif ($actioncode == 'AC_ALL_AUTO') {
  622. $sql .= " AND ca.type = 'systemauto'";
  623. } else {
  624. if (is_array($actioncode)) {
  625. $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", $actioncode)."'", 1).")";
  626. } else {
  627. $sql .= " AND ca.code IN (".$db->sanitize("'".implode("','", explode(',', $actioncode))."'", 1).")";
  628. }
  629. }
  630. }
  631. }
  632. if ($resourceid > 0) {
  633. $sql .= " AND r.element_type = 'action' AND r.element_id = a.id AND r.resource_id = ".((int) $resourceid);
  634. }
  635. if ($pid) {
  636. $sql .= " AND a.fk_project=".((int) $pid);
  637. }
  638. if (empty($user->rights->societe->client->voir) && !$socid) {
  639. $sql .= " AND (a.fk_soc IS NULL OR sc.fk_user = ".((int) $user->id).")";
  640. }
  641. if ($socid > 0) {
  642. $sql .= " AND a.fk_soc = ".((int) $socid);
  643. }
  644. // We must filter on assignement table
  645. if ($filtert > 0 || $usergroup > 0) {
  646. $sql .= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'";
  647. }
  648. //var_dump($day.' '.$month.' '.$year);
  649. if ($mode == 'show_day') {
  650. $sql .= " AND (";
  651. $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  652. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  653. $sql .= " OR ";
  654. $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  655. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  656. $sql .= " OR ";
  657. $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year, 'tzuserrel'))."'";
  658. $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year, 'tzuserrel'))."')";
  659. $sql .= ')';
  660. } else {
  661. // To limit array
  662. $sql .= " AND (";
  663. $sql .= " (a.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'"; // Start 7 days before
  664. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')"; // End 7 days after + 3 to go from 28 to 31
  665. $sql .= " OR ";
  666. $sql .= " (a.datep2 BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
  667. $sql .= " AND '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
  668. $sql .= " OR ";
  669. $sql .= " (a.datep < '".$db->idate(dol_mktime(0, 0, 0, $month, 1, $year) - (60 * 60 * 24 * 7))."'";
  670. $sql .= " AND a.datep2 > '".$db->idate(dol_mktime(23, 59, 59, $month, 28, $year) + (60 * 60 * 24 * 10))."')";
  671. $sql .= ')';
  672. }
  673. if ($type) {
  674. $sql .= " AND ca.id = ".((int) $type);
  675. }
  676. if ($status == '0') {
  677. $sql .= " AND a.percent = 0";
  678. }
  679. if ($status == '-1') {
  680. $sql .= " AND a.percent = -1";
  681. } // Not applicable
  682. if ($status == '50') {
  683. $sql .= " AND (a.percent > 0 AND a.percent < 100)";
  684. } // Running already started
  685. if ($status == 'done' || $status == '100') {
  686. $sql .= " AND (a.percent = 100)";
  687. }
  688. if ($status == 'todo') {
  689. $sql .= " AND (a.percent >= 0 AND a.percent < 100)";
  690. }
  691. // We must filter on assignement table
  692. if ($filtert > 0 || $usergroup > 0) {
  693. $sql .= " AND (";
  694. if ($filtert > 0) {
  695. $sql .= "ar.fk_element = ".((int) $filtert);
  696. }
  697. if ($usergroup > 0) {
  698. $sql .= ($filtert > 0 ? " OR " : "")." ugu.fk_usergroup = ".((int) $usergroup);
  699. }
  700. $sql .= ")";
  701. }
  702. // Sort on date
  703. $sql .= ' ORDER BY datep';
  704. //print $sql;
  705. dol_syslog("comm/action/index.php", LOG_DEBUG);
  706. $resql = $db->query($sql);
  707. if ($resql) {
  708. $num = $db->num_rows($resql);
  709. $MAXONSAMEPAGE = 10000; // Useless to have more. Protection to avoid memory overload when high number of event (for example after a mass import)
  710. $i = 0;
  711. while ($i < $num && $i < $MAXONSAMEPAGE) {
  712. $obj = $db->fetch_object($resql);
  713. // Discard auto action if option is on
  714. if (!empty($conf->global->AGENDA_ALWAYS_HIDE_AUTO) && $obj->type_code == 'AC_OTH_AUTO') {
  715. $i++;
  716. continue;
  717. }
  718. // Create a new object action
  719. $event = new ActionComm($db);
  720. $event->id = $obj->id;
  721. $event->ref = $event->id;
  722. $event->fulldayevent = $obj->fulldayevent;
  723. // event->datep and event->datef must be GMT date.
  724. if ($event->fulldayevent) {
  725. $tzforfullday = getDolGlobalString('MAIN_STORE_FULL_EVENT_IN_GMT');
  726. $event->datep = $db->jdate($obj->datep, $tzforfullday ? 'tzuser' : 'tzserver'); // If saved in $tzforfullday = gmt, we must invert date to be in user tz
  727. $event->datef = $db->jdate($obj->datep2, $tzforfullday ? 'tzuser' : 'tzserver');
  728. } else {
  729. // Example: $obj->datep = '1970-01-01 01:00:00', jdate will return 0 if TZ of PHP server is Europe/Berlin (+1)
  730. $event->datep = $db->jdate($obj->datep, 'tzserver');
  731. $event->datef = $db->jdate($obj->datep2, 'tzserver');
  732. }
  733. //$event->datep_formated_gmt = dol_print_date($event->datep, 'dayhour', 'gmt');
  734. //var_dump($obj->id.' '.$obj->datep.' '.dol_print_date($obj->datep, 'dayhour', 'gmt'));
  735. //var_dump($obj->id.' '.$event->datep.' '.dol_print_date($event->datep, 'dayhour', 'gmt'));
  736. $event->type_code = $obj->type_code;
  737. $event->type_label = $obj->type_label;
  738. $event->type_color = $obj->type_color;
  739. $event->type = $obj->type_type;
  740. $event->type_picto = $obj->type_picto;
  741. $event->libelle = $obj->label; // deprecated
  742. $event->label = $obj->label;
  743. $event->percentage = $obj->percent;
  744. $event->authorid = $obj->fk_user_author; // user id of creator
  745. $event->userownerid = $obj->fk_user_action; // user id of owner
  746. $event->fetch_userassigned(); // This load $event->userassigned
  747. $event->priority = $obj->priority;
  748. $event->location = $obj->location;
  749. $event->transparency = $obj->transparency;
  750. $event->fk_element = $obj->fk_element;
  751. $event->elementtype = $obj->elementtype;
  752. $event->fk_project = $obj->fk_project;
  753. $event->socid = $obj->fk_soc;
  754. $event->thirdparty_id = $obj->fk_soc;
  755. $event->contact_id = $obj->fk_contact;
  756. // Defined date_start_in_calendar and date_end_in_calendar property
  757. // They are date start and end of action but modified to not be outside calendar view.
  758. $event->date_start_in_calendar = $event->datep;
  759. if ($event->datef != '' && $event->datef >= $event->datep) {
  760. $event->date_end_in_calendar = $event->datef;
  761. } else {
  762. $event->date_end_in_calendar = $event->datep;
  763. }
  764. // Check values
  765. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  766. // This record is out of visible range
  767. } else {
  768. if ($event->date_start_in_calendar < $firstdaytoshow) {
  769. $event->date_start_in_calendar = $firstdaytoshow;
  770. }
  771. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  772. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  773. }
  774. // Add an entry in actionarray for each day
  775. $daycursor = $event->date_start_in_calendar;
  776. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  777. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  778. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  779. $daycursorend = $event->date_end_in_calendar;
  780. $anneeend = dol_print_date($daycursorend, '%Y', 'tzuserrel');
  781. $moisend = dol_print_date($daycursorend, '%m', 'tzuserrel');
  782. $jourend = dol_print_date($daycursorend, '%d', 'tzuserrel');
  783. //var_dump(dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt')); // Hour at greenwich
  784. //var_dump($annee.'-'.$mois.'-'.$jour);
  785. //print 'annee='.$annee.' mois='.$mois.' jour='.$jour.'<br>';
  786. // Loop on each day covered by action to prepare an index to show on calendar
  787. $loop = true; $j = 0;
  788. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt'); // $mois, $jour, $annee has been set for user tz
  789. $daykeyend = dol_mktime(0, 0, 0, $moisend, $jourend, $anneeend, 'gmt'); // $moisend, $jourend, $anneeend has been set for user tz
  790. /*
  791. print 'GMT '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'gmt').'<br>';
  792. print 'TZSERVER '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzserver').'<br>';
  793. print 'TZUSERREL '.$event->date_start_in_calendar.' '.dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  794. print 'GMT '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'gmt').'<br>';
  795. print 'TZSERVER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzserver').'<br>';
  796. print 'TZUSER '.$event->date_end_in_calendar.' '.dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel').'<br>';
  797. */
  798. do {
  799. //if ($event->id==408)
  800. //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'gmt').' - '.dol_print_date($event->datep, 'dayhour', 'gmt').' '.dol_print_date($event->datef, 'dayhour', 'gmt').'<br>';
  801. //print 'daykey='.$daykey.' daykeyend='.$daykeyend.' '.dol_print_date($daykey, 'dayhour', 'tzuserrel').' - '.dol_print_date($event->datep, 'dayhour', 'tzuserrel').' '.dol_print_date($event->datef, 'dayhour', 'tzuserrel').'<br>';
  802. $eventarray[$daykey][] = $event;
  803. $j++;
  804. $daykey += 60 * 60 * 24;
  805. //if ($daykey > $event->date_end_in_calendar) {
  806. if ($daykey > $daykeyend) {
  807. $loop = false;
  808. }
  809. } while ($loop);
  810. //var_dump($eventarray);
  811. //print 'Event '.$i.' id='.$event->id.' (start='.dol_print_date($event->datep).'-end='.dol_print_date($event->datef);
  812. //print ' startincalendar='.dol_print_date($event->date_start_in_calendar).'-endincalendar='.dol_print_date($event->date_end_in_calendar).') was added in '.$j.' different index key of array<br>';
  813. }
  814. $i++;
  815. }
  816. } else {
  817. dol_print_error($db);
  818. }
  819. //var_dump($eventarray);
  820. // BIRTHDATES CALENDAR
  821. // Complete $eventarray with birthdates
  822. if ($showbirthday) {
  823. // Add events in array
  824. $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday';
  825. $sql .= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp';
  826. $sql .= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.((int) $user->id).'))';
  827. $sql .= " AND sp.entity IN (".getEntity('contact').")";
  828. if ($mode == 'show_day') {
  829. $sql .= ' AND MONTH(birthday) = '.((int) $month);
  830. $sql .= ' AND DAY(birthday) = '.((int) $day);
  831. } else {
  832. $sql .= ' AND MONTH(birthday) = '.((int) $month);
  833. }
  834. $sql .= ' ORDER BY birthday';
  835. dol_syslog("comm/action/index.php", LOG_DEBUG);
  836. $resql = $db->query($sql);
  837. if ($resql) {
  838. $num = $db->num_rows($resql);
  839. $i = 0;
  840. while ($i < $num) {
  841. $obj = $db->fetch_object($resql);
  842. $event = new ActionComm($db);
  843. $event->id = $obj->rowid; // We put contact id in action id for birthdays events
  844. $event->ref = $event->id;
  845. $datebirth = dol_stringtotime($obj->birthday, 1);
  846. //print 'ee'.$obj->birthday.'-'.$datebirth;
  847. $datearray = dol_getdate($datebirth, true);
  848. $event->datep = dol_mktime(0, 0, 0, $datearray['mon'], $datearray['mday'], $year, true); // For full day events, date are also GMT but they wont but converted during output
  849. $event->datef = $event->datep;
  850. $event->type_code = 'BIRTHDAY';
  851. $event->type_label = '';
  852. $event->type_color = '';
  853. $event->type = 'birthdate';
  854. $event->type_picto = 'birthdate';
  855. $event->label = $langs->trans("Birthday").' '.dolGetFirstLastname($obj->firstname, $obj->lastname);
  856. $event->percentage = 100;
  857. $event->fulldayevent = 1;
  858. $event->date_start_in_calendar = $db->jdate($event->datep);
  859. $event->date_end_in_calendar = $db->jdate($event->datef);
  860. // Add an entry in eventarray for each day
  861. $daycursor = $event->datep;
  862. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  863. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  864. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  865. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  866. $eventarray[$daykey][] = $event;
  867. /*$loop = true;
  868. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee);
  869. do {
  870. $eventarray[$daykey][] = $event;
  871. $daykey += 60 * 60 * 24;
  872. if ($daykey > $event->date_end_in_calendar) $loop = false;
  873. } while ($loop);
  874. */
  875. $i++;
  876. }
  877. } else {
  878. dol_print_error($db);
  879. }
  880. }
  881. // LEAVE CALENDAR
  882. $sql = "SELECT u.rowid as uid, u.lastname, u.firstname, u.statut, x.rowid, x.date_debut as date_start, x.date_fin as date_end, x.halfday, x.statut as status";
  883. $sql .= " FROM ".MAIN_DB_PREFIX."holiday as x, ".MAIN_DB_PREFIX."user as u";
  884. $sql .= " WHERE u.rowid = x.fk_user";
  885. $sql .= " AND u.statut = '1'"; // Show only active users (0 = inactive user, 1 = active user)
  886. $sql .= " AND (x.statut = '2' OR x.statut = '3')"; // Show only public leaves (2 = leave wait for approval, 3 = leave approved)
  887. if ($mode == 'show_day') {
  888. // Request only leaves for the current selected day
  889. $sql .= " AND '".$db->escape($year)."-".$db->escape($month)."-".$db->escape($day)."' BETWEEN x.date_debut AND x.date_fin"; // date_debut and date_fin are date without time
  890. } elseif ($mode == 'show_week') {
  891. // TODO: Add filter to reduce database request
  892. } elseif ($mode == 'show_month') {
  893. // TODO: Add filter to reduce database request
  894. }
  895. $resql = $db->query($sql);
  896. if ($resql) {
  897. $num = $db->num_rows($resql);
  898. $i = 0;
  899. while ($i < $num) {
  900. $obj = $db->fetch_object($resql);
  901. $event = new ActionComm($db);
  902. // Need the id of the leave object for link to it
  903. $event->id = $obj->rowid;
  904. $event->ref = $event->id;
  905. $event->type_code = 'HOLIDAY';
  906. $event->type_label = '';
  907. $event->type_color = '';
  908. $event->type = 'holiday';
  909. $event->type_picto = 'holiday';
  910. $event->datep = $db->jdate($obj->date_start) + (empty($halfday) || $halfday == 1 ? 0 : 12 * 60 * 60 - 1);
  911. $event->datef = $db->jdate($obj->date_end) + (empty($halfday) || $halfday == -1 ? 24 : 12) * 60 * 60 - 1;
  912. $event->date_start_in_calendar = $event->datep;
  913. $event->date_end_in_calendar = $event->datef;
  914. if ($obj->status == 3) {
  915. // Show no symbol for leave with state "leave approved"
  916. $event->percentage = -1;
  917. } elseif ($obj->status == 2) {
  918. // Show TO-DO symbol for leave with state "leave wait for approval"
  919. $event->percentage = 0;
  920. }
  921. if ($obj->halfday == 1) {
  922. $event->label = $obj->lastname.' ('.$langs->trans("Morning").')';
  923. } elseif ($obj->halfday == -1) {
  924. $event->label = $obj->lastname.' ('.$langs->trans("Afternoon").')';
  925. } else {
  926. $event->label = $obj->lastname;
  927. }
  928. $daycursor = $event->date_start_in_calendar;
  929. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  930. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  931. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  932. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  933. do {
  934. $eventarray[$daykey][] = $event;
  935. $daykey += 60 * 60 * 24;
  936. } while ($daykey <= $event->date_end_in_calendar);
  937. $i++;
  938. }
  939. }
  940. // EXTERNAL CALENDAR
  941. // Complete $eventarray with external import Ical
  942. if (count($listofextcals)) {
  943. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/ical.class.php';
  944. foreach ($listofextcals as $extcal) {
  945. $url = $extcal['src']; // Example: https://www.google.com/calendar/ical/eldy10%40gmail.com/private-cde92aa7d7e0ef6110010a821a2aaeb/basic.ics
  946. $namecal = $extcal['name'];
  947. $offsettz = $extcal['offsettz'];
  948. $colorcal = $extcal['color'];
  949. $buggedfile = $extcal['buggedfile'];
  950. $ical = new ICal();
  951. $ical->parse($url);
  952. // After this $ical->cal['VEVENT'] contains array of events, $ical->cal['DAYLIGHT'] contains daylight info, $ical->cal['STANDARD'] contains non daylight info, ...
  953. //var_dump($ical->cal); exit;
  954. $icalevents = array();
  955. if (is_array($ical->get_event_list())) {
  956. $icalevents = array_merge($icalevents, $ical->get_event_list()); // Add $ical->cal['VEVENT']
  957. }
  958. if (is_array($ical->get_freebusy_list())) {
  959. $icalevents = array_merge($icalevents, $ical->get_freebusy_list()); // Add $ical->cal['VFREEBUSY']
  960. }
  961. if (count($icalevents) > 0) {
  962. // Duplicate all repeatable events into new entries
  963. $moreicalevents = array();
  964. foreach ($icalevents as $icalevent) {
  965. if (isset($icalevent['RRULE']) && is_array($icalevent['RRULE'])) { //repeatable event
  966. //if ($event->date_start_in_calendar < $firstdaytoshow) $event->date_start_in_calendar=$firstdaytoshow;
  967. //if ($event->date_end_in_calendar > $lastdaytoshow) $event->date_end_in_calendar=($lastdaytoshow-1);
  968. if ($icalevent['DTSTART;VALUE=DATE']) { //fullday event
  969. $datecurstart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
  970. $datecurend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
  971. } elseif (is_array($icalevent['DTSTART']) && !empty($icalevent['DTSTART']['unixtime'])) {
  972. $datecurstart = $icalevent['DTSTART']['unixtime'];
  973. $datecurend = $icalevent['DTEND']['unixtime'];
  974. if (!empty($ical->cal['DAYLIGHT']['DTSTART']) && $datecurstart) {
  975. //var_dump($ical->cal);
  976. $tmpcurstart = $datecurstart;
  977. $tmpcurend = $datecurend;
  978. $tmpdaylightstart = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['DAYLIGHT']['DTSTART'];
  979. $tmpdaylightend = dol_mktime(0, 0, 0, 1, 1, 1970, 1) + (int) $ical->cal['STANDARD']['DTSTART'];
  980. //var_dump($tmpcurstart);var_dump($tmpcurend); var_dump($ical->cal['DAYLIGHT']['DTSTART']);var_dump($ical->cal['STANDARD']['DTSTART']);
  981. // Edit datecurstart and datecurend
  982. if ($tmpcurstart >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
  983. $datecurstart -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
  984. } else {
  985. $datecurstart -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
  986. }
  987. if ($tmpcurend >= $tmpdaylightstart && $tmpcurstart < $tmpdaylightend) {
  988. $datecurend -= ((int) $ical->cal['DAYLIGHT']['TZOFFSETTO']) * 36;
  989. } else {
  990. $datecurend -= ((int) $ical->cal['STANDARD']['TZOFFSETTO']) * 36;
  991. }
  992. }
  993. // datecurstart and datecurend are now GMT date
  994. //var_dump($datecurstart); var_dump($datecurend); exit;
  995. } else {
  996. // Not a recongized record
  997. dol_syslog("Found a not recognized repeatable record with unknown date start", LOG_ERR);
  998. continue;
  999. }
  1000. //print 'xx'.$datecurstart;exit;
  1001. $interval = (empty($icalevent['RRULE']['INTERVAL']) ? 1 : $icalevent['RRULE']['INTERVAL']);
  1002. $until = empty($icalevent['RRULE']['UNTIL']) ? 0 : dol_stringtotime($icalevent['RRULE']['UNTIL'], 1);
  1003. $maxrepeat = empty($icalevent['RRULE']['COUNT']) ? 0 : $icalevent['RRULE']['COUNT'];
  1004. if ($until && ($until + ($datecurend - $datecurstart)) < $firstdaytoshow) {
  1005. continue; // We discard repeatable event that end before start date to show
  1006. }
  1007. if ($datecurstart >= $lastdaytoshow) {
  1008. continue; // We discard repeatable event that start after end date to show
  1009. }
  1010. $numofevent = 0;
  1011. while (($datecurstart < $lastdaytoshow) && (empty($maxrepeat) || ($numofevent < $maxrepeat))) {
  1012. if ($datecurend >= $firstdaytoshow) { // We add event
  1013. $newevent = $icalevent;
  1014. unset($newevent['RRULE']);
  1015. if ($icalevent['DTSTART;VALUE=DATE']) {
  1016. $newevent['DTSTART;VALUE=DATE'] = dol_print_date($datecurstart, '%Y%m%d');
  1017. $newevent['DTEND;VALUE=DATE'] = dol_print_date($datecurend + 1, '%Y%m%d');
  1018. } else {
  1019. $newevent['DTSTART'] = $datecurstart;
  1020. $newevent['DTEND'] = $datecurend;
  1021. }
  1022. $moreicalevents[] = $newevent;
  1023. }
  1024. // Jump on next occurence
  1025. $numofevent++;
  1026. $savdatecurstart = $datecurstart;
  1027. if ($icalevent['RRULE']['FREQ'] == 'DAILY') {
  1028. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'd');
  1029. $datecurend = dol_time_plus_duree($datecurend, $interval, 'd');
  1030. }
  1031. if ($icalevent['RRULE']['FREQ'] == 'WEEKLY') {
  1032. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'w');
  1033. $datecurend = dol_time_plus_duree($datecurend, $interval, 'w');
  1034. } elseif ($icalevent['RRULE']['FREQ'] == 'MONTHLY') {
  1035. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'm');
  1036. $datecurend = dol_time_plus_duree($datecurend, $interval, 'm');
  1037. } elseif ($icalevent['RRULE']['FREQ'] == 'YEARLY') {
  1038. $datecurstart = dol_time_plus_duree($datecurstart, $interval, 'y');
  1039. $datecurend = dol_time_plus_duree($datecurend, $interval, 'y');
  1040. }
  1041. // Test to avoid infinite loop ($datecurstart must increase)
  1042. if ($savdatecurstart >= $datecurstart) {
  1043. dol_syslog("Found a rule freq ".$icalevent['RRULE']['FREQ']." not managed by dolibarr code. Assume 1 week frequency.", LOG_ERR);
  1044. $datecurstart += 3600 * 24 * 7;
  1045. $datecurend += 3600 * 24 * 7;
  1046. }
  1047. }
  1048. }
  1049. }
  1050. $icalevents = array_merge($icalevents, $moreicalevents);
  1051. // Loop on each entry into cal file to know if entry is qualified and add an ActionComm into $eventarray
  1052. foreach ($icalevents as $icalevent) {
  1053. //var_dump($icalevent);
  1054. //print $icalevent['SUMMARY'].'->';
  1055. //var_dump($icalevent);exit;
  1056. if (!empty($icalevent['RRULE'])) {
  1057. continue; // We found a repeatable event. It was already split into unitary events, so we discard general rule.
  1058. }
  1059. // Create a new object action
  1060. $event = new ActionComm($db);
  1061. $addevent = false;
  1062. if (isset($icalevent['DTSTART;VALUE=DATE'])) { // fullday event
  1063. // For full day events, date are also GMT but they wont but converted using tz during output
  1064. $datestart = dol_stringtotime($icalevent['DTSTART;VALUE=DATE'], 1);
  1065. if (empty($icalevent['DTEND;VALUE=DATE'])) {
  1066. $dateend = $datestart + 86400 - 1;
  1067. } else {
  1068. $dateend = dol_stringtotime($icalevent['DTEND;VALUE=DATE'], 1) - 1; // We remove one second to get last second of day
  1069. }
  1070. //print 'x'.$datestart.'-'.$dateend;exit;
  1071. //print dol_print_date($dateend,'dayhour','gmt');
  1072. $event->fulldayevent = 1;
  1073. $addevent = true;
  1074. } elseif (!is_array($icalevent['DTSTART'])) { // not fullday event (DTSTART is not array. It is a value like '19700101T000000Z' for 00:00 in greenwitch)
  1075. $datestart = $icalevent['DTSTART'];
  1076. $dateend = empty($icalevent['DTEND']) ? $datestart : $icalevent['DTEND'];
  1077. $datestart += +($offsettz * 3600);
  1078. $dateend += +($offsettz * 3600);
  1079. $addevent = true;
  1080. //var_dump($offsettz);
  1081. //var_dump(dol_print_date($datestart, 'dayhour', 'gmt'));
  1082. } elseif (isset($icalevent['DTSTART']['unixtime'])) { // File contains a local timezone + a TZ (for example when using bluemind)
  1083. $datestart = $icalevent['DTSTART']['unixtime'];
  1084. $dateend = $icalevent['DTEND']['unixtime'];
  1085. $datestart += +($offsettz * 3600);
  1086. $dateend += +($offsettz * 3600);
  1087. // $buggedfile is set to uselocalandtznodaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtznodaylight'
  1088. if ($buggedfile === 'uselocalandtznodaylight') { // unixtime is a local date that does not take daylight into account, TZID is +1 for example for 'Europe/Paris' in summer instead of 2
  1089. // TODO
  1090. }
  1091. // $buggedfile is set to uselocalandtzdaylight if conf->global->AGENDA_EXT_BUGGEDFILEx = 'uselocalandtzdaylight' (for example with bluemind)
  1092. if ($buggedfile === 'uselocalandtzdaylight') { // unixtime is a local date that does take daylight into account, TZID is +2 for example for 'Europe/Paris' in summer
  1093. $localtzs = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTSTART']['TZID']));
  1094. $localtze = new DateTimeZone(preg_replace('/"/', '', $icalevent['DTEND']['TZID']));
  1095. $localdts = new DateTime(dol_print_date($datestart, 'dayrfc', 'gmt'), $localtzs);
  1096. $localdte = new DateTime(dol_print_date($dateend, 'dayrfc', 'gmt'), $localtze);
  1097. $tmps = -1 * $localtzs->getOffset($localdts);
  1098. $tmpe = -1 * $localtze->getOffset($localdte);
  1099. $datestart += $tmps;
  1100. $dateend += $tmpe;
  1101. //var_dump($datestart);
  1102. }
  1103. $addevent = true;
  1104. }
  1105. if ($addevent) {
  1106. $event->id = $icalevent['UID'];
  1107. $event->ref = $event->id;
  1108. $userId = $userstatic->findUserIdByEmail($namecal);
  1109. if (!empty($userId) && $userId > 0) {
  1110. $event->userassigned[$userId] = $userId;
  1111. $event->percentage = -1;
  1112. }
  1113. $event->type_code = "ICALEVENT";
  1114. $event->type_label = $namecal;
  1115. $event->type_color = $colorcal;
  1116. $event->type = 'icalevent';
  1117. $event->type_picto = 'rss';
  1118. $event->icalname = $namecal;
  1119. $event->icalcolor = $colorcal;
  1120. $usertime = 0; // We dont modify date because we want to have date into memory datep and datef stored as GMT date. Compensation will be done during output.
  1121. $event->datep = $datestart + $usertime;
  1122. $event->datef = $dateend + $usertime;
  1123. if ($icalevent['SUMMARY']) {
  1124. $event->label = $icalevent['SUMMARY'];
  1125. } elseif ($icalevent['DESCRIPTION']) {
  1126. $event->label = dol_nl2br($icalevent['DESCRIPTION'], 1);
  1127. } else {
  1128. $event->label = $langs->trans("ExtSiteNoLabel");
  1129. }
  1130. // Priority (see https://www.kanzaki.com/docs/ical/priority.html)
  1131. // LOW = 0 to 4
  1132. // MEDIUM = 5
  1133. // HIGH = 6 to 9
  1134. if (!empty($icalevent['PRIORITY'])) {
  1135. $event->priority = $icalevent['PRIORITY'];
  1136. }
  1137. // Transparency (see https://www.kanzaki.com/docs/ical/transp.html)
  1138. if ($icalevent['TRANSP']) {
  1139. if ($icalevent['TRANSP'] == "TRANSPARENT") {
  1140. $event->transparency = 0; // 0 = available / free
  1141. }
  1142. if ($icalevent['TRANSP'] == "OPAQUE") {
  1143. $event->transparency = 1; // 1 = busy
  1144. }
  1145. // TODO: MS outlook states
  1146. // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:TRANSPARENT => Available / Free
  1147. // X-MICROSOFT-CDO-BUSYSTATUS:FREE + TRANSP:OPAQUE => Work another place
  1148. // X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE + TRANSP:OPAQUE => With reservations
  1149. // X-MICROSOFT-CDO-BUSYSTATUS:BUSY + TRANSP:OPAQUE => Busy
  1150. // X-MICROSOFT-CDO-BUSYSTATUS:OOF + TRANSP:OPAQUE => Away from the office / off-site
  1151. }
  1152. if (!empty($icalevent['LOCATION'])) {
  1153. $event->location = $icalevent['LOCATION'];
  1154. }
  1155. $event->date_start_in_calendar = $event->datep;
  1156. if ($event->datef != '' && $event->datef >= $event->datep) {
  1157. $event->date_end_in_calendar = $event->datef;
  1158. } else {
  1159. $event->date_end_in_calendar = $event->datep;
  1160. }
  1161. // Add event into $eventarray if date range are ok.
  1162. if ($event->date_end_in_calendar < $firstdaytoshow || $event->date_start_in_calendar >= $lastdaytoshow) {
  1163. //print 'x'.$datestart.'-'.$dateend;exit;
  1164. //print 'x'.$datestart.'-'.$dateend;exit;
  1165. //print 'x'.$datestart.'-'.$dateend;exit;
  1166. // This record is out of visible range
  1167. } else {
  1168. if ($event->date_start_in_calendar < $firstdaytoshow) {
  1169. $event->date_start_in_calendar = $firstdaytoshow;
  1170. }
  1171. if ($event->date_end_in_calendar >= $lastdaytoshow) {
  1172. $event->date_end_in_calendar = ($lastdaytoshow - 1);
  1173. }
  1174. // Add an entry in actionarray for each day
  1175. $daycursor = $event->date_start_in_calendar;
  1176. $annee = dol_print_date($daycursor, '%Y', 'tzuserrel');
  1177. $mois = dol_print_date($daycursor, '%m', 'tzuserrel');
  1178. $jour = dol_print_date($daycursor, '%d', 'tzuserrel');
  1179. // Loop on each day covered by action to prepare an index to show on calendar
  1180. $loop = true; $j = 0;
  1181. // daykey must be date that represent day box in calendar so must be a user time
  1182. $daykey = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  1183. $daykeygmt = dol_mktime(0, 0, 0, $mois, $jour, $annee, 'gmt');
  1184. do {
  1185. //if ($event->fulldayevent) print dol_print_date($daykeygmt,'dayhour','gmt').'-'.dol_print_date($daykey,'dayhour','gmt').'-'.dol_print_date($event->date_end_in_calendar,'dayhour','gmt').' ';
  1186. $eventarray[$daykey][] = $event;
  1187. $daykey += 60 * 60 * 24; $daykeygmt += 60 * 60 * 24; // Add one day
  1188. if (($event->fulldayevent ? $daykeygmt : $daykey) > $event->date_end_in_calendar) {
  1189. $loop = false;
  1190. }
  1191. } while ($loop);
  1192. }
  1193. }
  1194. }
  1195. }
  1196. }
  1197. }
  1198. // Complete $eventarray with events coming from external module
  1199. $parameters = array(); $object = null;
  1200. $reshook = $hookmanager->executeHooks('getCalendarEvents', $parameters, $object, $action);
  1201. if (!empty($hookmanager->resArray['eventarray'])) {
  1202. foreach ($hookmanager->resArray['eventarray'] as $keyDate => $events) {
  1203. if (!isset($eventarray[$keyDate])) {
  1204. $eventarray[$keyDate] = array();
  1205. }
  1206. $eventarray[$keyDate] = array_merge($eventarray[$keyDate], $events);
  1207. }
  1208. }
  1209. // Sort events
  1210. foreach ($eventarray as $keyDate => &$dateeventarray) {
  1211. usort($dateeventarray, 'sort_events_by_date');
  1212. }
  1213. $maxnbofchar = 0;
  1214. $cachethirdparties = array();
  1215. $cachecontacts = array();
  1216. $cacheusers = array();
  1217. // Define theme_datacolor array
  1218. $color_file = DOL_DOCUMENT_ROOT."/theme/".$conf->theme."/theme_vars.inc.php";
  1219. if (is_readable($color_file)) {
  1220. include $color_file;
  1221. }
  1222. if (!is_array($theme_datacolor)) {
  1223. $theme_datacolor = array(array(120, 130, 150), array(200, 160, 180), array(190, 190, 220));
  1224. }
  1225. $massactionbutton ='';
  1226. print_barre_liste($langs->trans("Agenda"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, -1, 'object_action', 0, $nav.'<span class="marginleftonly"></span>'.$newcardbutton, '', $limit, 1, 0, 1, $viewmode);
  1227. // Show div with list of calendars
  1228. print $s;
  1229. if (empty($mode) || $mode == 'show_month') { // View by month
  1230. $newparam = $param; // newparam is for birthday links
  1231. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  1232. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1233. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1234. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  1235. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  1236. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  1237. $newparam = preg_replace('/viewcal=[0-9]+&?/i', '', $newparam);
  1238. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  1239. $newparam .= '&viewcal=1';
  1240. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  1241. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1242. print '</div>';
  1243. print '<div class="div-table-responsive-no-min sectioncalendarbymonth maxscreenheightless300">';
  1244. print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
  1245. print ' <tr class="liste_titre">';
  1246. // Column title of weeks numbers
  1247. echo ' <td class="center">#</td>';
  1248. $i = 0;
  1249. while ($i < 7) {
  1250. print ' <td class="center bold uppercase tdfordaytitle'.($i == 0 ? ' borderleft' : '').'">';
  1251. $numdayinweek = (($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7);
  1252. if (!empty($conf->dol_optimize_smallscreen)) {
  1253. $labelshort = array(0=>'SundayMin', 1=>'MondayMin', 2=>'TuesdayMin', 3=>'WednesdayMin', 4=>'ThursdayMin', 5=>'FridayMin', 6=>'SaturdayMin');
  1254. print $langs->trans($labelshort[$numdayinweek]);
  1255. } else {
  1256. print $langs->trans("Day".$numdayinweek);
  1257. }
  1258. print ' </td>'."\n";
  1259. $i++;
  1260. }
  1261. echo ' </tr>'."\n";
  1262. $todayarray = dol_getdate($now, 'fast');
  1263. $todaytms = dol_mktime(0, 0, 0, $todayarray['mon'], $todayarray['mday'], $todayarray['year']);
  1264. // In loops, tmpday contains day nb in current month (can be zero or negative for days of previous month)
  1265. //var_dump($eventarray);
  1266. for ($iter_week = 0; $iter_week < 6; $iter_week++) {
  1267. echo " <tr>\n";
  1268. // Get date of the current day, format 'yyyy-mm-dd'
  1269. if ($tmpday <= 0) { // If number of the current day is in previous month
  1270. $currdate0 = sprintf("%04d", $prev_year).sprintf("%02d", $prev_month).sprintf("%02d", $max_day_in_prev_month + $tmpday);
  1271. } elseif ($tmpday <= $max_day_in_month) { // If number of the current day is in current month
  1272. $currdate0 = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $tmpday);
  1273. } else // If number of the current day is in next month
  1274. {
  1275. $currdate0 = sprintf("%04d", $next_year).sprintf("%02d", $next_month).sprintf("%02d", $tmpday - $max_day_in_month);
  1276. }
  1277. // Get week number for the targeted date '$currdate0'
  1278. $numweek0 = date("W", strtotime(date($currdate0)));
  1279. // Show the week number, and define column width
  1280. echo ' <td class="center weeknumber opacitymedium" width="2%">'.$numweek0.'</td>';
  1281. for ($iter_day = 0; $iter_day < 7; $iter_day++) {
  1282. if ($tmpday <= 0) {
  1283. /* Show days before the beginning of the current month (previous month) */
  1284. $style = 'cal_other_month cal_past';
  1285. if ($iter_day == 6) {
  1286. $style .= ' cal_other_month_right';
  1287. }
  1288. echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
  1289. show_day_events($db, $max_day_in_prev_month + $tmpday, $prev_month, $prev_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1290. echo " </td>\n";
  1291. } elseif ($tmpday <= $max_day_in_month) {
  1292. /* Show days of the current month */
  1293. $curtime = dol_mktime(0, 0, 0, $month, $tmpday, $year);
  1294. $style = 'cal_current_month';
  1295. if ($iter_day == 6) {
  1296. $style .= ' cal_current_month_right';
  1297. }
  1298. $today = 0;
  1299. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  1300. $today = 1;
  1301. }
  1302. if ($today) {
  1303. $style = 'cal_today';
  1304. }
  1305. if ($curtime < $todaytms) {
  1306. $style .= ' cal_past';
  1307. }
  1308. //var_dump($todayarray['mday']."==".$tmpday." && ".$todayarray['mon']."==".$month." && ".$todayarray['year']."==".$year.' -> '.$style);
  1309. echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
  1310. show_day_events($db, $tmpday, $month, $year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1311. echo "</td>\n";
  1312. } else {
  1313. /* Show days after the current month (next month) */
  1314. $style = 'cal_other_month';
  1315. if ($iter_day == 6) {
  1316. $style .= ' cal_other_month_right';
  1317. }
  1318. echo ' <td class="'.$style.' nowrap tdtop" width="14%">';
  1319. show_day_events($db, $tmpday - $max_day_in_month, $next_month, $next_year, $month, $style, $eventarray, $maxprint, $maxnbofchar, $newparam);
  1320. echo "</td>\n";
  1321. }
  1322. $tmpday++;
  1323. }
  1324. echo " </tr>\n";
  1325. }
  1326. print "</table>\n";
  1327. print '</div>';
  1328. print '<input type="hidden" name="actionmove" value="mupdate">';
  1329. print '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_month&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
  1330. print '<input type="hidden" name="newdate" id="newdate">';
  1331. } elseif ($mode == 'show_week') {
  1332. // View by week
  1333. $newparam = $param; // newparam is for birthday links
  1334. $newparam = preg_replace('/showbirthday=/i', 'showbirthday_=', $newparam); // To avoid replacement when replace day= is done
  1335. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1336. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1337. $newparam = preg_replace('/day=[0-9]+&?/i', '', $newparam);
  1338. $newparam = preg_replace('/month=[0-9]+&?/i', '', $newparam);
  1339. $newparam = preg_replace('/year=[0-9]+&?/i', '', $newparam);
  1340. $newparam = preg_replace('/viewweek=[0-9]+&?/i', '', $newparam);
  1341. $newparam = preg_replace('/showbirthday_=/i', 'showbirthday=', $newparam); // Restore correct parameter
  1342. $newparam .= '&viewweek=1';
  1343. print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  1344. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1345. print '</div></div>';
  1346. print '<div class="div-table-responsive-no-min sectioncalendarbyweek maxscreenheightless300">';
  1347. print '<table class="centpercent noborder nocellnopadd cal_pannel cal_month">';
  1348. print ' <tr class="liste_titre">';
  1349. $i = 0;
  1350. while ($i < 7) {
  1351. echo ' <td class="center bold uppercase tdfordaytitle">'.$langs->trans("Day".(($i + (isset($conf->global->MAIN_START_WEEK) ? $conf->global->MAIN_START_WEEK : 1)) % 7))."</td>\n";
  1352. $i++;
  1353. }
  1354. echo " </tr>\n";
  1355. echo " <tr>\n";
  1356. for ($iter_day = 0; $iter_day < 7; $iter_day++) {
  1357. // Show days of the current week
  1358. $curtime = dol_time_plus_duree($firstdaytoshow, $iter_day, 'd'); // $firstdaytoshow is in timezone of server
  1359. $tmpday = dol_print_date($curtime, '%d', 'tzuserrel');
  1360. $tmpmonth = dol_print_date($curtime, '%m', 'tzuserrel');
  1361. $tmpyear = dol_print_date($curtime, '%Y', 'tzuserrel');
  1362. $style = 'cal_current_month';
  1363. if ($iter_day == 6) {
  1364. $style .= ' cal_other_month_right';
  1365. }
  1366. $today = 0;
  1367. $todayarray = dol_getdate($now, 'fast');
  1368. if ($todayarray['mday'] == $tmpday && $todayarray['mon'] == $tmpmonth && $todayarray['year'] == $tmpyear) {
  1369. $today = 1;
  1370. }
  1371. if ($today) {
  1372. $style = 'cal_today';
  1373. }
  1374. echo ' <td class="'.$style.'" width="14%" valign="top">';
  1375. show_day_events($db, $tmpday, $tmpmonth, $tmpyear, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300);
  1376. echo " </td>\n";
  1377. }
  1378. echo " </tr>\n";
  1379. print "</table>\n";
  1380. print '</div>';
  1381. echo '<input type="hidden" name="actionmove" value="mupdate">';
  1382. echo '<input type="hidden" name="backtopage" value="'.dol_escape_htmltag($_SERVER['PHP_SELF']).'?mode=show_week&'.dol_escape_htmltag($_SERVER['QUERY_STRING']).'">';
  1383. echo '<input type="hidden" name="newdate" id="newdate">';
  1384. } else { // View by day
  1385. $newparam = $param; // newparam is for birthday links
  1386. $newparam = preg_replace('/mode=show_month&?/i', '', $newparam);
  1387. $newparam = preg_replace('/mode=show_week&?/i', '', $newparam);
  1388. $newparam = preg_replace('/viewday=[0-9]+&?/i', '', $newparam);
  1389. $newparam .= '&viewday=1';
  1390. // Code to show just one day
  1391. $style = 'cal_current_month cal_current_month_oneday';
  1392. $today = 0;
  1393. $todayarray = dol_getdate($now, 'fast');
  1394. if ($todayarray['mday'] == $day && $todayarray['mon'] == $month && $todayarray['year'] == $year) {
  1395. $today = 1;
  1396. }
  1397. //if ($today) $style='cal_today';
  1398. $timestamp = dol_mktime(12, 0, 0, $month, $day, $year);
  1399. $arraytimestamp = dol_getdate($timestamp);
  1400. print '<div class="liste_titre liste_titre_bydiv centpercent"><div class="divsearchfield">';
  1401. print_actions_filter($form, $canedit, $status, $year, $month, $day, $showbirthday, 0, $filtert, 0, $pid, $socid, $action, -1, $actioncode, $usergroup, '', $resourceid);
  1402. print '</div></div>';
  1403. print '<div class="div-table-responsive-no-min sectioncalendarbyday maxscreenheightless300">';
  1404. echo '<table class="tagtable centpercent noborder nocellnopadd cal_pannel cal_month noborderbottom" style="margin-bottom: 5px !important;">';
  1405. echo ' <tr class="tagtr liste_titre">';
  1406. echo ' <td class="tagtd center bold uppercase">'.$langs->trans("Day".$arraytimestamp['wday'])."</td>\n";
  1407. echo " </td>\n";
  1408. /*
  1409. echo ' <div class="tagtr">';
  1410. echo ' <div class="tagtd width100"></div>';
  1411. echo ' <div class="tagtd center">';
  1412. echo show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, -1);
  1413. echo ' </div>'."\n";
  1414. echo " </div>\n";
  1415. */
  1416. echo '</table>';
  1417. print '</div>';
  1418. /* WIP View per hour */
  1419. $useviewhour = 0;
  1420. if ($useviewhour) {
  1421. print '<div class="div-table-responsive-no-min borderbottom">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  1422. $maxheightwin = (isset($_SESSION["dol_screenheight"]) && $_SESSION["dol_screenheight"] > 500) ? ($_SESSION["dol_screenheight"] - 200) : 660; // Also into index.php file
  1423. echo '<div style="max-height: '.$maxheightwin.'px;">';
  1424. echo '<div class="tagtable centpercent calendarviewcontainer">';
  1425. $maxnbofchar = 80;
  1426. $tmp = explode('-', $conf->global->MAIN_DEFAULT_WORKING_HOURS);
  1427. $minhour = round($tmp[0], 0);
  1428. $maxhour = round($tmp[1], 0);
  1429. if ($minhour > 23) {
  1430. $minhour = 23;
  1431. }
  1432. if ($maxhour < 1) {
  1433. $maxhour = 1;
  1434. }
  1435. if ($maxhour <= $minhour) {
  1436. $maxhour = $minhour + 1;
  1437. }
  1438. $i = 0;
  1439. $j = 0;
  1440. while ($i < 24) {
  1441. echo ' <div class="tagtr calendarviewcontainertr">'."\n";
  1442. echo ' <div class="tagtd width100 tdtop">'.dol_print_date($i * 3600, 'hour', 'gmt').'</div>';
  1443. echo ' <div class="tagtd '.$style.' tdtop"></div>'."\n";
  1444. echo ' </div>'."\n";
  1445. $i++;
  1446. $j++;
  1447. }
  1448. echo '</div></div>';
  1449. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 1);
  1450. print '</div>';
  1451. } else {
  1452. print '<div class="div-table-responsive-no-min">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  1453. show_day_events($db, $day, $month, $year, $month, $style, $eventarray, 0, $maxnbofchar, $newparam, 1, 300, 0);
  1454. print '</div>';
  1455. }
  1456. }
  1457. print "\n".'</form>';
  1458. // End of page
  1459. llxFooter();
  1460. $db->close();
  1461. /**
  1462. * Show event of a particular day
  1463. *
  1464. * @param DoliDB $db Database handler
  1465. * @param int $day Day
  1466. * @param int $month Month
  1467. * @param int $year Year
  1468. * @param int $monthshown Current month shown in calendar view
  1469. * @param string $style Style to use for this day
  1470. * @param array $eventarray Array of events
  1471. * @param int $maxprint Nb of actions to show each day on month view (0 means no limit)
  1472. * @param int $maxnbofchar Nb of characters to show for event line
  1473. * @param string $newparam Parameters on current URL
  1474. * @param int $showinfo Add extended information (used by day and week view)
  1475. * @param int $minheight Minimum height for each event. 60px by default.
  1476. * @param string $nonew 0=Add "new entry button", 1=No "new entry button", -1=Only "new entry button"
  1477. * @return void
  1478. */
  1479. function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $nonew = 0)
  1480. {
  1481. global $user, $conf, $langs;
  1482. global $action, $mode, $filter, $filtert, $status, $actioncode, $usergroup; // Filters used into search form
  1483. global $theme_datacolor;
  1484. global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused;
  1485. if ($conf->use_javascript_ajax) { // Enable the "Show more button..."
  1486. $conf->global->MAIN_JS_SWITCH_AGENDA = 1;
  1487. }
  1488. $dateint = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
  1489. //print 'show_day_events day='.$day.' month='.$month.' year='.$year.' dateint='.$dateint;
  1490. print "\n";
  1491. $curtime = dol_mktime(0, 0, 0, $month, $day, $year);
  1492. $urltoshow = DOL_URL_ROOT.'/comm/action/index.php?mode=show_day&day='.str_pad($day, 2, "0", STR_PAD_LEFT).'&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year.$newparam;
  1493. $urltocreate = '';
  1494. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1495. $newparam .= '&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year;
  1496. $hourminsec = '100000';
  1497. $urltocreate = DOL_URL_ROOT.'/comm/action/card.php?action=create&datep='.sprintf("%04d%02d%02d", $year, $month, $day).$hourminsec.'&backtopage='.urlencode($_SERVER["PHP_SELF"].($newparam ? '?'.$newparam : ''));
  1498. }
  1499. // Line with title of day
  1500. print '<div id="dayevent_'.$dateint.'" class="dayevent tagtable centpercent nobordernopadding">'."\n";
  1501. if ($nonew <= 0) {
  1502. print '<div class="tagtr cursorpointer" onclick="window.location=\''.$urltocreate.'\';"><div class="nowrap tagtd"><div class="left inline-block">';
  1503. print '<a class="dayevent-aday" style="color: #666" href="'.$urltoshow.'">';
  1504. if ($showinfo) {
  1505. print dol_print_date($curtime, 'daytextshort');
  1506. } else {
  1507. print dol_print_date($curtime, '%d');
  1508. }
  1509. print '</a>';
  1510. print '</div><div class="nowrap floatright inline-block marginrightonly">';
  1511. if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) {
  1512. print '<a class="cursoradd" href="'.$urltocreate.'">'; // Explicit link, usefull for nojs interfaces
  1513. print img_picto($langs->trans("NewAction"), 'edit_add.png');
  1514. print '</a>';
  1515. }
  1516. print '</div></div></div>'."\n";
  1517. }
  1518. if ($nonew < 0) {
  1519. print '</div>';
  1520. return;
  1521. }
  1522. // Line with td contains all div of each events
  1523. print '<div class="tagtr">';
  1524. print '<div class="tagtd centpercent agendacell sortable">';
  1525. //$curtime = dol_mktime (0, 0, 0, $month, $day, $year);
  1526. $i = 0; $ireallyshown = 0; $itoshow = 0; $numother = 0; $numbirthday = 0; $numical = 0; $numicals = array();
  1527. $ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day);
  1528. $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0
  1529. $nextindextouse = is_array($colorindexused) ?count($colorindexused) : 0; // At first run this is 0, so fist user has 0, next 1, ...
  1530. //var_dump($colorindexused);
  1531. include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php';
  1532. $tmpholiday = new Holiday($db);
  1533. foreach ($eventarray as $daykey => $notused) { // daykey is the 'YYYYMMDD' to show according to user
  1534. $annee = dol_print_date($daykey, '%Y', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1535. $mois = dol_print_date($daykey, '%m', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1536. $jour = dol_print_date($daykey, '%d', 'gmt'); // We use gmt because we want the value represented by string 'YYYYMMDD'
  1537. //print 'event daykey='.$daykey.' dol_print_date(daykey)='.dol_print_date($daykey, 'dayhour', 'gmt').' jour='.$jour.' mois='.$mois.' annee='.$annee."<br>\n";
  1538. if ($day == $jour && $month == $mois && $year == $annee) {
  1539. foreach ($eventarray[$daykey] as $index => $event) {
  1540. if ($i < $maxprint || $maxprint == 0 || !empty($conf->global->MAIN_JS_SWITCH_AGENDA)) {
  1541. $keysofuserassigned = array_keys($event->userassigned);
  1542. $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar);
  1543. // Define $color (Hex string like '0088FF') and $cssclass of event
  1544. $color = -1; $cssclass = ''; $colorindex = -1;
  1545. if (in_array($user->id, $keysofuserassigned)) {
  1546. $cssclass = 'family_mytasks';
  1547. if (empty($cacheusers[$event->userownerid])) {
  1548. $newuser = new User($db);
  1549. $newuser->fetch($event->userownerid);
  1550. $cacheusers[$event->userownerid] = $newuser;
  1551. }
  1552. //var_dump($cacheusers[$event->userownerid]->color);
  1553. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1554. if (!empty($cacheusers[$event->userownerid]->color)) {
  1555. $color = $cacheusers[$event->userownerid]->color;
  1556. }
  1557. } elseif ($event->type_code == 'ICALEVENT') { // Event come from external ical file
  1558. $numical++;
  1559. if (!empty($event->icalname)) {
  1560. if (!isset($numicals[dol_string_nospecial($event->icalname)])) {
  1561. $numicals[dol_string_nospecial($event->icalname)] = 0;
  1562. }
  1563. $numicals[dol_string_nospecial($event->icalname)]++;
  1564. }
  1565. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1566. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
  1567. } elseif ($event->type_code == 'BIRTHDAY') {
  1568. $numbirthday++; $colorindex = 2; $cssclass = 'family_birthday '; $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1569. } else {
  1570. $numother++;
  1571. $color = ($event->icalcolor ? $event->icalcolor : -1);
  1572. $cssclass = (!empty($event->icalname) ? 'family_ext'.md5($event->icalname) : 'family_other');
  1573. if (empty($cacheusers[$event->userownerid])) {
  1574. $newuser = new User($db);
  1575. $newuser->fetch($event->userownerid);
  1576. $cacheusers[$event->userownerid] = $newuser;
  1577. }
  1578. //var_dump($cacheusers[$event->userownerid]->color);
  1579. // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event)
  1580. if (!empty($cacheusers[$event->userownerid]->color)) {
  1581. $color = $cacheusers[$event->userownerid]->color;
  1582. }
  1583. }
  1584. if ($color < 0) { // Color was not set on user card. Set color according to color index.
  1585. // Define color index if not yet defined
  1586. $idusertouse = ($event->userownerid ? $event->userownerid : 0);
  1587. if (isset($colorindexused[$idusertouse])) {
  1588. $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user
  1589. } else {
  1590. $colorindex = $nextindextouse;
  1591. $colorindexused[$idusertouse] = $colorindex;
  1592. if (!empty($theme_datacolor[$nextindextouse + 1])) {
  1593. $nextindextouse++; // Prepare to use next color
  1594. }
  1595. }
  1596. //print '|'.($color).'='.($idusertouse?$idusertouse:0).'='.$colorindex.'<br>';
  1597. // Define color
  1598. $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]);
  1599. }
  1600. $cssclass = $cssclass.' eventday_'.$ymd;
  1601. // Defined style to disable drag and drop feature
  1602. if ($event->type_code == 'AC_OTH_AUTO') {
  1603. $cssclass .= " unmovable";
  1604. } elseif ($event->type_code == 'HOLIDAY') {
  1605. $cssclass .= " unmovable";
  1606. } elseif ($event->type_code == 'BIRTHDAY') {
  1607. $cssclass .= " unmovable";
  1608. } elseif ($event->type_code == 'ICALEVENT') {
  1609. $cssclass .= " unmovable";
  1610. } elseif ($event->date_start_in_calendar && $event->date_end_in_calendar && date('Ymd', $event->date_start_in_calendar) != date('Ymd', $event->date_end_in_calendar)) {
  1611. // If the event is on several days
  1612. $tmpyearend = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1613. $tmpmonthend = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1614. $tmpdayend = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1615. //var_dump($tmpyearend.' '.$tmpmonthend.' '.$tmpdayend);
  1616. if ($tmpyearend != $annee || $tmpmonthend != $mois || $tmpdayend != $jour) {
  1617. $cssclass .= " unmovable unmovable-mustusefirstdaytodrag";
  1618. } else {
  1619. $cssclass .= ' movable cursormove';
  1620. }
  1621. } else {
  1622. if ($user->rights->agenda->allactions->create ||
  1623. (($event->authorid == $user->id || $event->userownerid == $user->id) && $user->rights->agenda->myactions->create)) {
  1624. $cssclass .= " movable cursormove";
  1625. } else {
  1626. $cssclass .= " unmovable";
  1627. }
  1628. }
  1629. $h = ''; $nowrapontd = 1;
  1630. if ($mode == 'show_day') {
  1631. $h = 'height: 100%; '; $nowrapontd = 0;
  1632. }
  1633. if ($mode == 'show_week') {
  1634. $h = 'height: 100%; '; $nowrapontd = 0;
  1635. }
  1636. // Show event box
  1637. print "\n";
  1638. print '<!-- start event '.$i.' -->'."\n";
  1639. $morecss = '';
  1640. if ($maxprint && $ireallyshown >= $maxprint) {
  1641. $morecss = 'showifmore';
  1642. }
  1643. if ($event->type == 'birthdate' && !GETPOST('check_birthday')) {
  1644. $morecss = 'hidden';
  1645. }
  1646. if ($event->type == 'holiday' && !GETPOST('check_holiday')) {
  1647. $morecss = 'hidden';
  1648. }
  1649. if ($morecss != 'hidden') {
  1650. $itoshow++;
  1651. }
  1652. if ($morecss != 'showifmore' && $morecss != 'hidden') {
  1653. $ireallyshown++;
  1654. }
  1655. //var_dump($event->type.' - '.$morecss.' - '.$cssclass.' - '.$i.' - '.$ireallyshown.' - '.$itoshow);
  1656. print '<div id="event_'.$ymd.'_'.$i.'" class="event family_'.$event->type.' '.$cssclass.($morecss ? ' '.$morecss : '').'"';
  1657. //print ' style="height: 100px;';
  1658. //print ' position: absolute; top: 40px; width: 50%;';
  1659. //print '"';
  1660. print '>';
  1661. //var_dump($event->userassigned);
  1662. //var_dump($event->transparency);
  1663. print '<table class="centpercent cal_event';
  1664. print (empty($event->transparency) ? ' cal_event_notbusy' : ' cal_event_busy');
  1665. //if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) print ' opacitymedium'; // Not busy
  1666. print '" style="'.$h;
  1667. $colortouse = $color;
  1668. // If colortouse is similar than background, we force to change it.
  1669. if (empty($event->transparency) && empty($conf->global->AGENDA_NO_TRANSPARENT_ON_NOT_BUSY)) {
  1670. print 'background: #f0f0f0;';
  1671. print 'border-left: 5px solid #'.$colortouse.';';
  1672. } else {
  1673. print 'background: #f0f0f0;';
  1674. print 'border-left: 5px solid #'.dol_color_minus($colortouse, -3).';';
  1675. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($colortouse, -3).'), to(#'.dol_color_minus($colortouse, -1).'));';
  1676. }
  1677. //print 'background: #'.$colortouse.';';
  1678. //print 'background: -webkit-gradient(linear, left top, left bottom, from(#'.dol_color_minus($color, -3).'), to(#'.dol_color_minus($color, -1).'));';
  1679. //if (! empty($event->transparency)) print 'background: #'.$color.'; background: -webkit-gradient(linear, left top, left bottom, from(#'.$color.'), to(#'.dol_color_minus($color,1).'));';
  1680. //else print 'background-color: transparent !important; background: none; border: 1px solid #bbb;';
  1681. //print ' -moz-border-radius:4px;"';
  1682. //print 'border: 1px solid #ccc" width="100%"';
  1683. print '">';
  1684. print '<tr>';
  1685. print '<td class="tdoverflow nobottom centpercent '.($nowrapontd ? 'nowrap ' : '').'cal_event'.($event->type_code == 'BIRTHDAY' ? ' cal_event_birthday' : '').'">';
  1686. $daterange = '';
  1687. if ($event->type_code == 'BIRTHDAY') { // It's birthday calendar
  1688. print $event->getNomUrl(1, $maxnbofchar, 'cal_event', 'birthday', 'contact');
  1689. } elseif ($event->type_code == 'HOLIDAY') { // It's holiday calendar
  1690. $tmpholiday->fetch($event->id);
  1691. print $tmpholiday->getNomUrl(1);
  1692. $tmpid = $tmpholiday->fk_user;
  1693. if (empty($cacheusers[$tmpid])) {
  1694. $newuser = new User($db);
  1695. $newuser->fetch($tmpid);
  1696. $cacheusers[$tmpid] = $newuser;
  1697. }
  1698. $listofusertoshow = '';
  1699. $listofusertoshow .= '<br>'.$cacheusers[$tmpid]->getNomUrl(-1, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1700. print $listofusertoshow;
  1701. } else { // Other calendar
  1702. // Picto
  1703. if (empty($event->fulldayevent)) {
  1704. //print $event->getNomUrl(2).' ';
  1705. }
  1706. // Date
  1707. if (empty($event->fulldayevent)) {
  1708. // Show hours (start ... end)
  1709. $tmpyearstart = dol_print_date($event->date_start_in_calendar, '%Y', 'tzuserrel');
  1710. $tmpmonthstart = dol_print_date($event->date_start_in_calendar, '%m', 'tzuserrel');
  1711. $tmpdaystart = dol_print_date($event->date_start_in_calendar, '%d', 'tzuserrel');
  1712. $tmpyearend = dol_print_date($event->date_end_in_calendar, '%Y', 'tzuserrel');
  1713. $tmpmonthend = dol_print_date($event->date_end_in_calendar, '%m', 'tzuserrel');
  1714. $tmpdayend = dol_print_date($event->date_end_in_calendar, '%d', 'tzuserrel');
  1715. // Hour start
  1716. if ($tmpyearstart == $annee && $tmpmonthstart == $mois && $tmpdaystart == $jour) {
  1717. $daterange .= dol_print_date($event->date_start_in_calendar, 'hour', 'tzuserrel');
  1718. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1719. if ($tmpyearstart == $tmpyearend && $tmpmonthstart == $tmpmonthend && $tmpdaystart == $tmpdayend) {
  1720. $daterange .= '-';
  1721. }
  1722. //else
  1723. //print '...';
  1724. }
  1725. }
  1726. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1727. if ($tmpyearstart != $tmpyearend || $tmpmonthstart != $tmpmonthend || $tmpdaystart != $tmpdayend) {
  1728. $daterange .= '...';
  1729. }
  1730. }
  1731. // Hour end
  1732. if ($event->date_end_in_calendar && $event->date_start_in_calendar != $event->date_end_in_calendar) {
  1733. if ($tmpyearend == $annee && $tmpmonthend == $mois && $tmpdayend == $jour) {
  1734. $daterange .= dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel');
  1735. }
  1736. }
  1737. } else {
  1738. if ($showinfo) {
  1739. print $langs->trans("EventOnFullDay")."<br>\n";
  1740. }
  1741. }
  1742. // Show title
  1743. $titletoshow = $daterange;
  1744. $titletoshow .= ($titletoshow ? ' ' : '').($event->label ? $event->label : $event->libelle);
  1745. if ($event->type_code != 'ICALEVENT') {
  1746. $savlabel = $event->label ? $event->label : $event->libelle;
  1747. $event->label = $titletoshow;
  1748. $event->libelle = $titletoshow; // deprecatd
  1749. // Note: List of users are inside $event->userassigned. Link may be clickable depending on permissions of user.
  1750. $titletoshow = (($event->type_picto || $event->type_code) ? $event->getTypePicto() : '');
  1751. $titletoshow .= $event->getNomUrl(0, $maxnbofchar, 'cal_event cal_event_title', '', 0, 0);
  1752. $event->label = $savlabel;
  1753. $event->libelle = $savlabel;
  1754. }
  1755. // Loop on each assigned user
  1756. $listofusertoshow = '';
  1757. $posuserassigned = 0;
  1758. foreach ($event->userassigned as $tmpid => $tmpdata) {
  1759. if (!$posuserassigned && $titletoshow) {
  1760. $listofusertoshow .= '<br>';
  1761. }
  1762. $posuserassigned++;
  1763. if (empty($cacheusers[$tmpid])) {
  1764. $newuser = new User($db);
  1765. $newuser->fetch($tmpid);
  1766. $cacheusers[$tmpid] = $newuser;
  1767. }
  1768. $listofusertoshow .= $cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'paddingright valigntextbottom');
  1769. }
  1770. print $titletoshow;
  1771. print $listofusertoshow;
  1772. if ($event->type_code == 'ICALEVENT') {
  1773. print '<br>('.dol_trunc($event->icalname, $maxnbofchar).')';
  1774. }
  1775. $thirdparty_id = ($event->socid > 0 ? $event->socid : ((is_object($event->societe) && $event->societe->id > 0) ? $event->societe->id : 0));
  1776. $contact_id = ($event->contact_id > 0 ? $event->contact_id : ((is_object($event->contact) && $event->contact->id > 0) ? $event->contact->id : 0));
  1777. // If action related to company / contact
  1778. $linerelatedto = '';
  1779. if ($thirdparty_id > 0) {
  1780. if (!isset($cachethirdparties[$thirdparty_id]) || !is_object($cachethirdparties[$thirdparty_id])) {
  1781. $thirdparty = new Societe($db);
  1782. $thirdparty->fetch($thirdparty_id);
  1783. $cachethirdparties[$thirdparty_id] = $thirdparty;
  1784. } else {
  1785. $thirdparty = $cachethirdparties[$thirdparty_id];
  1786. }
  1787. if (!empty($thirdparty->id)) {
  1788. $linerelatedto .= $thirdparty->getNomUrl(1, '', 0);
  1789. }
  1790. }
  1791. if (!empty($contact_id) && $contact_id > 0) {
  1792. if (!is_object($cachecontacts[$contact_id])) {
  1793. $contact = new Contact($db);
  1794. $contact->fetch($contact_id);
  1795. $cachecontacts[$contact_id] = $contact;
  1796. } else {
  1797. $contact = $cachecontacts[$contact_id];
  1798. }
  1799. if ($linerelatedto) {
  1800. $linerelatedto .= '&nbsp;';
  1801. }
  1802. if (!empty($contact->id)) {
  1803. $linerelatedto .= $contact->getNomUrl(1, '', 0);
  1804. }
  1805. }
  1806. if (!empty($event->fk_element) && $event->fk_element > 0 && !empty($event->elementtype) && !empty($conf->global->AGENDA_SHOW_LINKED_OBJECT)) {
  1807. include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1808. if ($linerelatedto) {
  1809. $linerelatedto .= '<br>';
  1810. }
  1811. $linerelatedto .= dolGetElementUrl($event->fk_element, $event->elementtype, 1);
  1812. }
  1813. if ($linerelatedto) {
  1814. print '<br>'.$linerelatedto;
  1815. }
  1816. }
  1817. // Show location
  1818. if ($showinfo) {
  1819. if ($event->location) {
  1820. print '<br>';
  1821. print $langs->trans("Location").': '.$event->location;
  1822. }
  1823. }
  1824. print '</td>';
  1825. // Status - Percent
  1826. $withstatus = 0;
  1827. if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') {
  1828. $withstatus = 1;
  1829. if ($event->percentage >= 0) {
  1830. $withstatus = 2;
  1831. }
  1832. }
  1833. print '<td class="nobottom right nowrap cal_event_right'.($withstatus >= 2 ? ' cal_event_right_status' : '').'">';
  1834. if ($withstatus) {
  1835. print $event->getLibStatut(3, 1);
  1836. } else {
  1837. print '&nbsp;';
  1838. }
  1839. print '</td></tr></table>';
  1840. print '</div><!-- end event '.$i.' -->'."\n";
  1841. $i++;
  1842. } else {
  1843. print '<a href="'.DOL_URL_ROOT.'/comm/action/index.php?mode='.$mode.'&maxprint=0&month='.((int) $monthshown).'&year='.((int) $year);
  1844. print ($status ? '&status='.$status : '').($filter ? '&filter='.urlencode($filter) : '');
  1845. print ($filtert ? '&search_filtert='.urlencode($filtert) : '');
  1846. print ($usergroup ? '&search_usergroup='.urlencode($usergroup) : '');
  1847. print ($actioncode != '' ? '&search_actioncode='.urlencode($actioncode) : '');
  1848. print '">'.img_picto("all", "1downarrow_selected.png").' ...';
  1849. print ' +'.(count($eventarray[$daykey]) - $maxprint);
  1850. print '</a>';
  1851. break;
  1852. //$ok=false; // To avoid to show twice the link
  1853. }
  1854. }
  1855. break;
  1856. }
  1857. }
  1858. if (!$i) { // No events
  1859. print '&nbsp;';
  1860. }
  1861. if (!empty($conf->global->MAIN_JS_SWITCH_AGENDA) && $itoshow > $ireallyshown && $maxprint) {
  1862. print '<div class="center cursorpointer" id="more_'.$ymd.'">'.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'</div>';
  1863. //print ' +'.(count($eventarray[$daykey])-$maxprint);
  1864. print '<script type="text/javascript">'."\n";
  1865. print 'jQuery(document).ready(function () {'."\n";
  1866. print ' var open=0;'."\n";
  1867. print ' jQuery("#more_'.$ymd.'").click(function() { console.log("Click on showmore for '.$ymd.'"); reinit_day_'.$ymd.'(); event.stopImmediatePropagation(); });'."\n";
  1868. print ' function reinit_day_'.$ymd.'() {'."\n";
  1869. print ' jQuery(".eventday_'.$ymd.'.showifmore").toggle();'."\n";
  1870. print ' open = open + 1; if (open > 1) { open = 0; }'."\n";
  1871. print ' if (open) { ';
  1872. print ' jQuery("#more_'.$ymd.'").html(\''.img_picto("All", "angle-double-up", 'class="warning"').'\');'."\n";
  1873. print ' } else { ';
  1874. print ' jQuery("#more_'.$ymd.'").html(\''.img_picto("All", "angle-double-down", 'class="warning"').' +'.($itoshow - $ireallyshown).'\');'."\n";
  1875. print ' }'."\n";
  1876. print ' }'."\n";
  1877. print '});'."\n";
  1878. print '</script>'."\n";
  1879. }
  1880. print '</div></div>'; // td tr
  1881. print '</div>'; // table
  1882. print "\n";
  1883. }
  1884. /**
  1885. * Change color with a delta
  1886. *
  1887. * @param string $color Color
  1888. * @param int $minus Delta (1 = 16 unit). Positive value = darker color, Negative value = brighter color.
  1889. * @param int $minusunit Minus unit
  1890. * @return string New color
  1891. */
  1892. function dol_color_minus($color, $minus, $minusunit = 16)
  1893. {
  1894. $newcolor = $color;
  1895. if ($minusunit == 16) {
  1896. $newcolor[0] = dechex(max(min(hexdec($newcolor[0]) - $minus, 15), 0));
  1897. $newcolor[2] = dechex(max(min(hexdec($newcolor[2]) - $minus, 15), 0));
  1898. $newcolor[4] = dechex(max(min(hexdec($newcolor[4]) - $minus, 15), 0));
  1899. } else {
  1900. // Not yet implemented
  1901. }
  1902. return $newcolor;
  1903. }
  1904. /**
  1905. * Sort events by date
  1906. *
  1907. * @param object $a Event A
  1908. * @param object $b Event B
  1909. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same time slot
  1910. */
  1911. function sort_events_by_date($a, $b)
  1912. {
  1913. // Sort holidays at first
  1914. if ($a->type_code === 'HOLIDAY') {
  1915. return -1;
  1916. }
  1917. if ($b->type_code === 'HOLIDAY') {
  1918. return 1;
  1919. }
  1920. // datep => Event start time
  1921. // datef => Event end time
  1922. // Events have different start time
  1923. if ($a->datep !== $b->datep) {
  1924. return $a->datep - $b->datep;
  1925. }
  1926. // Events have same start time and no end time
  1927. if ((!is_numeric($b->datef)) || (!is_numeric($a->datef))) {
  1928. return sort_events_by_percentage($a, $b);
  1929. }
  1930. // Events have the same start time and same end time
  1931. if ($b->datef === $a->datef) {
  1932. return sort_events_by_percentage($a, $b);
  1933. }
  1934. // Events have the same start time, but have different end time -> longest event first
  1935. return $b->datef - $a->datef;
  1936. }
  1937. /**
  1938. * Sort events by percentage
  1939. *
  1940. * @param object $a Event A
  1941. * @param object $b Event B
  1942. * @return int < 0 if event A should be before event B, > 0 otherwise, 0 if they have the exact same percentage
  1943. */
  1944. function sort_events_by_percentage($a, $b)
  1945. {
  1946. // Sort events with no percentage before each other
  1947. // (usefull to sort holidays, sick days or similar on the top)
  1948. if ($a->percentage < 0) {
  1949. return -1;
  1950. }
  1951. if ($b->percentage < 0) {
  1952. return 1;
  1953. }
  1954. return $b->percentage - $a->percentage;
  1955. }