index.php 93 KB

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