index.php 93 KB

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