index.php 97 KB

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